Introduction: READ ANALOG VOLTAGE - ARDUINO - CODE REVEAL #1

CODE REVEAL #1

READ ANALOG VOLTAGE:

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).

Step 1: HARDWARE REQUIRED:

Arduino or Genuino Board,
10k OHM Potentiometer.

Step 2: SAFETY PRECAUTIONS; HEALTHY USAGE:

BE AWARE THAT EXTERNAL POWER SUPPLY USAGE ON THE ANALOG PIN OF THE ARDUINO SHOULD NOT EXCEED 5V, BECAUSE ARDUINO WORKS AT 5V LOGIC, AND THE MICROCONTROLLER CAN BURN OUT IF THE VOLTAGE IS HIGHER THAN 5V. THIS PROJECT IS USEFUL FOR CHECKING THE VOLTAGE OF SMALL PENCIL OR LITHIUM BATTERIES AND TRIMPOTS.

Step 3: CIRCUIT:

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 0.
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 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.

Step 4: CODE:

To be noted that if you don't have a computer or a laptop, you can program your Arduino with the app 'Arduinodroid' available at Google Play Store. You can visit the serial monitor with the help of 'Arduinodroid'.

void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0); float voltage = sensorValue * (5.0 / 1023.0);
Serial.println(voltage);
}

Step 5: The Instagram Post

Visit this Instagram post where I described this project - https://www.instagram.com/p/BwwZ6r1hLLx/?utm_source=ig_share_sheet&igshid=19hxbax53ggmw