If I put 5V dc to the head of zenar diode D5, then the voltage divider improves to 4.97V, I was wrong to check it. But, if we think its a 8-bit ADC, https://docs.arduino.cc/resources/datasheets/A000005-datasheet.pdf, then Resolution = Vref /(2n) − 1 = 0.019, if I place it in code it does not work. Correct me if I am wrong.you have switched controller several times (Arduino Uno, PIC, Arduino Nano, Proteus...). are you sure that ADC resolution is 1024 counts? because i know that even on Arduino Uno, there is a difference between R3 and R4. read datasheets - that is what they are for.
the crude but simple method is to get a multimeter, measure AC voltage (say you get 226VAC), then look at ADC raw value (say 580) and calculate scaling factor:
226/580=0.39
then your AC voltage is
float vac= 0.39 * analogRead(A3);
My last response to you, I was talking about this code when the relay for AC210V changes its position.
C:
int acval = 0, acvalold, actarget = 210;
int relayPin[] = {3, 4, 5, 6};
void setup() {
Serial.begin(9600);
Serial.println("meaw");
for (int i = 0; i < 4; i++) {
pinMode(relayPin[i], OUTPUT);
digitalWrite(relayPin[i], HIGH);
delay(100);
}
}
void loop() {
acval = analogRead(A0); // read the value
if (acval != acvalold) { // only update if acval updates
acvalold = acval; // store old value
Serial.print("ACval ");
Serial.print(acval);
if (acval < actarget) {
Serial.print(" is less than ");
Serial.print(actarget);
Serial.println("V. Relays ON.");
for (int i = 0; i < 4; i++) {
digitalWrite(relayPin[i], HIGH); // relays ON
}
} else {
Serial.println(". Relays OFF.");
for (int i = 0; i < 4; i++) {
digitalWrite(relayPin[i], LOW); // relays OFF
}
}
}
}
Last edited:


