11. Input devices¶
An input device is an equipment/Component used to provide data and control signals to an information processing system such as a Micro Controller. Examples of input devices include Sensors, Cameras etc.
Sensors : A sensor is a transducer whose purpose is to detect some characteristic of its environments. It detects events or changes in quantities and provides a corresponding output, generally as an electrical or optical signal. Transducers are measurement devices used to change one kind of energy to another. Energy may include electrical, mechanical, electromagnetic, chemical, acoustic, and thermal energy.
Devices which perform an “Input” function are commonly called Sensors because they “sense” a physical change in some characteristic that changes in response to some excitation, for example, heat or force and convert that into an electrical signal. Devices which perform an “Output” function are generally called Actuators and are used to control some external device, for example, movement or sound.
The Board¶
- This week I decided to make a board that could drive motors and hence I could use for later weeks as well. Hence, I started making the schematic in Eagle.
- The important thing here is to refer the pinout of ATMega328p IC, before assigning the pins for the sensors and making the connections. All the Input devices should be on the analog pins of the IC.
- I added three header pins for the sensor connections and a L293d motor driver to drive two motors at a time. The routing had to be done manually here since the autorouter was not able to route to 100%. I also had to add a few 0 ohm jumper resistors in order to route all the traces.
- This is how this board looked like.
-
Go to week 5 documentation to see how to generate trace and cut files and mill the board.
-
This is the resultant board.
- Next was soldering the components onto the board. Soldering the tiny ATMega328p was a bit difficult at first.
- Since it was taking a lot of tme for me, I decided to test the board first before going forward with soldering all the components. Thus I soldered the power LED and the six pin header and powered the board. The power LED lit up.
- A couple of components(L293d motor driver and DC Jack) were not available at the lab so I had to buy them from a local store.
Programming¶
- To start programming using a FabISP, first thing you need to do is connect the FabISP to the programming pins of the board using jumper wires. The connections need to be made very carefully as one incorrect connection could fry your circuit. Keep the circuit diagrams open for both FabISP and your board and make the connections.
- Here, the connections that need to be made are:
MISO-MISO
VCC-VPROG
SCK-SCK
MOSI-MOSI
RST-RST
GND-GND
- Once these connections are made and the touch sensor is connected, its time to write the code.
Touch Sensor¶
-
Since I was a beginner with programming, I decided to go for a simple task first and turn on a LED using a touch switch. I was planning to use a touch switch with my final project so this would help me there as well.
-
The touch switch I used was TTP223B which is for digital inputs i.e. it read High - Low and not analog values. Hence, I’ve used digitalRead in my code.
-
Below is the code I wrote with explaination of what each line is for
#define ctsPin A1 // define pin for touch input int ledPin = 13; // define pin for LED output void setup() { pinMode(ledPin, OUTPUT); // define input pinMode(ctsPin, INPUT); // define output } void loop() { int ctsValue = digitalRead(ctsPin); // read input value if (ctsValue == HIGH) // input condition { digitalWrite(ledPin, HIGH); // output 1 } else // when the above condition is not fulfilled { digitalWrite(ledPin, LOW); // output 2 } delay(0.9); }
The Video¶
Ultrasonic Sensor¶
-
Another sensor that I wanted to use for my final project was ultrasonic sensor. Hence, that was the second sensor I used.
-
Again, the ultrasonic sensor was used to turn on an LED. The code for that is written below.
(Note : I started with the code on this page and modified it further for the desired application)
const int trigPin = A2; const int echoPin = A3; // defining the pins long duration; int distance; // defining variables void setup() { pinMode(13, OUTPUT); pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input Serial.begin(9600); // Starts the serial communication } void loop() { digitalWrite(trigPin, LOW); // Clears the trigPin delayMicroseconds(2); digitalWrite(trigPin, HIGH); //Sets the trigPin on HIGH state for 10 micro seconds delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); // Reads the echoPin, returns the sound wave travel time in microseconds distance = duration * 0.034 / 2; // Calculating the distance Serial.print("Distance: "); Serial.println(distance); // Prints the distance on the Serial Monitor if (distance < 100) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } }
Video¶
-
Thus, this week I learned to use two different input devices to generate an output. Next week, during output devices, I’ll try and work with multiple input devices at the same time to generate an output.
-
All the files for this week are attached here.
-
Here are the board files.
Group Work¶
The Group Assignment was to probe an input device’s analog levels and digital signals. The group page can be found here