Arduino - AnalogRead Serial With Potentiometer

by MertArduino in Circuits > Arduino

21866 Views, 54 Favorites, 0 Comments

Arduino - AnalogRead Serial With Potentiometer

Arduino Basic Tutorial 03 - analogRead Serial Monitor with Potentiometer

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 board, 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 or Genuino and your computer running the Arduino Software (IDE).

Reference : https://www.arduino.cc/en/Tutorial/AnalogReadSerial

AnalogRead()

vlcsnap-2016-11-16-02h14m58s172.png
vlcsnap-2016-11-16-02h15m07s472.png

Reads the value from the specified analog pin. The Arduino board contains a 6 channel (8 channels on the Mini and Nano, 16 on the Mega), 10-bit analog to digital converter. This means that it will map input voltages between 0 and 5 volts into integer values between 0 and 1023. This yields a resolution between readings of: 5 volts / 1024 units or, .0049 volts (4.9 mV) per unit. The input range and resolution can be changed using analogReference().

It takes about 100 microseconds (0.0001 s) to read an analog input, so the maximum reading rate is about 10,000 times a second.

Syntax

analogRead(pin)

Parameters

pin: the number of the analog input pin to read from (0 to 5 on most boards, 0 to 7 on the Mini and Nano, 0 to 15 on the Mega)

Returns

int (0 to 1023)

Note

If the analog input pin is not connected to anything, the value returned by analogRead() will fluctuate based on a number of factors (e.g. the values of the other analog inputs, how close your hand is to the board, etc.).

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

Hardware Required

vlcsnap-2016-11-16-02h15m36s227.png

  • Arduino Uno
  • 10K Potentiometer
  • Wires

Connections

vlcsnap-2016-11-16-02h15m42s643.png
vlcsnap-2016-11-16-02h15m54s079.png
vlcsnap-2016-11-16-02h16m04s503.png
vlcsnap-2016-11-16-02h16m24s486.png
vlcsnap-2016-11-16-02h16m30s167.png
vlcsnap-2016-11-16-02h16m55s402.png
vlcsnap-2016-11-16-02h17m00s746.png

  • Attach the center pin of a potentiometer to Analog 0 (A0)
  • And the outside pins to +5V and ground (GND)

Code

vlcsnap-2016-11-16-02h17m28s877.png

// This example code is in the public domain

void setup() {

Serial.begin(9600);

}

void loop() {

int sensorValue = analogRead(A0);

Serial.println(sensorValue);

delay(1);

}

// reference : https://www.arduino.cc/en/Tutorial/AnalogReadSerial

If It Helps, Please Subscribe

vlcsnap-2016-11-16-02h18m05s170.png

First of all, I would like to thank you for reading this guide ! I hope it helps you.

If you want to support me, you can subscribe my channel and watch my videos.

Visit My Youtube Channel