hey i have this sensor that detects motion and i was going to use as for a project but im kinda stuck in how i should program it?
i got this toy tank that its going to detect motion with the motion detector sensor and i want it to sweep acroos the every 90 degrees aND stop for about 10 seconds and move again, but once it detects i want it to stop and use a ping sensor to get the sensor to stop at a certain distance to shoot its bbs.
so far i have wote the motion detector to test it out but my problem is how should i be able to use the motion detector sensor in this application for c code, any help would be appreciated.
im going to put an example of my code to show how its writen!
by the way im using a xband motion detector
my program:
void setup() {
Serial.begin(9600);
Serial.println("Pulse test");
pinMode(13, OUTPUT);
attachInterrupt(1, intHandler, CHANGE);
}
volatile int pulseCount = 0;
void intHandler() {
pulseCount++;
}
void loop() {
if (pulseCount > 2) {
digitalWrite(13, HIGH);
if (pulseCount > 3) {
Serial.print("MOTION! ");
Serial.println(pulseCount);
}
digitalWrite(13, LOW);
}
if (pulseCount > 0 && pulseCount <= 3) {
Serial.println(pulseCount);
}
pulseCount = 0;
delay(250);
}