# How to change the value within a variable using math? [closed]

I'm up to Lesson 11 in the TopTechBoy tutorial: https://www.youtube.com/watch?v=afurKLOqqSg

I can use the analogRead() to fill a variable with a value and Serial.printld it out, but I want to be able to increase that integer by × 4.887585533

``````int pinV; // This empty variable will be filled with an integer value between 0 and 1023.
int receiverPin=0; // This is the RX pin, a ‘receiver’ that connects to the USB to Serial interface.
int ResultsPerSec=500; // The Arduino reads and prints out a result every half second.
float printingValue; // Another empty variable that is given the pinV value to multiply and print.
void setup() {
Serial.begin(9600);
}

void loop() {
// Each Volt has a value of 204.6 (4.88 mV per integer of the 1023 available)
printingValue = (pinV *4.887585533);
// 5,000 mV divided by 1023 possible values = is 4.887585533 mV per integer
// The Arduino can count from 0 to 5 Volts in 4.887585533 mV increments.
// 1,000 mV divided by 4.887585533 mV = 204.599999989 integers out of the 1023 available equal 1V
// Each integer of the 1023 possible values that analogRead() outputs can be increased by 4.887585533
// This shows the real Voltage in millivolts (mV).
Serial.println(printingValue);
delay(ResultsPerSec);
}
``````

This is actually acceptable as far as the IDE is concerned, but it doesn't work as intended. I'm getting outputs in the thousands, when it should be printing 0 in the Serial monitor. How do I do this properly?

• 1. The voltage you should print is `5e3/1024*analogRead(A0)`. Ignore the tutorial using 1023: the datasheet is the only authoritative reference. 2. Floats do not hold decimals: they are binary, whith a machine epsilon of 2^(−23) ≈ 1.19e-7. The ratio 5e3/1024 is an exact float. 5e3/1023 is not, and the compiler rounds it to the nearest float, namely 4.88758563995361328125. The rounding error is inconsequential given the low resolution of the measurement. – Edgar Bonet May 15 '18 at 10:42