VOLTAGE MEASUREMENT

Voltage meas

// 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

voltage = ((float)sum / (float)NUM_SAMPLES * 5) / 1024.0;

// send voltage for display on Serial Monitor

Serial.print(voltage * 11);

Serial.println (” V”);

sample_count = 0;

sum = 0;

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s