Input Devices


Group Assignment:

Probe an input device(s)'s signals and Document your work (in a group or individually)

Ultrasonics Sensor HC-SR04:

Ultrasonic transducers and ultrasonic sensors are devices that generate or sense ultrasound energy. They can be divided into three broad categories: transmitters, receivers and transceivers. Transmitters convert electrical signals into ultrasound, receivers convert ultrasound into electrical signals, and transceivers can both transmit and receive ultrasound. In a similar way to radar and sonar, ultrasonic transducers are used in systems which evaluate targets by interpreting the reflected signals. For example, by measuring the time between sending a signal and receiving an echo the distance of an object can be calculated. Passive ultrasonic sensors are basically microphones that detect ultrasonic noise that is present under certain conditions. It emits an ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle on its path It will bounce back to the module. Considering the travel time and the speed of the sound you can calculate the distance.The HC-SR04 Ultrasonic Module has 4 pins, Ground, VCC, Trig and Echo. The Ground and the VCC pins of the module needs to be connected to the Ground and the 5 volts pins on the Arduino Board respectively and the trig and echo pins to any Digital I/O pin on the Arduino Board.
Circuit diagram of the HC-SR04 with micro Controller along with code is available here
Upload above code to the microcontroller and connect the signal probes with osiloscope.

Without object

Result are shown on Osiliscope when object is not in front of sensor.

="Responsive
With object

Result are shown on Osiliscope when object is in front of sensor. Change in duty cycle is clearly shown on osiloscope

="Responsive
Result

In our group assignment, we have to use the HC-SR04 sensor to measure the distance, we use the oscilloscope to see the graphs, for this job we consider two conditions first when the object is not near to sensor than the wave is square with 40% to 60% duty cycle, and when an object comes to target than the square wave decrease the duty cycle and reached to 5% to 10%. in the same way when the target changes its place from the origin the wave is going to change.



Individual Assignment:

Measure something: add a sensor to a microcontroller board that you have designed and read it


Due to COVID-19 our lab is closed. So I try to connect sensor with arduino. I used HC-SR04 Ultra sonic distance sensor, which will measure us the distance using ultra sonics waves.


Distance calculation
="Responsive

Connection of HC-SR04 with Arduino.

VCC ==>VCC
GND==>GND
ECHO==>D12
Trig ==> D11

="Responsive

Coding in Arduino IDE and result
="Responsive

Testing HC-SR04 on Arduino UNO
Now we get partial access of Lab so I started working on PCB designing and fabrication.

My idea is to make ATtinny 44 board with HC-SR04 sensor. So open the eagle and import the ATtinny 44 ic, headers, resonater and resisters in schemtics. Using label, name the I/O pins. Same will be connected with each other.

="Responsive
="Responsive ="Responsive
Schemtic layout
="Responsive
Board layout
="Responsive
Generate .png file

Go to the layers and disable all the layer expect pads, top layer. Then go to file and click on export and click on image. New dialog will open. check on the Monochrome and give dpi 2000 and select the location where you want to save and click Ok.

="Responsive
Seprate the trace, outline and holes image

Open the image if trace in paint. Draw rectangle around it and remove every thing inside. Save as outline. Similarly open it again and remove every thing expect holes and save it as holes.

="Responsive
="Responsive ="Responsive
Generate RMLs

Now open mods and select the SRM 20 and upload the image of traces. Select the tool bit 1/64 and dpi 2000 then click calculate. RML for traces is generated. Similary upload the outline image and holes image one by one. Select the tool bit 1/32 and dpi 2000 and click the calculate. RML for holes and outline will be generated.

="Responsive ="Responsive
Milling

First of all trace rml is given to machine with 1/64 tool bit then having same x,y coordinates change the tool bit to 1/32 and give the holes rml first then outline rml file.

="Responsive
Result

After milling board is soldered. Here is final result.

="Responsive
Boot load the board

Connect Fab ISP to the ATtinny 44 board using ISP header. Power the Tinny44 using usb cable and connect to the PC. Open Arduio IDE. Select the programer. Click the burn boat loader.

="Responsive
Coding

#include "SoftwareSerial.h"
// defines pins numbers
SoftwareSerial mySerial(4, 6); /* RX:D4, TX:D6 */
const int trigPin = 3;
const int echoPin = 2;
// defines variables
long duration;
int distance;
void setup() {
pinMode(8, OUTPUT);
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.print("Distance: ");
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(100);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(200);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.039/2; // Here the displayed distance is in centimeters cm
// Prints the distance on the Serial
mySerial.print("Distance: ");
mySerial.println(distance);
if(distance >= 10){ //if distance is less than 10 cm then LED will glow.
digitalWrite(8, LOW);
delay(100);
}
else{//if distance is greater than 10 cm then LED will be off.
digitalWrite(8, HIGH);
delay(100);
}
}

="Responsive
Final Demo


Download all files from here

="Responsive

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact me

you can get in touch with me

Engr. Farhan Ali Shah

Email: farhan.shah@iba-suk.edu.pk

Thank you for visiting my site

woods are lovely dark and deep, but i promise to keep. Miles to go before i sleep, miles to go before i sleep.