Week 6:Input Devices

Assignment Activities

1.Group Assignment.

.probe an input device's analog levels and digital signals

You can access Group Assignment in details here

2.Individual Assignment.

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



Individual Assignment.

In This week 11 of Input device I have learnt many types of sensors and other input devices,It was an educative week because I got time to test some sensors like Gas Sensor, Temperature Sensor, Moisture Sensor, and Also the one I will use which is the ultrasonic sensor in my final project

After the sort of time testing different sensors as I said Above I thought of using The one which is in my final project for the sake of time we are remaining.

For the first time I wanted to use the Gas Sensor in order to detect the Smoke level in the room(Place), I have plugged the sensor on my board with ESP 32 MCU and LCD but It's display was numbers which were varying with time but the problem was that I was not recognising the meaning of that numbers, and I took sometime for research in different sites like here , I found that my Gas Sensor (MQ-2) has some gases like Methane, Butane, LPG, Smoke it uses,However The meaning of the numbers displayed on screen was not clear to me.

Because of this challenge of this Sensor I changed to one of my sensor in the final Project which is Ultrasonic Sensor and it's really an Awesome one because of it's accuracy in distance measurement.

First of all,I have to summarize necessary information regarding my Ultrasonic Sensor.

About Ultrasonic Sensor.

What Is Sensor.

Sensor:is a device that detects and responds to some type of input from the physical environment. The input can be light, heat, motion, moisture, pressure or any number of other environmental phenomena.

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.

Working Principle of Ultrasonic Sensor

The working principle of an ultrasonic sensor is based on the fact that sound waves travel at a constant speed through a medium, such as air or water. The sensor sends out a high-frequency sound wave that travels through the air until it hits an object. When the sound wave hits an object, it bounces back to the sensor, where it is detected by the receiver.

The sensor then measures the time it takes for the sound wave to travel from the transmitter to the object and back to the receiver. Since the speed of sound is constant, the time taken for the sound wave to travel can be used to calculate the distance to the object.

This distance measurement is made possible by the use of a piezoelectric element in the ultrasonic transmitter and receiver. This element converts electrical energy into mechanical energy, producing sound waves when an electrical signal is applied. When the sound waves hit the object and bounce back, the piezoelectric element in the receiver converts the mechanical energy of the sound waves back into an electrical signal, which is then processed by the sensor to calculate the distance to the object.

Formular used is the one which is known in physics of dynamics.

Ultrasonic Sensor Pinout Configuration

After it's working principle there's pinout description of ultrasonic sensor


Sensor Features.

Sensor Applications.


Regarding my Project of making BMI Machine I will use ultrasonic Sensor in measuring the height of the person, and what I was looking is to be familiar with this sensor so for the time of application could be much easier for me.

Board Designation

For the Board I have used the one I designed in

in Week9 of output devices.

with my Programmer.

Then the next thing which was remained is to connect my Sensor on GPIO pins and read it's signal as the output on the serial monitor After entering the codes.

After connecting The sensor Board and Programmer,I plugged to power(5V) from the USB Port.

After Connecting to The computer I inserted the codes in Arduino and I runned it,Below are the Codes.


  const int trigPin = 32;  //change  ur pins here
const int echoPin = 35; // and here
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); 
  pinMode(echoPin, INPUT); 
  Serial.begin(9600); 
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration * 0.034 / 2;
  distance = distance + 1;
  Serial.print("Distance: ");
  Serial.print(distance);
  Serial.println("cm");
}

Picture showing an obstacle near the surface of ultrasonic sensor.

Picture showing reading signal on the Serial monitor of Arduino IDE.

Below is the hello shot while working.


Ultrasonic Library and Source Codesyou can download the files.