12. Output devices

Output devices in electronic systems transfer energy from the electrical energy that has been processed to another kind of energy, often light, sound or movement (kinetic). Output devices can be digital or analogue.

Devices which perform an “Output” function are generally called Actuators.

Boards

outputdevices

Pin 1: When Enable1/2 is HIGH, Left part of IC will work, i.e motor connected with pin 3 and pin 6 will rotate.

Pin 2: Input 1, when this pin is HIGH the current will flow though output 1.

Pin 3: Output 1, this pin is connected with one terminal of motor.

Pin 4/5: GND pins

Pin 6: Output 2, this pin is connected with one terminal of motor.

Pin 7: Input 2, when this pin is HIGH the current will flow though output 2.

Pin 8: VSS, this pin is used to give power supply to connected motors from 5V to 36V maximum depends on Motor connected.

Pin 9: When Enable 3/4 is HIGH, Right part of IC will work, i.e motor connected with pin 11 and pin 14 will rotate.

Pin 10: Input 4, when this pin is HIGH the current will flow though output 4.

Pin 11: Output 4, this pin is connected with one terminal of motor.

Pin 12/13: GND pins

Pin 14: Output 3, this pin is connected with one terminal of motor.

Pin 15: Input 3, when this pin is HIGH the current will flow though output 3.

Pin 16: VCC, for supply power to IC i.e 5V.

• Pin 2 = Logic 1 and Pin 7 = Logic 0 | Clockwise Direction
• Pin 2 = Logic 0 and Pin 7 = Logic 1 | Anticlockwise Direction
• Pin 2 = Logic 0 and Pin 7 = Logic 0 | Idle [No rotation] [Hi-Impedance state]
• Pin 2 = Logic 1 and Pin 7 = Logic 1 | Idle [No rotation]

Reference : L293d

Board Files

outputdevices

Traces

outputdevices

Cut

Follow the steps in week 5 documentation to use the trace and cut file to mill the board.

Output Devices

DC Motor using Touch Sensor

#define ctsPin A1 //defines input pin

int ledPin = 13;  
int m1 = 6;
int m2 = 7; // defines the specified pin numbers as integers


void setup()
{     
  Serial.begin(9600);     // Starts the serial communication
  pinMode(ledPin, OUTPUT); // defines output
  pinMode(m1, OUTPUT); // define output
  pinMode(m2, OUTPUT); // defines output
  pinMode(ctsPin, INPUT); // defines input
}

void loop() // starts the loop
{     
  int ctsValue = digitalRead(ctsPin); // reads the value from input 

  if (ctsValue == HIGH) // condition 1
  {    
    digitalWrite(ledPin, HIGH);   
    digitalWrite(m1,HIGH);
    digitalWrite(m2,LOW);  // output
    Serial.println("TOUCHED");  // Output in serial Monitor

  }   
  else // condition 2
  {     
    digitalWrite(ledPin,LOW);   
    digitalWrite(m2,LOW);
    digitalWrite(m1,LOW);  // output
    Serial.println("not touched");  // Output in serial monitor

  }
  delay(0.9); // sets delay
}

DC Motor using Touch and Ultrasonic Sensors

(Note : For ultrasonic part, I started with the code on this page and modified it further for the desired application)

#define ctsPin A1 //defines input pin
const int trigPin = A2; 
const int echoPin = A3; //Constant Integer value
long duration;
int distance; 
int ledPin = 13;
int m1 = 6;
int m2 = 7; //defines the specified pin numbers as integers

void setup()
{     
  Serial.begin(9600);     // Starts the serial communication
  pinMode(ledPin, OUTPUT); // defines output
  pinMode(m1, OUTPUT); // defines output
  pinMode(m2, OUTPUT); // defines output
  pinMode(ctsPin, INPUT); // defines input
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
}

void loop() // starts the loop
{     
  digitalWrite(trigPin, LOW); 
delayMicroseconds(2);  
digitalWrite(trigPin, HIGH);
delayMicroseconds(10); // Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, LOW); // Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2; // Calculating the distance
Serial.print("Distance: ");
Serial.println(distance); // Prints the distance on the Serial Monitor
  int ctsValue = digitalRead(ctsPin);     

  if (ctsValue == HIGH  && distance >6) // condition 1
  {    
    digitalWrite(ledPin, HIGH);   
    digitalWrite(m1,HIGH);
    digitalWrite(m2,LOW);  // output
    Serial.println("TOUCHED");  // Output in serial monitor

  }   
  if (ctsValue == HIGH  && distance <5)  //condition 2
  {     
    digitalWrite(ledPin,LOW);  
    digitalWrite(m2,LOW);
    digitalWrite(m1,LOW);    // output
    Serial.println("not touched");  // Output in serial monitor

  }
  else // condition 3
  {
    digitalWrite(ledPin,LOW);  
    digitalWrite(m2,LOW);
    digitalWrite(m1,LOW);  // output
  }
}

Charlieplexing

These are the files for that board:

outputdevices

Traces

outputdevices

Cut

This is how the board looked after milling and soldering.

outputdevices

What is charlieplexing and how it works?

outputdevices

outputdevices

Reference 1 : Charlieplexing - Wikipedia
Reference 2 : Charlieplexing

(Note : This code is not written by me. I just tried to understand it and used it to programme the charlieplexing board. The code is written by Neil Gershenfeld. Here is the link.)

    #include <avr/io.h>
    #include <util/delay.h> // Includes the libraries

    #define output(directions,pin) (directions |= pin) // set port direction for output
    #define input(directions,pin) (directions &= (~pin)) // set port direction for input 
    #define set(port,pin) (port |= pin) // set port pin
    #define clear(port,pin) (port &= (~pin)) // clear port pin
    #define pin_test(pins,pin) (pins & pin) // test for port pin
    #define bit_test(byte,bit) (byte & (1 << bit)) // test for bit set

    #define led_delay() _delay_ms(1) // LED delay

    #define led_port PORTA
    #define led_direction DDRA

    #define A (1 << PA1) // row 1
    #define B (1 << PA2) // row 2
    #define C (1 << PA3) // row 3
    #define D (1 << PA4) // row 4
    #define E (1 << PA5) // row 5


    void flash(uint8_t from, uint8_t to, uint8_t delay)  // source from, sink to, flash

    {

    static uint8_t i;
    set(led_port,from);
    clear(led_port,to);
    output(led_direction,from);
    output(led_direction,to);
    for (i = 0; i < delay; ++i)
           led_delay();
    input(led_direction,from);
    input(led_direction,to);
    }

    void led_cycle(uint8_t number, uint8_t delay) // cycle through LEDs
        {


    uint8_t i;
    for (i = 0; i < number; ++i) {
    flash(B,A,delay);
    flash(C,A,delay);
    flash(D,A,delay);
    flash(E,A,delay);
    flash(A,B,delay);
    flash(C,B,delay);
    flash(D,B,delay);
    flash(E,B,delay);
    flash(A,C,delay);
    flash(B,C,delay);
    flash(D,C,delay);
    flash(E,C,delay);
    flash(A,D,delay);
    flash(B,D,delay);
    flash(C,D,delay);
    flash(E,D,delay);
    flash(A,E,delay);
    flash(B,E,delay);
    flash(C,E,delay);
    flash(D,E,delay);
    }
    }

    int main(void) {

    CLKPR = (1 << CLKPCE);
    CLKPR = (0 << CLKPS3) | (0 << CLKPS2) | (0 << CLKPS1) | (0 << CLKPS0);  // set clock divider to /1

    while (1) {
      led_cycle(1,100);
      led_cycle(3,20);
      led_cycle(100,1); // main loop
      }
    }

### Group Work

The Group Assignment was to probe an input device’s analog levels and digital signals. The group page can be found here