hi im trying to make a project which if sensor A detect movement LED A will light, if sensor B detect movement LED B will light up, i tri the code, but sensor A only give "out of range" output..
here is the code.
#define trigPin 2 //sensor A
#define echoPin 3 //sensor A
#define btrigPin 7 //sensor B
#define bechoPin 8 //sensor B
#define LED 13
#define LED2 12
unsigned long blinkTime = 0;
void blink(void)
{ static int x = 0; /* Current LED state 0=>off, 1=>on */
digitalWrite(LED,x ^= 1); /* Set LED to opposite state */
blinkTime = millis(); /* Schedule next state change */
}
void watch(void)
{ if (millis() - blinkTime >= 1) /* If it's time to change state */
blink(); /* then go do it */
}
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(btrigPin, OUTPUT);
pinMode(bechoPin, INPUT);
pinMode(LED, OUTPUT);
pinMode(LED2, OUTPUT);
}
void loop() {
int bduration, bdistance;
digitalWrite(btrigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(btrigPin, LOW);
bduration = pulseIn(bechoPin, HIGH);
bdistance = (bduration/2) / 29.1;
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance >= 3 && distance <= 200)
{
Serial.print(distance);
Serial.println(" cm");
digitalWrite(LED, HIGH);
}
if (bdistance >= 3 && bdistance <= 200)
{
digitalWrite(LED2, HIGH);
}
else {
Serial.println("Out of range");
digitalWrite(LED, LOW);
digitalWrite(LED2, LOW);
}
delay(50);
}
im also trying to make LED blink. is it possible to have
did you mean the delay between trigpin HIGH and trigpin LOW? i change it 5000 microsecond. still nothing happen. but right now im thinking my programming logic realy2 went wrong.
could you please post back the value of the 2nd sensor please...
also, voltage matters here, my breakout board came with a regulator, 3v supply was not enough and had to switch to a 5v rail, without a regulator it's important you use the correct voltage you're supposed to use.
and lastly, the sensor could be dead, swap them around see what happens (you might try that first to rule out a broken sensor/ic)
Could you list your current code that works?
I just purchased one of these sensors on ebay and need some help figuring out the code for it. I thought this module would be the same as the Ping))). I was wrong, but hope to get it to work just as well.