Translate

Mastering Analog Inputs: Measuring Voltage with Arduino Uno

 In the world of basic electronics, learning how to read analog signals is a fundamental skill. Unlike digital signals, which are simply HIGH or LOW, analog signals allow us to measure a range of values—essential for using sensors like potentiometers, light sensors, or thermistors.

In this tutorial, we will use an Arduino Uno and a potentiometer to create a simple voltmeter that displays real-time voltage on your computer screen.


Components Needed

  • Arduino Uno Board

  • Potentiometer (e.g., 10k ohm)

  • Breadboard

  • Jumper Wires

  • USB Cable to connect to your PC


The Circuit and Connection


Follow the wiring as shown in your breadboard diagram:
  • VCC (Power): Connect the 5V pin of the Arduino to the left outer pin of the potentiometer (Red Wire).

  • GND (Ground): Connect the GND pin of the Arduino to the right outer pin of the potentiometer (Black Wire).

  • Signal (Analog): Connect the middle pin (wiper) of the potentiometer to the A0 analog pin on the Arduino (Yellow Wire).

As you turn the knob, the voltage at the middle pin changes between 0V and 5V.


The Working Program

Copy this code into your Arduino IDE to start reading data:

void setup() {
  // Start the serial communication
  Serial.begin(9600);
}

void loop() {
  // Read the input on analog pin 0
  int sensorValue = analogRead(A0);

  // Convert the raw value (0 - 1023) to a voltage (0 - 5V)
  float voltage = sensorValue * (5.0 / 1023.0);

  // Print the results to the Serial Monitor
  Serial.print("Voltage: ");
  Serial.print(voltage);
  Serial.println(" V");

  // Wait half a second so the data is easy to read
  delay(500); 
}

Detailed Program Explanation

To help you understand the logic behind the code, here is a line-by-line breakdown:

1. The Setup

  • Serial.begin(9600);: This opens the communication channel between the Arduino and your computer at a speed of 9600 bits per second.

2. Capturing the Signal

  • int sensorValue = analogRead(A0);: The Arduino uses a 10-bit Analog-to-Digital Converter (ADC). It takes the voltage at pin A0 and converts it into a digital number between 0 and 1023.

3. The Math (Conversion)

  • float voltage = sensorValue * (5.0 / 1023.0);: Since we want to see the actual voltage (0–5V) instead of a raw number (0–1023), we use this formula. We use float because voltage readings require decimal points.

4. Output and Timing

  • Serial.println(voltage);: This sends the converted value to your Serial Monitor.

  • delay(500);: This pauses the loop for 500 milliseconds. Without this, the numbers would scroll too fast for you to read.


Conclusion

Reading analog values is the gateway to more advanced projects. Whether you are building a light-sensing nightlight or a temperature monitor, the logic remains the same.

തുടക്കക്കാർക്കായി ഇലക്ട്രോണിക്സ് ലളിതമായി പഠിക്കാം.

Empowering students in Kerala with hands-on technical skills.