I’m really to this so my project has no real purpose. It was a way to take two lessons and try and combine them. It looked simple enough but I’m stumped.
I have a continuous rotation servo. When the angle is set at 90 degrees the servo stops, less than 90 - it rotates anti-clockwise and of course greater than 90 and it goes clockwise. That works great.
I have a second circuit, it’s a variable resistor. I can’t remember what they’re called, it’s a flat pad and the resistance goes up us you apply pressure. I hook it up, open the Serial Monitor can see the values. 0 when I’m not touching it up to around 1,000 if I squeeze really hard.
The servo is looking for a value between 0 and 180 so I map the analog read from the resistor to these values.
Perfect. The servo rotates one way, as I squeeze the resistor and the value goes past 90, the servo rotates the other way. There is no stop though. This is the part I thought would be simple. That’s what the “if” statement is for. If the resistor is reading 0, no one is touching it so send a rotation angle of 90 degrees to stop the servo.
It doesn’t happen that way. The servo never runs and when I look at the serial monitor it reads 0 all the time, no matter how hard I squeeze the resistor.
Help – Please
int valServo = 0;
myservo.attach(9); // Servo pin is on 9
myservo.write (90); // Set to 90 degrees
valServo = map(analogRead(0), 0, 1023, 0, 180);
if(valServo == 0);
valServo = 90;