Arduino - Reading Analog Voltage



    Sohail Gulam


    A potentiometer (or pot) is a simple electro-mechanical transducer. It converts rotary or linear motion from the input operator into a change of resistance. This change is (or can be) used to control anything from the volume of a hi-fi system to the direction of a huge container ship.

    The pot as we know it was originally known as a rheostat (essentially a variable wirewound resistor). The variety of available pots is now quite astonishing, and it can be very difficult for the beginner (in particular) to work out which type is suitable for a given task. A few different pot types, which can all be used for the same task makes the job harder.

    void setup() {
       // initialize serial communication at 9600 bits per second:
    // the loop routine runs over and over again forever:
    void loop() {
       // read the input on analog pin 0:
       int sensorValue = analogRead(A0);
       // 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:
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.