12. Input devices¶
Individual Assignment¶
- Measure something: add a sensor to a microcontroller board that you have designed and read it.
Group Assignment¶
Probe an input device’s analog levels and digital signals link to group assignment
Input devices?¶
An input device is any device that reads data and communicates the data to a microcontroller which will further use and interpret it. Sensors are in fact Input devices. They interpret information from the real world and convert it to a signal that can be processed (by the main processing unit). Some of the sensors I got familiar during the fab academy course are shown below;
-
Ultrasonic sensor For my final project I want to use an ultrasonic sensor to trigger the audio output on the fountain lamp that I will be making. An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves. An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object’s proximity. High-frequency sound waves reflect from boundaries to produce distinct echo patterns. The ultrasonic sensor has 4 pins namely Trig, Echo, Vcc and Gnd.
-
Mic sensor The microphone sound sensor, as the name says, detects sound. It gives a measurement of how loud a sound is.There are a wide variety of these sensors. The one I got familiar with is given below; It has 4 pins namely, Ao, Gnd, Vcc and Do pins.The sensor module have a built-in potentiometer to adjust the sensitivity of the digital output pin.
-
PIR(Passive Infrared) sensor A passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view. They are most often used in PIR-based motion detectors. PIR sensors are commonly used in security alarms and automatic lighting applications. It is a passive motion detector that waits for infrared temperature from body heat to trigger an activity. In other words, it can sense motion through changes in temperature. So when a person walks into the detection area of a passive sensor, it detects heat emitted from that person and triggers an alarm or turns on the light.
-
LiDAR sensor LiDAR, which stands for Light Detection and Ranging is a popular remote surveying method used to measure the exact distance of an object on the earth’s surface.LiDAR technology is an active remote sensing system which means that the system itself generates energy which will be light in the form of a rapidly firing laser to measure ranges and the exact distance of an object on the Earth’s surface. If you want to know more about the LiDAR sensor then you can check this website
So far I am familiar with the above mentioned sensors.
Ultrasonic sensor as input device¶
More about ultrasonic sensor¶
As the name indicates, ultrasonic sensors measure distance by using ultrasonic waves. The sensor head emits an ultrasonic wave and receives the wave reflected back from the target. Ultrasonic Sensors measure the distance to the target by measuring the time between the emission and reception.
An ultrasonic sensor uses a single ultrasonic element for both emission and reception. In a reflective model ultrasonic sensor, a single oscillator emits and receives ultrasonic waves alternately. This enables miniaturization of the sensor head.
Distance calculation¶
The distance can be calculated with the following formula:
Distance L = 1/2 × T × C where L is the distance, T is the time between the emission and reception, and C is the sonic speed. (The value is multiplied by 1/2 because T is the time for go-and-return distance.)
Features¶
-
Transparent object detectable. Since ultrasonic waves can reflect off a glass or liquid surface and return to the sensor head, even transparent targets can be detected.
-
Resistant to mist and dust Detection is not affected by accumulation of dust or dirt.
-
Complex shaped objects detectable Presence detection is stable even for targets such as mesh trays or springs. You can read more about ultrasonic sensor here.
So to read serial data from ultrasonic sensor I decided to use Attiny 1614 microcontroller since I can connect the echo and trig pin in any of the analog pins of Attiny1614. To start off I started designing the board. Firstly I opened Eagle software, as usual added the fab libraries so that I will be able to use the components.
My schemtic diagram is given above. I kept Echo, Trig, Vcc and Gnd(4 pin connector) to connect ultrasonic sensor and used Pin 12 and 13 of the Attiny1614 for the Echo and Trig pin connection. I kept UPDI(3 pin connector) with UPDI, VCC and GND pins for programming the Attiny1614. For serial data reading I kept VCC, GND, RX and TX(4 pin connector) and connected the RX and TX to the RX and TX of Attiny1614.
After the schematic I switched to board view and after successful routing the board looked like the above image. I did the DRC check, found few wire stubs, deleted them and then exported them in monochrome with 1000 dpi and went to MODs.Mit to generate the toolpath for the SRM20 machine.
After generating the .rml file of the board and the border of the board, and after successful cutting of the board I started soldering the board.
My board is ready for programming now. But for Attiny1614 I had to mill a new programmer that is the UPDI programmer which uses FT230X microcontroller. You can find the board design, components and border files here on the Fab Academy>> Embedded programming week>> under in-system development side as ‘ USB-FT230X-UPDI’. So I directly downloaded traces and interior files and milled and did soldering;
Now since the board is soldered and ready, I had to update the driver so as to make it as programmer. All you have to do is download this driver. I downloaded the 64 bit drivers for windows connected the Updi programmer in my computer’s USB port, went to device manager and then updated the driver. Now it is ready to program my input board.
I connected the UPDI programmer to my input board, opened my arduino ide and added the MegaTinyCore so as to be able to program attiny1614. TO better understand how to install the MegaTinyCore to your arduino ide you can refer this tutorial which helped me successfully install the MegaTinyCore. You have to copy the link and add that in the preferences as shown below;
‘http://drazzy.com/package_drazzy.com_index.json’ This is the link you have to add. Go to File>> Preferences, enter the URL in “Additional Boards Manager URLs” and press ‘OK’. Next go to Tools>> Boards>> Boards Manager, choose “megaTinyCore by Spence Konde” and click “Install”.
Now go to tools>> Board>> MegaTinyCore>> Attiny1614 as shown below to choose your micro controller;
Select the port.
Select the programmer;
Now everything was set. The code I compiled and uploaded is given below;
The arduino code;
// this constant won’t change. It’s the pin number of the sensor’s output: const int pingPin = 9;
void setup() { // initialize serial communication: Serial.begin(9600); }
void loop() { // establish variables for duration of the ping, and the distance result // in inches and centimeters: long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds. // Give a short LOW pulse beforehand to ensure a clean HIGH pulse: pinMode(pingPin, OUTPUT); digitalWrite(pingPin, LOW); delayMicroseconds(2); digitalWrite(pingPin, HIGH); delayMicroseconds(5); digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH pulse // whose duration is the time (in microseconds) from the sending of the ping // to the reception of its echo off of an object. pinMode(pingPin, INPUT); duration = pulseIn(pingPin, HIGH);
Serial.print(inches); Serial.print(“in, “); Serial.print(cm); Serial.print(“cm”); Serial.println();
delay(100); }
long microsecondsToInches(long microseconds) {
return microseconds / 74 / 2; }
long microsecondsToCentimeters(long microseconds) {
return microseconds / 29 / 2; }
After prgramming, I removed the programmer and connected the FTDI connector to my board and to my PC to read the serial communication in the serial monitor of the arduino ide.
The video below shows the successful reading in the serial monitor of arduino ide by the ultrasonic sensor;
Design files¶
Input board schematic design file
Input board design file