Hide minor edits - Show changes to markup
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.
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 0 to the middle pin of the potentiometer.
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino lang=arduino tabwidth=4:)
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:
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:
(:source http://github.com/arduino/Arduino/raw/new-extension/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/new-extension/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.ino lang=arduino tabwidth=4:)
click the image to enlarge
(:include BasicsSeeAlsoIncludes :)
This example shows you how to read analog input from the physical world using a potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
This example shows you how to read analog input from the physical world using a potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a potentiometer (or pot for short) as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
By turning the shaft of the potentiometer, you change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and a 0 value is read. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and a 1023 value is reported. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
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.
int sensorValue = analogRead(0);
Finally, you need to print this information to our serial window as a decimal (DEC) value. You can do this with the command Serial.println() in your last line of code:
int sensorValue = analogRead(A0);
Finally, you need to print this information to your serial window as a decimal (DEC) value. You can do this with the command Serial.println() in your last line of code:
A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
This example shows you how to read analog input from the physical world using a potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
By turning the shaft of the potentiometer, you change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and a 0 value is read. When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and a 1023 value is reported. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
Finally, we need to print this information to our serial window as a decimal (DEC) value. You can do this with the command Serial.println() in your last line of code:
Finally, you need to print this information to our serial window as a decimal (DEC) value. You can do this with the command Serial.println() in your last line of code:
=======
=======
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-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will respond nearly instantly.
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-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will respond almost instantly.
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-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will change almost instantly.
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-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will respond nearly instantly.
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) coming in from your potentiometer:
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:
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-1023, depending on the position of the pot. As you turn your potentiometer, this numbers will change almost instantly.
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-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will change almost instantly.
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:
In the program below, the only 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 command:
Next, initialize analog Input pin 0, the pin that will read the output from your potentiometer, as an input:
pinMode(0,INPUT);
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) coming in from your potentiometer:
int sensorValue = analogRead(0);
Finally, we need to print this information to our serial window as a decimal (DEC) value. You can do this with the command Serial.println() in your last line of code:
Serial.println(sensorValue, 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-1023, depending on the position of the pot. As you turn your potentiometer, this numbers will change almost instantly.
pinMode(0,INPUT);
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:
Serial.begin(9600);
Next, initialize analog Input pin 0, the pin that will read the output from your potentiometer, as an input:
Describe what's going on here
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead?() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead?() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
A potentiometer is a simple mechanical device that provides a varying amount of resistance when turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
A potentiometer is a simple mechanical device that provides a variable resistance. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
A potentiometer is a simple mechanical device that provides a varying amount of resistance when turned. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. In this example you will monitor the state of your potentiometer by establishing .
A potentiometer is a simple mechanical device that provides a variable resistance. By passing voltage through a potentiometer and into an analog input on your Arduino, it is possible to measure the amount of resistance produced by a "pot" as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino and your computer.
Description
A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. In this example you will monitor the state of your potentiometer by establishing .
By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative "closeness" of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.
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.
(:source http://github.com/arduino/Arduino/raw/master/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/build/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/libraries/Ethernet/examples/WebClient/WebClient.pde lang=arduino tabwidth=4:)
(:source http://github.com/arduino/Arduino/raw/master/shared/examples/1.Basics/AnalogReadSerial/AnalogReadSerial.pde lang=arduino tabwidth=4:)
Examples > Basics
Description
(:div class=BOM :)
(:divend:)
(:div class=circuit :)
image developed using Fritzing. For more circuit examples, see the Fritzing project page
(:divend:)
(:div class=circuit :)
(:divend:)
Describe what's going on here
(:div class=code :) (:source http://github.com/arduino/Arduino/raw/master/libraries/Ethernet/examples/WebClient/WebClient.pde lang=arduino tabwidth=4:) (:divend:)