11. Input devices¶
Assignment¶
- Individual assignment:
Measure something: add a sensor to a microcontroller board that you have designed and read it.
Getting started¶
I carefully studied all the boards on Neil’s page on input devices. He made a different board for every sensor. I wanted to use all or at least 5-6 sensors on a single board then with the help of jumper wires read the data from each one by one.
Input Devices¶
In order for an electronic circuit or system to perform any useful task or function it needs to be able to communicate with the “real world” whether this is by reading an input signal from an “ON/OFF” switch or by activating some form of output device to illuminate a single light.
In other words, an Electronic System or circuit must be able or capable to “do” something and Sensors and Transducers are the perfect components for doing this.
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.
Common Sensors
Analog vs Digital Sensors
Analogue Sensors produce a continuous output signal or voltage which is generally proportional to the quantity being measured. Physical quantities such as Temperature, Speed, Pressure, Displacement, Strain, etc are all analog quantities as they tend to be continuous in nature.
Digital Sensors produce a discrete digital output signals or voltages that are a digital representation of the quantity being measured. Digital sensors produce a Binary output signal in the form of a logic “1” or a logic “0”, (“ON” or “OFF”). This means then that a digital signal only produces discrete (non-continuous) values which may be outputted as a single “bit”, (serial transmission) or by combining the bits to produce a single “byte” output (parallel transmission).
Schematic¶
I used 6 sensors in my board
- Swtich
- Distance sensor
- Motion sensor
- Magnetic sensor
- IR sensor
- Temperature sensor
I connected the pin3, pin4, and gnd of the Attiny 45 to a smd jumper. So that I could connect any sensor to the controller using jumper wires.
Then I added all the sensors one by one and created separate schematics for each. The ground pin of all the sensor is connected to the gnd pin of the Attiny45. Vcc of each sensor remains disconnected. I used pin-headers with the pins each sensor.
-
Button
-
Motion sensor
-
Magnetic sensor
-
Distance sensor
-
Temperature sensor
-
IR sensor
At that time, I didn’t know how to add solder pads in the schematics. So, I searched on the internet and found a library(wirepads) on diymodules.org. In this library, there are many types of soldering pads available for use. On pads, I soldered the sensors which already have pin-headers mounted on them.
Click here to download the schematic.
Eagle board¶
Click here to download the board file.
Milling¶
I milled the PCB on Roland SRM 20. For milling steps, check my Electronics production page.
In Picture, you can see at two places the gap wasn’t enough so it didn’t mill properly and the traces were shorting. So I, using a knife, cut the copper in between the traces and made this pcb workable.
Soldering¶
- I found PIR, Distance sensor and switch in our lab. As I used smd versions of the temperature sensor, IR sensor and hall effect which were not available in the lab so I left these components currently. I will purchase and solder them later.
Connections¶
I used FTDI chip for the serial communication and giving power to the microcontroller. Connect Vcc, Gnd and Rx pin of the FTDI to the same pins of the 6pin header in the board. Also connect FTDI to the laptop using USB cable. For programming the board, connect the cable of the AVRISP mkii programmer to the 2X3 pin header of the board. Double check the orientation.
Connect the vcc, pin 3, pin 4 and gnd of the mcirocontroller to the vcc, echo, trig and gnd pin of the ultrasonic distance sensor using jumper wires.
Programming¶
For Progrrmming I used the Arduino IDE. I programmed the ultrasonic distance sensor to read the distance of an obstacle and print this on the serial monitor.
Code
#include "SoftwareSerial.h" // defines pins numbers #define Rx 1 #define Tx 2 const int trigPin = 3; const int echoPin = 4; SoftwareSerial myserial(Rx, Tx); // defines variables long duration; int distance; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output pinMode(echoPin, INPUT); // Sets the echoPin as an Input myserial.begin(9600); // Starts the serial communication myserial.println("Communicating now"); } void loop() { // Clears the trigPin digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin on HIGH state for 10 micro seconds digitalWrite(trigPin, HIGH); delayMicroseconds(10); 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; // Prints the distance on the Serial Monitor myserial.print("Distance: "); myserial.print(distance); myserial.println("cm"); }
Group Assignment¶
For detailed documentation go to our lab Group page.
Oscilloscope¶
An oscilloscope is a laboratory instrument commonly used to display and analyze the waveform of electronic signals. In effect, the device draws a graph of the instantaneous signal voltage as a function of time.
A typical oscilloscope can display alternating current (AC) or pulsating direct current (DC) waveforms having a frequency as low as approximately 1 hertz (Hz) or as high as several megahertz (MHz).
In our lab we got Scientific SMO1102E and Keysight DSO1052B Oscilloscopes.
Features
- Bandwidth = 50 MHz
- Channels = 2
- Max Memory Depth = 16 kpts
- Max Sample Rate = 1 GSa/s
- Display Size = 5.7 inch
- ADC Bits = 8 bits
- USB storage, RS232C and J45 interface
- Multi-waveforms math, FFT Function
- Built-in delay sweep function
- Waveform Record and Recall, Trigger Mode for Edge, Video, Pulse Width, Slope and Alternate
Calibrating the probes¶
Always calibrate an oscilloscope before you use it; never assume the factory settings are correct without checking them. To calibrate an oscilloscope, you’ll use a signal whose voltage is known, then adjust the device until it reads accurately.
Our instructor Rahul explained the process of calibrating the probes.
Measuring Digital Signals¶
We tested the frequency of the crystal oscillator of the Arudino Uno. On display we can see the frequency 16MHz.
On the screen, we can see a digital pulse of frequency 1s with the peak value of 5V. As our DSO is callibrated the pulse was very smooth.
- We then uploaded blink sketch on the Arduino and observed the Pulse signal.
Measuring Analog Signals¶
We measured the analog voltage generated by a motor when rotated manually.
On the screen, we can clearly see an analog waveform pulsating in between negative and positive value. The peak value was +10v.
On reversing the direction of the motor, the peak value was -8V.
Learning outcomes¶
- I got to know about the various sensors.
- I learned how to hook up different sensors to a microcontroller.
- I learned about how to setup communication between the board and the laptop to get the readings of the sensor on the serial monitor.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.