I currently have an Arduino Uno hooked up with an EasyDriver and a NEMA 17 stepper motor. I have a power supply that can be dialed in from -15V to 15V. I dial in 12 volts to power the EasyDriver. What I want to do is to have that voltage read to the serial monitor. The reason why I want that is so I can build some if else statements and have my motor spin clockwise if the voltage is less than 12 volts and spin counter clockwise if the voltage is greater than 12 volts. Right now I have that power supply hooked up to pin A0. How would I go about reading the voltage of the power supply? I think it would be something like this but I would need to know the right ADC.
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
I would then take that voltage value and go from there with the stepper motor.