I'm working on an project on a container.
I attached an Infrared Motion Sensor to the lid of the container and a servo to open the lid.
The concept is when the Infrared Motion Sensor detects movement, the servo will turn and open the lid for a few seconds.
But now I got a problem,
When I wave my hand above the sensor, the sensor detects motion and the lid will open, but when the lid is closing
The sensor will detect movement again and the lid opens again without my hand waving
And the lid just keep opening and closing endlessly
So how can I make it so that only when my hand waves, the lid will open
Without the lid closing and opening endlessly
This is the code.
But i just can't wrap my head around how to make this work.
I need some assistance with the code
#include <Servo.h>
Servo servo1;
void setup() {
// put your setup code here, to run once:
servo1.attach(8);
pinMode(10,INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly
int sensorValue = digitalRead(10);
if (sensorValue == 1) {
servo1.write (180) ;
}
else {
servo1.write (0) ;
}
}