Go Down

### Topic: AC voltage measuring using arduino (Read 7504 times)previous topic - next topic

#### RBR

#15
##### Mar 07, 2012, 04:08 am
@retrolefty

But my doubt is about the fluctuation in the voltage ranging between 200-230?
How can I include this?

#### retrolefty

#16
##### Mar 07, 2012, 04:17 am

@retrolefty

But my doubt is about the fluctuation in the voltage ranging between 200-230?
How can I include this?

I don't understand your doubts. If the line voltage varies then the analog input pin DC voltage will vary, tracking that change in line voltage, correct? And the map function will recalculate the value everytime you call it with the results of a new analogRead() command. You only have to validate the conversion factor value (the 230 value used in the map function in our examples so far) one time by comparing what the program prints out Vs what a meter reading of actual line volt is at the same time. Just adjust the 230 value in the map function until there is agreement and your program will succefully track changing AC line voltage just fine from then on.

That make sense?

Lefty

#### RBR

#17
##### Mar 07, 2012, 06:26 am
@Magician

Quote

Corrected: just noticed a drawings, there is only one diode, off-set about  230 x 0.7 / 3 x 1.414 = 38 V

#### Techone

#18
##### Mar 07, 2012, 06:44 am
Let me get in this tread.

@RBR

I did a project to monitor AC voltage.

I check your circuit, it look OK, as long the V out is not over 5 V.

So, To figure this out, you need this :

1. What is the voltage at that output of your circuit ?   example : 3 V
2. What is the AC main voltage in rms ?  example : 122 V
3. What is the A Vref voltage ?  example : 5 V

So let calculate the ratio.  122 / 3 = 40.6666667

Let calculate a "step" value :  5 V / 1023 = 0.004887585 V

So Vin is the 3 V at the analog pin and 3 V is  :  614  =  value = analogRead( Vin );

Let do a code :

Code: [Select]
`value = analogRead( Vin );Vac = ( float (value) * ( 5.0 / 1023.0 ) ) * ( 122.0 / 3.0 ); Serial.print( Vac, 3);`

Any question ?

#### Techone

#19
##### Mar 07, 2012, 06:46 am
Anyway.

Here my project code.

Code: [Select]
`/*   Size : 6810 Bytes      Version 2.0      AC Frequency and AVC Main monitor      By Serge J Desjardins    aka techone / tech37      Toronto, ON Canada      Compile - Tested - Calibrated*/#include <LiquidCrystal.h>LiquidCrystal lcd(12,11,10,9,8,7);byte sw_mode=3;byte inpulse=2;byte voltpin=1;boolean what_mode;const int number_of_samples = 50;const float main_ratio = 40.63018242;unsigned long duration_ton;unsigned long average_ton;unsigned long sample_the_pulse;unsigned long duration_toff;unsigned long average_toff;unsigned long total_adc;unsigned int sample_the_adc;unsigned int average_adc;float frequency;float voltage;float single_step;float voltage_out;float duty_cycle;void setup(){  analogReference(DEFAULT);  pinMode(inpulse, INPUT);  pinMode(sw_mode, INPUT);  Serial.begin(9600);  lcd.begin(16, 2);  lcd.clear();  lcd.print("Main:");  lcd.setCursor(12,0);  lcd.print("VAC");  lcd.setCursor(0,1);  lcd.print("F:");  lcd.setCursor(7,1);  lcd.print(" Hz D:");  lcd.setCursor(15,1);  lcd.print("%");  single_step=4.92/1023.0;  delay(5000);  what_mode = digitalRead(sw_mode);  delay(100);  if ( what_mode == 0 )  {    Serial.print(" S ");    Serial.print(main_ratio, 8);    Serial.print(' ');    Serial.print(single_step, 8);    Serial.print(" E ");      }   }void loop(){  pulse_sampling();       average_ton = ((duration_ton*10)/number_of_samples)/10;  average_toff = ((duration_toff*10)/number_of_samples)/10;  frequency = 1/(float(average_ton+average_toff)/1000000.0);  duty_cycle = (float(average_ton)/float(average_ton+average_toff))*100.0;    voltage_sampling();    average_adc=((total_adc*10)/number_of_samples)/10;  voltage_out=float(average_adc)*single_step;  voltage=(float(average_adc)*single_step)*main_ratio;    what_mode = digitalRead(sw_mode);  delay(100);  if ( what_mode == 0 )   {    send_data();    display_the_data();  }  else  {      display_the_data();  }  }void pulse_sampling(){  duration_ton = 0;  sample_the_pulse= 0;  duration_toff=0;      for (int i=0;i<number_of_samples;i++)  {    sample_the_pulse = pulseIn(inpulse, HIGH);    duration_ton = sample_the_pulse+duration_ton;    sample_the_pulse = pulseIn(inpulse, LOW);    duration_toff = sample_the_pulse+duration_toff;   }} void voltage_sampling(){  sample_the_adc=0;  total_adc=0;      for (int i=0;i<number_of_samples;i++)  {    sample_the_adc=analogRead(voltpin);    total_adc=sample_the_adc+total_adc;  }}void display_the_data(){  lcd.setCursor(5,0);  lcd.print(voltage, 3);   lcd.setCursor(2,1);  lcd.print(frequency, 3);  lcd.setCursor(13,1);  lcd.print(duty_cycle, 0);} void send_data(){  Serial.print(" S ");    Serial.print(average_ton, DEC);  Serial.print(' ');  Serial.print(average_toff, DEC);  Serial.print(' ');  Serial.print(average_adc, DEC);  Serial.print(" E ");  }  `

#### Magician

#20
##### Mar 07, 2012, 03:57 pm
Quote
@Magician

Quote
Corrected: just noticed a drawings, there is only one diode, off-set about  230 x 0.7 / 3 x 1.414 = 38 V

Yes, sure.  You are using two diodes to rectify AC voltage coming from transformer. Because a diode is not conducting current till voltage reach 0.7 V (it's like a barrier) arduino would read "0" till voltage of the secondary winding of transformer reach 0.7 V.
Now, let calculate what is the AC voltage at the primary winding  when secondary 0.7 V. All you have to do is multiply by transformer ratio: 230 / 3,
and divide by sqrt(2) to correct difference RMS and amplitude value.
http://en.wikipedia.org/wiki/Root_mean_square
Off-set tells you, that arduino would read "0" till voltage reach 38 V in the outlet, and after that readings would be lower by 38V than "real" voltage so you will have to adjust your results accordingly.

#### RBR

#21
##### Mar 07, 2012, 05:34 pm
thnx for the reply . I will reply soon after correcting my code

Go Up

Please enter a valid email to subscribe