Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Arduino Voltmeter
- //4-Channels Voltmeter
- //Measure Voltages from 0V to 50V per channel
- //4 resistors of 100K connected to GND and the remaining terminals
- //to their respective resistors of 1M forming the 4-common points
- //connected to A2, A3, A4, and A5 respectively while the remaining
- //terminals of these last resistors are the outputs of Vr, Vw, Vy, and Vg
- #include <LiquidCrystal.h>
- #define NUM_SAMPLES 10
- #define DIV_1 11.1346
- #define DIV_2 11.1969
- #define DIV_3 11.0718
- #define DIV_4 11.0718
- #define V_REF 4.991
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- int sum[4] = {0};
- unsigned char sample_count = 0;
- float voltage[4] = {0.0};
- char l_cnt = 0;
- void setup()
- {
- lcd.begin(16, 2);
- }
- void loop()
- {
- while (sample_count < NUM_SAMPLES) {
- for (l_cnt = 0; l_cnt < 4; l_cnt++) {
- sum[l_cnt] += analogRead(A2 + l_cnt);
- }
- sample_count++;
- delay(10);
- }
- for (l_cnt = 0; l_cnt < 4; l_cnt++) {
- voltage[l_cnt] = ((float)sum[l_cnt] / (float)NUM_SAMPLES * V_REF) / 1024.0;
- }
- //the common point of a set of resistors connect to A2
- lcd.setCursor(0, 0);
- lcd.print("Vr=");
- lcd.print(voltage[0] * DIV_1, 1);
- lcd.print("V ");
- //the common point of the next set of resistors connect to A3
- lcd.setCursor(8, 0);
- lcd.print("Vw=");
- lcd.print(voltage[1] * DIV_2, 1);
- lcd.print("V ");
- //the common point of the next set of resistors connect to A4
- lcd.setCursor(0, 1);
- lcd.print("Vy=");
- lcd.print(voltage[2] * DIV_3, 1);
- lcd.print("V ");
- //the common point of the next set of resistors connect to A5
- lcd.setCursor(8, 1);
- lcd.print("Vg= ");
- lcd.print(voltage[3] * DIV_4, 1);
- lcd.print("V ");
- sample_count = 0;
- for (l_cnt = 0; l_cnt < 4; l_cnt++) {
- sum[l_cnt] = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement