Pages: 1 [2]   Go Down
Author Topic: AC voltage measuring using arduino  (Read 4504 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@retrolefty

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

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 362
Posts: 17307
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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
Can you please explain it?
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

value = analogRead( Vin );
Vac = ( float (value) * ( 5.0 / 1023.0 ) ) * ( 122.0 / 3.0 );
Serial.print( Vac, 3);

   

Any question ? 

Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Anyway.

Here my project code.

Code:
/*
   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 "); 


Logged

Montreal
Online Online
Faraday Member
**
Karma: 30
Posts: 2608
Per aspera ad astra.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Can you please explain it?
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 27
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thnx for the reply . I will reply soon after correcting my code
Logged

Pages: 1 [2]   Go Up
Jump to: