ULTRASONIC SENSOR

 The ultrasonic sensor

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.

 

The sensor consists of 4pins :

 

.VCC-5V ,INPUT POWER

.TRIG-Trigger input

.ECHO-Echo Output

.GND-Ground

It has two modules one transmitter and one receiver.

 

HARDWARE SETUP OF ULTRASONIC SENSOR:

 

Connect Trig pin to pin D12 on the Arduino board.

Connect the Echo pin to pin D13 on the Arduino board.

Connect VCC pin to 5V pin on the Arduino board.

Connect the GND pin to the GND pin on the Arduino board.

 

Explanation:

 

Provide input to TRIG input then enables the module to transmit ultrasonic burst.

If there is an obstacle detected in front of the module then it will reflect those ultrasonic waves.

If the signal comes back, the ECHO output will be high for some specific time of duration for sending and receiving ultrasonic signals.

The formula used to calculate distance :

Distance =(speed*time)/2

 

The basic components required for the setup:

 

.HC-SR04 ultrasonic sensor

.Arduino Uno

.Breadboard

.Jumper wires(as per requirements)

 

Basic specifications of ultrasonic sensor:

.Input current: 15 mA

.Output voltage: 0 – 5V

.Modulation frequency: 40 HZ

.Beam Angle: Max. 15 degrees

.Distance: 2 cm – 400cm

.Accuracy: 0.3 cm

.Output cycle: 50ms

 

Basic dimensions of the ultrasonic sensor:

.Length: 45 mm

.Height: 20 mm

.Height of transmitter and receiver: 11 mm.

.The diameter of the transmitter and Receiver: 16 mfm

 

BASIC STEPS FOR PROGRAM EXECUTION

 

Open the Arduino IDE software on your desktop. Open a new sketch File by clicking New. The Arduino code should contain two functions as void setup() and void loop(). All pinMode declarations are made in void setup(). The functions inside the void loop() will run infinitely. These are the basic steps you can follow to write the program for interfacing.

 

SMALL STEPS FOR PROGRAM EXECUTION

 

Serial.begin(9600) – to set the baud-rate for the sensor reading.

pinMode(pin, mode) – to declare the pin and specify that it is an input pin or output pin.

digitalWrite(pin, HIGH/LOW) – to specify the particular pin as high or low.

delay(µs) – to delay the process executing for some microseconds.

.PulseIn (echo-pin, mode) – Reads a pulse on a pin(either HIGH or LOW).

.print(data)- to print the reading on the serial monitor.

 

Basic code for demonstration of ultrasonic sensor :

Condition :

 when the Obstacle is  within 10cm of range then the inbuilt led of Arduino will switch on

Else it will remain off



const int trigpin=9;
const int echopin=10;
long duration;
int distance;
void setup() {
  pinMode(trigpin,OUTPUT);
  pinMode(echopin,INPUT);
  pinMode(13,OUTPUT);             //using the arduino's inbuilt led for                                              output//
  Serial.begin(9600);                   //to set the baud rate for the serial                                                communication//
}

void loop() {

 digitalWrite(trigpin,LOW);
 delayMicroseconds(2);
 digitalWrite(trigpin,HIGH);
 delayMicroseconds(10);
 digitalWrite(trigpin,LOW);
 duration=pulseIn(echopin,HIGH);
 distance=duration*0.034/2;   //distance of the obstacle in cm//
 Serial.println(distance);          //printing the calculated distance in                                                             the serial monitor//
 delay(1000);
 if(distance<=10)
 {
  digitalWrite(13,HIGH);          //led on if obstacle is within the range                                                         10cm//

 }

else
{
  digitalWrite(13,LOW);        

}
}

Comments

Unknown said…
Very informative
ISHA SRIVASTAVA said…
Hope it provided you some information,thank you for showing interest.
ISHA SRIVASTAVA said…
Hope it provided you some information,thank you for showing interest.

Popular posts from this blog