/*
Wowki: https://wokwi.com/projects/408184485529159681
Forum: https://forum.arduino.cc/t/can-you-help-me-with-this-code/1298754
*/
#include <Servo.h>
const byte servoPin = 4;
Servo stopCar;
const byte pirPin = 2;
byte val = 0;
byte oldVal = 255;
void setup() {
Serial.begin(115200);
pinMode(pirPin, INPUT);
stopCar.attach(servoPin);
stopCar.write(50);
}
void loop() {
// main code, runs reapetedly:
val = digitalRead(pirPin);
if (val != oldVal) {
oldVal = val;
if (val == HIGH) {
Serial.println("Position 1");
stopCar.write(50); // position 1
} else {
Serial.println("Position 2");
stopCar.write( 0); // position 2
delay(10000);
Serial.println("Ready");
}
}
}