Hi, newbie here
I want to toggle my pressure sensor so that if pressure is applied to the sensor and released, the servo motor rotates to 0 degrees. If the same action is done again, the servo motor rotates back to 90 degrees.
Here is my code as of now
#include <Servo.h>
Servo servo;
int reading;
void setup(void) {
Serial.begin(9600);
servo.attach(9);
servo.write(90);
}
void loop(void) {
reading = analogRead(A0);
int value = map(reading, 0, 1023, 0, 180);
if (value < 10){
servo.write(90);
delay(20);
} else {
servo.write(0);
delay(20);
}
Serial.print("Sensor value = ");
Serial.println(reading);
delay(100);
}