I've exhausted reading posts and sites trouble shooting this so now I'm seeking the experienced to offer advice.
I have 3 HC-SR04 ultrasonic sensors in a row like so
A -->
B -->
C -->
They are mounted to the wall and meant to read distance of the closest object at the moment.
Running this sketch.
const int atpin = 2;
const int aepin = 3;
const int btpin = 4;
const int bepin = 5;
const int ctpin = 6;
const int cepin = 7;
void setup() {
Serial.begin(9600);
pinMode(atpin, OUTPUT);
pinMode(aepin, INPUT);
pinMode(btpin, OUTPUT);
pinMode(bepin, INPUT);
pinMode(ctpin, OUTPUT);
pinMode(cepin, INPUT);
}
void loop()
{
long adur, acm;
digitalWrite(atpin, LOW);
delayMicroseconds(2);
digitalWrite(atpin, HIGH);
delayMicroseconds(10);
digitalWrite(atpin, LOW);
adur = pulseIn(aepin, HIGH);
long bdur, bcm;
digitalWrite(btpin, LOW);
delayMicroseconds(2);
digitalWrite(btpin, HIGH);
delayMicroseconds(10);
digitalWrite(btpin, LOW);
bdur = pulseIn(bepin, HIGH);
long cdur, ccm;
digitalWrite(ctpin, LOW);
delayMicroseconds(2);
digitalWrite(ctpin, HIGH);
delayMicroseconds(10);
digitalWrite(ctpin, LOW);
cdur = pulseIn(cepin, HIGH);
Serial.print(adur);
Serial.print(" ");
Serial.print(bdur);
Serial.print(" ");
Serial.println(cdur);
delay(1000);
}
I know I can void function() another to make the repeated pings easier in code but that's not the problem. In both codes I get this jumping back and forth. Left is A, Center is B etc
When blocking A physically and leaving B and C open, they read a signal then don't then do then don't etc.
190481 194420 8634 <-- Blocking Left
3875 4027 8656
190799 194971 8553
3792 3979 8776
189674 193434 8576
3819 4082 8632
190276 192711 8677
3739 4055 8608
189802 194260 6276
3721 3930 8656
188833 194558 7253
3753 3613 5279
190889 3214 3000 <-- Blocking Center
189799 3304 3000
189367 193782 6457
189930 3538 8663
From any one's experience, WTH?!
Thanks!