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¶
-
Since I needed to work with motors for my final project, I wanted to run a basic dc motor this week using my board. But since my board from last week got damaged(One of the header pins came off), I decided to make the second upgraded version of the board I had alreeady made during week 11.
-
In this new board, I used a smaller 2.5mm jack since we had that available in the lab unlike the ones I used earlier.
-
Also, since I wanted to run motors as my output, I was using an L293d motor driver.
-
It works on the concept of H-bridge. H-bridge is a circuit which allows the voltage to be flown in either direction. As you know voltage need to change its direction for being able to rotate the motor in clockwise or anticlockwise direction, Hence H-bridge IC are ideal for driving a DC motor.
-
In a single L293D chip there are two h-Bridge circuit inside the IC which can rotate two dc motor independently. Due its size it is very much used in robotic application for controlling DC motors. Given below is the pin diagram of a L293D motor controller.
-
There are two Enable pins on l293d. Pin 1 and pin 9, for being able to drive the motor, the pin 1 and 9 need to be high. For driving the motor with left H-bridge you need to enable pin 1 to high. And for right H-Bridge you need to make the pin 9 to high. If anyone of the either pin1 or pin9 goes low then the motor in the corresponding section will suspend working. It’s like a switch.
-
Below is the pinout for L293d.
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.
-
The traces and the cut files of this board can be found below:
-
Logic Table:
• 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¶
Traces
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
-
First I tried to using a basic touch sensor to run the motor, since I was not sure if the L293d would run the DC motor. I already had a code for the touch sensor as Input from previous week. So I made changes to that code to run the motor.
-
Here, touch sensor was input and motor was output. The code is written below
#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
-
For the second application of output devices, I tried to use the sensors as I require in the final project. For that, what I require is touch and ultrasonic sensors on the input pins and motor in the output. The touch sensor would start the motor, only when the distance reading in ultrasonic sensor in more than a certain distance. In any other case, the motor won’t spin.
-
The code for this condition is written below with explaination:
(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¶
- I made a second board this week for charlieplexing(A little bit out of fascination) which was not my own design. I downloaded the files from the weekly page.
These are the files for that board:
Traces
Cut
This is how the board looked after milling and soldering.
What is charlieplexing and how it works?¶
-
Charlieplexing is a technique for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used e.g. to drive an array of LEDs.
-
With Charlieplexing, n drive pins can be used to drive n digits with n-1 segments each; in other words, n drive pins can be used to control n2-n LEDs. Traditional multiplexed display technique would take 2n drive pins to control n2 LEDs.
-
How this works:
-
Look at the diagram below. We have three complementary pairs, one pair between a each combination of micro output pins. One pair between A-B, one pair between B-C and one pair between A-C.
-
If you disconnected pin C for now we’d have the same situation as before. With 5V on pin A and 0V on pin B, LED1 will glow, LED2 is reverse biased and will not conduct current. With 5V on pin B and 0V on pin A LED2 will glow and LED1 is reverse biased.
-
If we disconnected pin B and set pin A to 5V and pin C to 0V then LED5 would glow. Reversing so that pin A is 0V and pin C is 5V then LED6 would glow. Same for the complementary pair between pins B-C.
Reference 1 : Charlieplexing - Wikipedia
Reference 2 : Charlieplexing
-
Charlieplexing works by having the I/O pins alternate between driving digits and driving segments.
-
The third attempt was to use the below code on the charlieplexing board I made this week.
(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 } }
- This is the video of this code running on the board.
-
Thus, I tried multiple different codes on two boards. The code for touch+ultrasonic will be of great help for my final project.
-
All the files for this week are attached here
-
All the board files are attached here
(Note : Since the charlieplexing board wasn’t designed by me, there are no board files attached for that)
### Group Work
The Group Assignment was to probe an input device’s analog levels and digital signals. The group page can be found here