I dont think the issue is with the code but my wiring! However
DC Voltmeter Using a Voltage Divider
Based on Code Created By
Amended by SMDE 10 August 2016
Added in two sensors, etc.
int analogInput = A1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000.0; //
float R2 = 7500.0; //
int value = 0;
// read the value at analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0; // see text
vout2 = (value2 * 5.0)/1024.0;
vin = vout / (R2/(R1+R2));
vin2 = vout2 / (R4/(R3+R4));
vmotor = 19-vin;
vmotor2 = 19-vin2;
Serial.print("INPUT V1= ");
Serial.println("Sensor 2= ");
The sensor is one of these http://www.ebay.co.uk/itm/25v-Voltage-Sensor-Module-Hobby-Electronics-Arduino-Raspberry-Pi-Robot-UK-/181884273832?hash=item2a5925c4a8:g:CwMAAOSwWnFWBxCt - there is no identifying number etc.
The M is the motor in the scalextric car as the potentiometer is the variable resistor in the handcontroller!
Track voltage is 19v of which < 1V goes to the car when the handcontroller is not "squeezed". As the trigger on the controller is squeezed the variable resistance changes and the voltage across the car motor rises and the car moves until at full "squeeze" the voltage across the car motor is 18 odd volts.
As regards the splicing, it is sheathed in insulating tape which is difficult to remove, but it is just a controller wire (red for +ve, green for GND) cut, stripped, rejoined with an additional piece added in for the connection to the voltage sensor. All the connections are soldered.
Ahhhh, I see. Your code is correct except that the voltage across the motor IS Vout (NOT 19-Vout as you have in your code). As for the electrical short you mention in your original post, bad wiring is most likely to blame (it happens to the best of us).
As a side note: stay as far away from voltage dividers as you can. If you need to measure voltages above 5V, use zener diodes to knock down the voltage. For instance: in my experimental Arduino RC airplane, I have to measure my batteries voltage (which is max 12.6V each). At first, I tried using a voltage divider, but due to ground currents and inaccurate resistor values, it didn’t work. Instead, I now use 10V zener diodes in series and they work like a charm. They are MUCH simpler, much less fickle, and are guaranteed to work within the limits specified in their datasheets.