Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // number of analog samples to take per reading
- #define NUM_SAMPLES 10
- int sum1 = 0;
- int sum2 = 0;
- int sum3 = 0;
- unsigned char sample_count = 0; // current sample number
- float voltage1 = 0.0; // calculated voltage
- float voltage2 = 0.0;
- float voltage3 = 0.0;
- void setup()
- {
- analogReference(INTERNAL);
- pinMode(A5, INPUT);
- pinMode(A6, INPUT);
- pinMode(A7, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- // take a number of analog samples and add them up
- while (sample_count < NUM_SAMPLES) {
- sum1 += analogRead(A5);
- sum2 += analogRead(A6);
- sum3 += analogRead(A7);
- sample_count++;
- delay(10);
- }
- // calculate the voltage
- // use 5.0 for a 5.0V ADC reference voltage
- // 5.015V is the calibrated reference voltage
- voltage1 = ((float)sum1 / (float)NUM_SAMPLES * 5.015) / 1024.0;
- voltage2 = ((float)sum2 / (float)NUM_SAMPLES * 5.015) / 1024.0;
- voltage3 = ((float)sum3 / (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(voltage1 * 11.132);
- Serial.println (" V ");
- Serial.print(voltage2 * 11.132);
- Serial.println (" V ");
- Serial.print(voltage3 * 11.132);
- Serial.println (" V ");
- sample_count = 0;
- sum1 = 0;
- sum2 = 0;
- sum3 = 0;
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement