Skip to content

Commit 0f19ecf

Browse files
Merge pull request #2098 from arduino/pedromsousalima/builtinexamples_AnalogVoltage_3V3
11885 - Added note for 3.3V boards (ReadAnalogVoltage)
2 parents f0da8e3 + 41a9219 commit 0f19ecf

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

content/built-in-examples/01.basics/ReadAnalogVoltage/ReadAnalogVoltage.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Connect the three wires from the potentiometer to your board. The first goes to
2828

2929
By turning the shaft of the potentiometer, you change the amount of resistance on either side of the wiper which is connected to the center pin of the potentiometer. This changes the voltage at the center pin. When the resistance between the center and the side connected to 5 volts is close to zero (and the resistance on the other side is close to 10 kilohms), the voltage at the center pin nears 5 volts. When the resistances are reversed, the voltage at the center pin nears 0 volts, or ground. This voltage is the **analog voltage** that you're reading as an input.
3030

31-
The microcontroller of the board has a circuit inside called an *analog-to-digital converter* or *ADC* that reads this changing voltage and converts it to a number between 0 and 1023. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In between, [analogRead](https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/)() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
31+
The microcontroller of the board has a circuit inside called an *analog-to-digital converter* or *ADC* that reads this changing voltage and converts it to a number between 0 and 1023 (on boards with a 10 bit resolution ADC). When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In between, [analogRead](https://www.arduino.cc/reference/en/language/functions/analog-io/analogread/)() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
3232

3333
### Schematic
3434

@@ -48,6 +48,8 @@ To change the values from 0-1023 to a range that corresponds to the voltage the
4848

4949
`float voltage= sensorValue * (5.0 / 1023.0);`
5050

51+
***Please note that this example was initially conceived for 5V boards. If you are using a 3.3V board, you should change '5.0' to '3.3' in the code above to ensure it correctly aligns with your hardware. Similarly, if you are using a board with a default ADC resolution different from 10 bits, you must change the value '1023' to correspond to the number of discrete levels supported by your hardware.***
52+
5153
Finally, you need to print this information to your serial monitor. You can do this with the command [Serial.println](https://www.arduino.cc/en/Serial/Println)() in your last line of code:
5254

5355
`Serial.println(voltage)`

0 commit comments

Comments
 (0)