Hi everyone,
This is my first post on this site, so thank you in advance to anyone and everyone that reads and or helps me with this.
At the moment i am currently building an autonomous robot using 3 HC-SR04 Ultra sonic sensors but i am having trouble getting them to work together. I have wired them up on three separate breadboards. They all share the same Trigger pin GND and VCC pins whilst having different echo pins.
The bug i am having is that is one sensor i.e. the right sensor finds anything within close proximity for some reason it will cause the middle sensor to automatically sense 0. The middle sensor also does this for the left sensor.
Does anyone have any ideas what is wrong? The wires have been wired up correctly also each sensor has been tested on its own prior to this and worked well.
I have attached my code below, thanks again.
#include <NewPing.h>
#define TRIGGER_PIN 7
#define ECHO_PINR 5 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define ECHO_PINL 4
#define ECHO_PINM 6
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
NewPing RightSen(TRIGGER_PIN, ECHO_PINR, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
NewPing LeftSen(TRIGGER_PIN, ECHO_PINL, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
NewPing MidUs(TRIGGER_PIN,ECHO_PINM, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
void setup() {
Serial.begin(9600); // Open serial monitor at 115200 baud to see ping results.
}
void loop() {
unsigned int RS = RightSen.ping(); // Send ping, get ping time in microseconds (uS).
unsigned int MS = MidUs.ping();
unsigned int LS = LeftSen.ping();
int mid = MidUs.convert_cm(MS);
int RSen = RightSen.convert_cm(RS);
int Lsen = LeftSen.convert_cm(LS);
Serial.print("Right Sensor ");
Serial.print(RSen);
Serial.println(" CM");
Serial.print("Middle Sensor ");
Serial.print(mid);
Serial.println(" CM");
Serial.print("Left Sensor ");
Serial.print(Lsen);
Serial.println(" CM");
delay(1000);
}