a common radio control servo has a motor that drives a gear train with the output shaft connected to a pot. beacuse of the gear train, the motor has to turn many times to move the output shaft just a fraction of a turn.
circuitry compares the position of the pot to a control signal indicating the target postion.
I will need to use the code the control 4 different motors. The motors are wing mirrors of a car. So I need it to be more if its moving cw and the reading on A0 hasn't changed stop the motor or if its moving ccw do the same
Ok, back to your first post. With your DVM, measure the voltage on the pot wiper and make a mirror motor go from one limit to the other. Record the voltages you see on the DVM. Those voltages will be your limits. Any voltage in between will relate to the mirror position, as you know.
Then connected to A0 of your Arduino, display the raw values on the serial monitor as you make the same motor movements as your did for the DVM. Record these values as they will be the limits your code will be looking for to stop the motor movement.
I have Recorded the values of the pots for each motor but they are all different.
Is there a simple code that will check if A0 is incrementing or decrementing and stop the motor if it has not changed
I tried this code but didn't work
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue; // variable to store the value coming from the sensor
int oldSensorValue;
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
if (sensorValue++ || sensorValue--) {
oldSensorValue = sensorValue;
if (sensorValue != oldSensorValue)
digitalWrite(ledPin, LOW);
else
digitalWrite(ledPin, HIGH);
}
}