Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views1 page

Arduino Voltmeter New

The document describes a program for an Arduino Uno that measures voltage using a voltage divider on analog input A2. It takes multiple analog samples, calculates the average voltage, and outputs the result to the Serial Monitor. The program is compatible with Arduino software version 1.0 and above, and was authored by W.A. Smith in May 2013.

Uploaded by

trendigital.pku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views1 page

Arduino Voltmeter New

The document describes a program for an Arduino Uno that measures voltage using a voltage divider on analog input A2. It takes multiple analog samples, calculates the average voltage, and outputs the result to the Serial Monitor. The program is compatible with Arduino software version 1.0 and above, and was authored by W.A. Smith in May 2013.

Uploaded by

trendigital.pku
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

ARDUINO VOLTMETER NEW

/*--------------------------------------------------------------
Program: volt_measure

Description: Reads value on analog input A2 and calculates


the voltage assuming that a voltage divider
network on the pin divides by 11.

Hardware: Arduino Uno with voltage divider on A2.

Software: Developed using Arduino 1.0.5 software


Should be compatible with Arduino 1.0 +

Date: 22 May 2013

Author: W.A. Smith, http://startingelectronics.org


--------------------------------------------------------------*/

// number of analog samples to take per reading


#define NUM_SAMPLES 10

int sum = 0; // sum of samples taken


unsigned char sample_count = 0; // current sample number
float voltage = 0.0; // calculated voltage

void setup()
{
Serial.begin(9600);
}

void loop()
{
// take a number of analog samples and add them up
while (sample_count < NUM_SAMPLES) {
sum += analogRead(A2);
sample_count++;
delay(10);
}
// calculate the voltage
// use 5.0 for a 5.0V ADC reference voltage
// 5.015V is the calibrated reference voltage
voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
// send voltage for display on Serial Monitor
// voltage multiplied by 11 when using voltage divider that
// divides by 11. 11.132 is the calibrated voltage divide
// value
Serial.print(voltage * 11.132);
Serial.println (" V");
sample_count = 0;
sum = 0;
}

You might also like