Hi, so i'm using two HC-SR04 sonar sensors on my dwenguino, they control the motors of the robot.
We started out with one sonar on the front, which worked good. But now we wanted to add a second sonar on the back of the robot. But when testing the sonar and writing both values to the LCD, the sonar attached to the front of the robot always gave correct values, while the sonar connected to the back of the robot always gave weird/glitchy values on the LCD, the value jumps to 0 alot, and is just really inconsistent.
Nothing happens when switching the two sonars, so it has nothing to do with the sonar itself.
I'm using this code to test :
#include <LiquidCrystal.h>
#include <Wire.h>
#include <Dwenguino.h>
#include <NewPing.h>
#include <dht.h>
#define MAX_DISTANCE 500
void setup() {
initDwenguino();
}
void loop() {
NewPing sonar2(14, 13, MAX_DISTANCE);
NewPing sonar1(12, 11, MAX_DISTANCE);
unsigned int afstand2 = sonar2.ping_cm();
unsigned int afstand1 = sonar1.ping_cm();
dwenguinoLCD.clear();
dwenguinoLCD.setCursor(0,0);
dwenguinoLCD.print(afstand1);
dwenguinoLCD.setCursor(0,1);
dwenguinoLCD.print(afstand2);
}
}
Any help would be appreciated!
