Interfacing 2 Ultrasonic sensors with one Arduino
Ultrasonic sensors are widely used in the Arduino projects
to detect objects, distances and system disturbances. Majority of peoples
having some problems while trying to use Arduino to drive two HC-SR04
ultrasonic sensor. While trying to display two measured value from each sensor,
one of them work fine but the other displays value 0.
The situation were two sensors works in parallel, but pulseIn
functions are executed in serial. This is the reason why your code doesn't
work. Let's image when you toss two balls by your right hand, and try catch
them one by one with your right hand. When you catch one ball and put it in a
box, another ball had been fallen on the ground. This is why first pulseIn can
get correct value and second one fail to get correct value.
I have created a programme to display two distance values
from different sensors and displays it in a 6x2 LCD. To sole the code problem,
I have created a separate function for read the sensor and distance
calculation.
I have used I2C display library for LCD to reduce wiring
complexity. So need to use 2 libraries Wire.h & LiquidCrystal_I2C.h. If you
don’t having the same, please go to ‘Manage Libraries’ in Arduino and install
the same! Please refer THIS or THIS tutorial for any references.
LCD Connections:
LCD
Arduino
GND - Ground
VCC - 5V
SDA - A4
SCL - A5
Ultrasonic Connections:
Ultrasonic 1 Arduino
Triger 10
Echo 12
VCC VCC
GND GND
Ultrasonic 2 Arduino
Triger 9
Echo 11
VCC VCC
GND GND
Comments
Post a Comment