Help troubleshooting code
-
Don't confuse MOTION_A_TRIGGER_PIN with MOTION_A_CHILD_ID.
You're right it should be MOTION_A_TRIGGER_PIN. And it should be -1 not -2 confirm?
-
You're right it should be MOTION_A_TRIGGER_PIN. And it should be -1 not -2 confirm?
The interrupt number is usually pin - 2 on our boards. But I would rather use the function provided by arduino to get the correct interrupt number for a pin, digitalPinToInterrupt.
-
Thanks for the help, the sketch complies and runs now. But where and how do I specify the timing in the sketch. This is what I want.
1 PIR detects movement
2 PIR is disabled for 30 seconds
3 Both ultrasonic sensors is enbabled for 30 seconds
4 Ultrasonic sensors OFF PIR ON
5 --> Step one -
I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under
if (tripped)runs, but for how long are the ultrasonic sensors active? And how do I make it so that they are active for 30 sec before they are disabled and the PIR starts again.
-
I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under
if (tripped)runs, but for how long are the ultrasonic sensors active? And how do I make it so that they are active for 30 sec before they are disabled and the PIR starts again.
Should the node sleep in between pinging during the 30 secs that the sonars should be active?
-
@Cliff-Karlsson said:
I don't really understand how the sketch that I posted works. After motionsensor detects movement the loop under
No I only want the sensor to sleep until it gets interrupted from the PIR. Then I want the ultrasonic sensors to ping continuously during the 30 secs.
-
Right now there's a call to wait method in between A and B pings, waiting 1 second. Is that intended? For 30 secs, ping A and B alternatively every 1 second?
-
Right now there's a call to wait method in between A and B pings, waiting 1 second. Is that intended? For 30 secs, ping A and B alternatively every 1 second?
Well I thing the sketch was created mostly using copy/paste so that bit is not exactly what I wanted.
For 30secs, ping A and B alternatively every 100ms would probably be better.
-
I don't understand where and how I should specify that the ultrasonic part should run for 30 sec.
void loop() { boolean tripped = digitalRead(MOTION_A_TRIGGER_PIN) == HIGH; Serial.println(tripped); send(MOTION_A_msg.set(tripped?"1":"0")); // Send tripped value to gw if(tripped) { int SONAR_A_dist = metric?sonar_A.ping_cm():sonar_A.ping_in(); Serial.print("Ping Sonar A: "); Serial.print(SONAR_A_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.println(metric?" cm":" in"); if (SONAR_A_dist != SONAR_A_lastDist) { send(SONAR_A_msg.set(SONAR_A_dist)); SONAR_A_lastDist = SONAR_A_dist; } wait(1000); int SONAR_B_dist = metric?sonar_B.ping_cm():sonar_B.ping_in(); Serial.print("Ping Sonar B: "); Serial.print(SONAR_B_dist); // Convert ping time to distance in cm and print result (0 = outside set distance range) Serial.println(metric?" cm":" in"); if (SONAR_B_dist != SONAR_B_lastDist) { send(SONAR_B_msg.set(SONAR_B_dist)); SONAR_B_lastDist = SONAR_B_dist; } sleep(SLEEP_TIME); } } //else{ // Sleep until interrupt comes in on motion sensor. Send update every two minute. sleep(INTERRUPT,CHANGE, MOTION_SLEEP_TIME);``` -
You have to add a timer, and an if statement. Start the timer after motion is tripped. If time is less than 30 s, ping. Else reset timer and sleep with motion interrupt.
I can post some example code later perhaps.