--> Project II - 10. Measuring 4 Distance with 4 Ultrasonic Sensor (Arduino Based) | basic arduino tutorial

Monday, August 7, 2017

Project II - 10. Measuring 4 Distance with 4 Ultrasonic Sensor (Arduino Based)

| Monday, August 7, 2017
Measuring 4 Distance with 4 Ultrasonic Sensor



This application is used to measure 4 distance using 4 ultrasonic sensors and the data processed by Arduino UNO. Sensor used is HC-SR04 and the result is displayed on the LCD.



Hardware Requirement
  • 4 HC-SR04 Ultrasonic Sensor Module
  • Arduino UNO
  • LCD 2x16 Module
  • Power supply +5 Volt

HC-SR04 Module | Source


Block  Diagram



Schematic



Arduino - LCD Wiring


Arduino - Ultrasonic Sensor Wiring


Source Code/Sketch
#define TRIG1 8
#define ECHO1 9
#define TRIG2 10
#define ECHO2 11
#define TRIG3 12
#define ECHO3 13
#define TRIG4 A0
#define ECHO4 A1
#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
unsigned int j1, j2, j3, j4, timer;
void setup(){
lcd.begin(16, 2);
lcd.print(" 4 ULTRASONIC");
lcd.setCursor(0, 1);
lcd.print(" RANGE METER");
delay(2000);
pinMode(ECHO1, INPUT);
pinMode(TRIG1, OUTPUT);
pinMode(ECHO2, INPUT);
pinMode(TRIG2, OUTPUT);
pinMode(ECHO3, INPUT);
pinMode(TRIG3, OUTPUT);
pinMode(ECHO4, INPUT);
pinMode(TRIG4, OUTPUT);
}
void loop(){
//-------------sensor 1
digitalWrite(TRIG1, LOW);
delayMicroseconds(2);

digitalWrite(TRIG1, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG1, LOW);
timer = pulseIn(ECHO1, HIGH);
j1= timer/58;
//-------------sensor 2
digitalWrite(TRIG2, LOW);
delayMicroseconds(2);
digitalWrite(TRIG2, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG2, LOW);
timer = pulseIn(ECHO2, HIGH);
j2= timer/58;
//-------------sensor 3
digitalWrite(TRIG3, LOW);
delayMicroseconds(2);
digitalWrite(TRIG3, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG3, LOW);
timer = pulseIn(ECHO3, HIGH);
j3= timer/58;
//-------------sensor 4
digitalWrite(TRIG4, LOW);
delayMicroseconds(2);
digitalWrite(TRIG4, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG4, LOW);
timer = pulseIn(ECHO4, HIGH);
j4= timer/58;
lcd.setCursor(0,0);
lcd.print("J1= J2=");
lcd.setCursor(0, 1);
lcd.print("J3= J4=");
lcd.setCursor(3, 0);
lcd.print(j1);
lcd.print("cm ");
lcd.setCursor(12, 0);
lcd.print(j2);
lcd.print("cm ");
lcd.setCursor(3, 1);
lcd.print(j3);

lcd.print("cm ");
lcd.setCursor(12, 1);
lcd.print(j4);
lcd.print("cm ");
delay(100);
}


How it Works
1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino

4. On the lcd you'll see the opening text like this


5.After 2 second the data from ultrasonic sensor will shown in one layer



6. Next you can give a barrier or board in front of the ultrasonic sensor (as reflective media) to result 

   different measurement


Video for Project II - 10 Measuring 4 Distance with 4 Ultrasonic Sensor (Arduino Based)



Download the required file.

Related Posts

No comments:

Post a Comment