The examples in this, or any series of tutorials, should have a meaningful progression, and, so, I want to test my understanding of the example named in the title, and hopefully get useful insight I might be missing. The first thing I notice is that ReadAnalogVoltage uses the same schematic and circuit board layout as AnalogReadSerial, example #1, in set 01. The code is the same except for the following differences:

``````  // read the input on analog pin 0:
// print out the value you read:
Serial.println(sensorValue);
delay(1);        // delay in between reads for stability
}
``````
``````  // 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 understand "float" means write a value with a decimal, in other words, a floating decimal number. The board voltage is 5.0, which is divided by 1023.0. In the simple potentiometer example the serial reading is an arbitrary integer, or int, between 0-1023, depending on my twist of the knob.
Now, to get to my question, can the voltage factor be exchanged for another value, such as degrees Celsius, if I were to replace the potentiometer with a temperature sensor? My guess is the fraction within the parentheses would be 100.0 / 1203.0. Can it be that simple? And what would the schematic look like? Thanks.

brianeo wrote (in part):

My guess is the fraction within the parentheses would be 100.0 / 1203.0

I think that you intended 100.0/1023.0 (notice the reversal of the zero and the two).
This is true IF and ONLY IF you use a temperature sensor that senses 0 degrees for an analog reading of 0 (which is at 0 volts), and senses 100 degrees for an analog reading of 1023 (which is at 5 volts), and is linear between those two points (some are, some are not).

The map(...) function may be of help to you. Unfortunately, the map(...) function does integer math and not floating point math. You may want to do what the map(...) function does but do it yourself using floating point values. Simple floating point math will work with linear sensors.

Thanks for catching my error transposing the number 1203 for 1023. Very important! And, concerning my idea for using a temperature sensor with the ReadAnalogVoltage example, after thinking about it, I decided there are better tutorials ahead for such things. For now, how can I check the serial monitor reading against a multimeter reading? I would like to compare readings. It seems to me the new setup code would assign a pin, or pins, for contact with the multimeter probes. In the loop, there would be a function for sending to the new pins the same data being sent to the serial monitor. My multimeter probes don't fit the header pins of my Uno board, but I can put a wire into the assigned header pin hole, and touch the multimeter probe to the wire. Any suggestions appreciated.

If you want to compare with the meter then use your meter probes to measure the same pin or wire that the sketch is reading. You don't need Arduino to output anything for that. Just read it directly and compare what you see on the meter with what you see on the serial monitor.

I am not getting the expected result. Please see schematic, attached. Which pins give the same reading to a multimeter as the serial monitor? There are three. This is the code, if an IDE with Example sketches is not available:

``````/*
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {a
// read the input on analog pin 0:
// 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);
}
``````

Thanks!

Between GND and A0 you should get the same reading an seen in serial monitor.

It is working! My hand-drawn schematic showing placement of multimeter probes is attached. Also attached is a snapshot of an actual multimeter reading next to the serial monitor on the desktop screen. If space permitted, I could include a video showing the values change on both displays at the same rate as I twist the potentiometer knob. I realize this is an extremely simple concept, but one that had me stuck. Code is not the answer. I have more questions about what is happening on the Arduino board between A0 and the serial monitor. I will post them on the General Electronics forum, not Programming. Thanks to all who responded.

brianeo:
It is working! My hand-drawn schematic showing placement of multimeter probes is attached. Also attached is a snapshot of an actual multimeter reading next to the serial monitor on the desktop screen. If space permitted, I could include a video showing the values change on both displays at the same rate as I twist the potentiometer knob. I realize this is an extremely simple concept, but one that had me stuck. Code is not the answer. I have more questions about what is happening on the Arduino board between A0 and the serial monitor. I will post them on the General Electronics forum, not Programming. Thanks to all who responded.

It's quite simple what's happening there. analogRead tells it to get the analog reading from that pin, which produces a number between 0 and 1023 and gets stored in the sensorValue variable that you made there. Then you are doing some math on that value and storing the result in another variable that you've named "voltage". And then finally you are printing that variable out to the serial monitor. Nothing else magical is happening.

Which Arduino do you have? If Nano, the AREF voltage will be about 4.75V, not 5V, with the program running, measure the voltage from GND to the AREF pin and use that in your program instead of 5.0.

``````float aRef = 4.75; // measured with DMM
float volts = analogRead(A0) * aRef / 1024;
Serial.println(volts,1);
delay(300);
``````

I had to search AREF. Link below about it. It does not look like something I can use at this time -but I might be wrong about that. At this point, I am still separating analog from digital concepts.
After I tried checking circuit board voltage against serial monitor print with this tutorial, I can imagine building a multimeter project on an Arduino board. Ideally, it would be a complete diagnostic device for any given board. Twist a knob to select board type, plug it in, and see what’s going on, on your desktop. Sell a million of them.

https://www.arduino.cc/en/Reference/analogReference

What I was getting at is you're assuming 5.0 is your reference voltage, it could be 4.9 or 5.1, thats why I always check first with a DMM and enter that value in my "float aRef" variable.
Send me the first model of your device, I'll critique it free of charge