I made a circuit bellow for you. Note that the top resistor is 100 ohm and the bottom one is only 10 ohm. What I did is called a voltage divider. This way you can read voltages up to 50V. Simply connect the positive of your power source that you want to measure to the red wire and the ground of that same source to the black wire.
I also included a code that you could use:
Please notify me if any mistakes were spotted.
#define sensor A0 //defining sensor pin
float int resistor1 = 100; //you can change it if you want, just make sure you also do it on the circuit
float int resistor2 = 10;
float Vmax = (5*resistor1 + 5* resistor2)/resistor2;
void setup() {
pinMode(sensor, INPUT); //declaring sensor as an output
Serial.begin(9600);
Serial.print("Do not input more then (V) : "); // print max input voltage
Serial.print(Vmax);
Serial.println(); //skip line
}
void loop() {
float V = analogRead(sensor); //measuring analog values
V = analogRead(sensor) * Vmax / 1024
Serial.println(V); //printing voltage
}
