Week 11. Input Device
Image Courtesy: Photo by Jorge Ramirez on Unsplash
By the end of this assignment, we will have a better understanding of the role of input devices in computing and how to choose the best device for your needs. This time i chose ultrasonic sensor with ATTiny 3216 chip.
Assignment Tasks:
-
Group Assignment: Probe an input device’s analog levels and digital signals.
-
Individual Assignment: Measure something: add a sensor to a microcontroller board (which was designed earlier/new one) and read it.
Learning Process
Ultrasonic Sensor
An ultrasonic sensor is a type of sensor that uses sound waves with frequencies above the range of human hearing to detect the distance of objects.
The sensor emits a high-frequency sound wave and measures the time it takes for the wave to bounce off an object and return to the sensor. Based on the time it takes for the sound wave to travel to the object and back, the sensor can calculate the distance between the sensor and the object.
Ultrasonic sensors are commonly used in a wide range of applications, such as robotics, automation, and automotive systems. They are often used to detect the presence or absence of objects, measure distances, or detect movement.
One advantage of ultrasonic sensors is their ability to detect objects at a distance without the need for direct contact or line-of-sight. They can also operate in a wide range of environments and can be relatively inexpensive compared to other types of sensors.
However, ultrasonic sensors can be affected by factors such as temperature, humidity, and wind, which can affect the accuracy of distance measurements. They may also be susceptible to interference from other ultrasonic sources or noise in the environment.
Principle of HC-SR04
The ultrasonic sensor works on the principle of SONAR and RADAR system which is used to determine the distance to an object.
An ultrasonic sensor generates high-frequency sound (ultrasound) waves. When this ultrasound hits the object, it reflects as echo which is sensed by the receiver as shown in below figure.
By measuring the time required for the echo to reach to the receiver, we can calculate the distance. This is the basic working principle of Ultrasonic module to measure distance.
HC-SR-04 has an ultrasonic transmitter, receiver and control circuit.
n the ultrasonic module HCSR04, we have to give trigger pulse, so that it will generate ultrasound of frequency 40 kHz. After generating ultrasound i.e. 8 pulses of 40 kHz, it makes echo pin high. Echo pin remains high until it does not get the echo sound back. So the width of echo pin will be the time for sound to travel to the object and return back. Once we get the time we can calculate distance, as we know the speed of sound.
The calculation as follows,
Distance = Speed x Time
With the speed of sound waves, 343 m/s, we can calculate the distance.
Total Distance = (343 x Time)/2
Total distance is divided by 2 because signal travels from sensor to object and returns to the sensor.
Pinout of HC-SR-04
VCC: +5 V supply
TRIG: Trigger input of sensor. Microcontroller applies 10 us trigger pulse to the HC-SR04 ultrasonic module.
ECHO: Echo output of sensor. Microcontroller reads/monitors this pin to detect the obstacle or to find the distance.
GND: Ground
Board Design
I chose the ATTiny 3216 chip for my project. The plan was intended to operate this device as a radar by coupling a servo motor with an HC-SR04 sensor. This chip was chosen in order to test BH1750, another sensor for light intensity sensing as well.
The schematic was as shown below.
The PCB design:
Bill Of Materials:
a. PCB Board - 50mm x 50mm (Minimum Size as per design)
b. ATTiny 3216 microcontroller - 1 no.
c. Capacitor - 100nf - 1 no.
d. UPDI - 2x3 pin - 1 no.
e. Resistor R499 - 1 no.
f. Resistor R0 - 1 no.
g. LED - 1 no.
h. Pinhead 1x6 - 1 no.
i. Pinhead 1x4 - 3 nos
Board Production
I milled my board in accordance with my design using mods and a Roland PCB Milling Machine, much like in the electronics production week. I also soldered each component after that. And below you can see my board.
Programming
First step was to burn the bootloader to the chip. I used UPDI programmer to burn the bootloader.
After that it time to program and upload the same to our board. I used Adrian’s program for my assignment and added software serial since i made a mistake while connecting the pins on the design stage. I used FTDI for serial communication, which was made by one of our previous year fellow student Mr. Saheen Paliyil.
And then, I used Processing for getting a result. the code used was as shown below:
And the final Result:
Group Assignment
Detailed Study Report on our Group Assignment Page.
Help Taken & Other References
Chat GPT used for doubt clearing and content helps.