I have successfully constructed a DC generator for charging a 24v battery bank. I am using an Arduino uno to control the throttle using a servo. It works well but the arduino just randomly cuts out.
Connected between A0 and ground is the voltage sensor which is just a voltage divider consisting of a 10K resistor and a 5K potentiometer for calibration. If 32v goes in 5v comes out to the ADC. My batteries never go above 32v.
I am powering the arduino off a 3s lipo battery at the moment and the servo is on its own separate buck converter which is attached to the same battery.
I am using the servo example and only changed one line where the ADC is mapped to the servo.
Servo myservo; // create servo object to control a servo
int potpin = 0; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
myservo.attach(9); // attaches the servo on pin 9 to the servo object
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 784, 1000, 0, 180); // scale it to use it with the servo (value between 0 and 180)884 954
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there