July 29, 2015, at 09:59 PM by Simone Maiocchi -
Changed lines 7-11 from:

This example shows you how to read an analog input on Pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor of the Arduino Software (IDE).

to:

This example shows you how to read an analog input on analog pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor of the Arduino Software (IDE).

July 29, 2015, at 09:44 PM by Simone Maiocchi -
Changed line 69 from:
to:
July 29, 2015, at 09:44 PM by Simone Maiocchi -
Changed lines 65-67 from:
to:
July 29, 2015, at 09:42 PM by Simone Maiocchi -
Changed lines 9-11 from:

This example shows you how to read an analog input on Pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor.

to:

This example shows you how to read an analog input on Pin 0, convert the values from analogRead() into voltage, and print it out to the serial monitor of the Arduino Software (IDE).

Changed lines 30-31 from:

The Arduino has a circuit inside called an analog-to-digital converter 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() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

to:

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() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Changed lines 41-42 from:

In the program below, the very first thing that you do will in the setup function is to begin serial communications, at 9600 bits of data per second, between your Arduino and your computer with the line:

to:

In the program below, the very first thing that you do will in the setup function is to begin serial communications, at 9600 bits of data per second, between your board and your computer with the line:

July 29, 2015, at 09:38 PM by Simone Maiocchi -
Changed lines 7-8 from:

to:

Changed line 13 from:

to:

### Hardware Required

Changed line 19 from:

to:

### Circuit

Changed lines 72-75 from:
to:
July 09, 2015, at 03:18 PM by Simone Maiocchi -
Changed line 2 from:

Tutorials > Examples? > USB > Basics > ReadAnalogVoltage

to:

Tutorials > Examples? > Basics > ReadAnalogVoltage

July 09, 2015, at 03:18 PM by Simone Maiocchi -
Changed lines 1-2 from:

Examples > Basics

to:
Deleted lines 11-12:
Changed lines 13-16 from:

### Hardware Required

• Arduino Board
• a variable resistor, like a potentiometer
to:

#### Hardware Required

• Arduino or Genuino Board
• 10k ohm potentiometer
Changed line 19 from:

### Circuit

to:

#### Circuit

Deleted line 23:
Changed lines 26-27 from:

Connect the three wires from the potentiometer to your Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer.

to:

Connect the three wires from the potentiometer to your board. The first goes to ground from one of the outer pins of the potentiometer. The second goes to 5 volts from the other outer pin of the potentiometer. The third goes from the middle pin of the potentiometer to analog input 2.

Changed lines 57-58 from:

Now, when you open your Serial Monitor in the Arduino development environment (by clicking the button directly to the right of the "Upload" button in the header of the program), you should see a steady stream of numbers ranging from 0.0 - 5.0. As you turn the pot, the values will change, corresponding to the voltage coming into pin A0.

to:

Now, when you open your Serial Monitor in the Arduino IDE (by clicking on the icon on the right side of the top green bar or pressing Ctrl+Shift+M), you should see a steady stream of numbers ranging from 0.0 - 5.0. As you turn the pot, the values will change, corresponding to the voltage coming into pin A0.

Changed lines 65-67 from:
to:
February 02, 2014, at 11:41 AM by Scott Fitzgerald -
Changed lines 50-51 from:

`float voltage= sensorValue * (5.0 / 1024.0);`

to:

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

January 31, 2013, at 11:54 AM by Roberto Guido - minor typo in example code, thanks to Nicolas Charvin for alert
Changed lines 50-51 from:

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

to:

`float voltage= sensorValue * (5.0 / 1024.0);`

May 02, 2012, at 03:35 AM by Scott Fitzgerald -
Changed line 59 from:
to:
April 16, 2012, at 07:41 PM by Scott Fitzgerald -
Changed lines 54-55 from:

` Serial.println(voltage, DEC)`

to:

` Serial.println(voltage)`

April 16, 2012, at 07:31 PM by Scott Fitzgerald -
Changed lines 66-68 from:
to:
Changed lines 69-70 from:
to:
April 16, 2012, at 07:29 PM by Scott Fitzgerald -
Changed lines 14-16 from:
• hook-up wire
to:
Changed lines 19-22 from:

to:

April 16, 2012, at 07:29 PM by Scott Fitzgerald -
Changed lines 50-53 from:

To change the values from 0-1023 to a range that corresponds to the voltage the pin is reading, you'll need to create another variable, a `float`, and use the `map` function. `Map` takes the value you stored in sensorValue and scales it between 0.0. and 5.0 :

`float voltage=map(sensorVal, 0, 1023, 0.0, 5.0);`

to:

To change the values from 0-1023 to a range that corresponds to the voltage the pin is reading, you'll need to create another variable, a `float`, and do a little math. To scale the numbers between 0.0 and 5.0, divide 5.0 by 1023.0 and multiply that by sensorValue :

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

April 16, 2012, at 07:26 PM by Scott Fitzgerald -
Changed lines 21-24 from:

to:

Changed lines 27-32 from:

Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.

Pushbuttons or switches connect two points in a circuit when you press them. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and reads as LOW, or 0. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to 5 volts, so that the pin reads as HIGH, or 1.

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, it doesn't have a solid connection to voltage or ground, and it will randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

to:

Connect the three wires from the potentiometer to your Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer.

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.

The Arduino has a circuit inside called an analog-to-digital converter 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() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.

Changed line 37 from:
to:
Changed lines 46-62 from:

Next, initialize digital pin 2, the pin that will read the output from your button, as an input:

`pinMode(2,INPUT);`

Now that your setup has been completed, move into the main loop of your code. When your button is pressed, 5 volts will freely flow through your circuit, and when it is not pressed, the input pin will be connected to ground through the 10-kilohm resistor. This is a digital input, meaning that the switch can only be in either an on state (seen by your Arduino as a "1", or HIGH) or an off state (seen by your Arduino as a "0", or LOW), with nothing in between.

The first thing you need to do in the main loop of your program is to establish a variable to hold the information coming in from your switch. Since the information coming in from the switch will be either a "1" or a "0", you can use an` int `datatype. Call this variable `sensorValue`, and set it to equal whatever is being read on digital pin 2. You can accomplish all this with just one line of code:

`int sensorValue = digitalRead(2);`

Once the Arduino has read the input, make it print this information back to the computer as a decimal value. You can do this with the command Serial.println() in our last line of code:

`Serial.println(sensorValue);`

Now, when you open your Serial Monitor in the Arduino environment, you will see a stream of "0"s if your switch is open, or "1"s if your switch is closed.

to:

Next, in the main loop of your code, you need to establish a variable to store the resistance value (which will be between 0 and 1023, perfect for an ` int `datatype) coming in from your potentiometer:

` int sensorValue = analogRead(A0);`

To change the values from 0-1023 to a range that corresponds to the voltage the pin is reading, you'll need to create another variable, a `float`, and use the `map` function. `Map` takes the value you stored in sensorValue and scales it between 0.0. and 5.0 :

`float voltage=map(sensorVal, 0, 1023, 0.0, 5.0);`

Finally, you need to print this information to your serial window as. You can do this with the command Serial.println() in your last line of code:

` Serial.println(voltage, DEC)`

Now, when you open your Serial Monitor in the Arduino development environment (by clicking the button directly to the right of the "Upload" button in the header of the program), you should see a steady stream of numbers ranging from 0.0 - 5.0. As you turn the pot, the values will change, corresponding to the voltage coming into pin A0.

Changed line 75 from:
to:
April 16, 2012, at 06:12 PM by Scott Fitzgerald -
Changed line 64 from:
to:
April 16, 2012, at 06:11 PM by Scott Fitzgerald -