2

I am trying to get the status of appliance using current sensor. My Circuit looks like below image. I don't want to measure current. I just want to know whether appliance is on or off.

enter image description here

I am getting following readings when power turned on and off, I don't see any difference, I am not able to figure out whether the bulb is on or off.

enter image description here

Please help me to know the status of appliance/bulb.

PS. Please find my code below:

/*
Measuring AC Current Using ACS712
www.circuits4you.com
*/
const int sensorIn = A0;
int mVperAmp = 185; // Use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

void setup(){ 
 Serial.begin(9600);
}

void loop(){

 Voltage = getVPP();
 VRMS = (Voltage/2.0) *0.707;  //root 2 is 0.707
 AmpsRMS = (VRMS * 1000)/mVperAmp;
 Serial.print(AmpsRMS);
 Serial.println(" Amps RMS");
}

float getVPP()
{
  float result;
  int readValue;             // value read from the sensor
  int maxValue = 0;          // store max value here
  int minValue = 1024;       // store min value here

   uint32_t start_time = millis();
   while((millis()-start_time) < 1000)  // sample for 1 Sec
   {
       readValue = analogRead(sensorIn);
       // see if you have a new maxValue
       if (readValue > maxValue) 
       {
            /*record the maximum sensor value*/
           maxValue = readValue;
       }
       if (readValue < minValue) 
       {
           /*record the minimum sensor value*/
           minValue = readValue;
       }
   }

   // Subtract min from max
   result = ((maxValue - minValue) * 5.0)/1024.0;

   return result;
 }
  • Show your code. – Enric Blanco Mar 31 '17 at 17:33
  • Hi @EnricBlanco thanks for prompt response,Please find the code above. – Surendranath Reddy Mar 31 '17 at 18:24
  • Is your ACS712 module made to be used with the mains voltage ? Most are not. The ACS712 modules are sensitive for magnetic fields from transformers and wires. They are also noisy. If you, for example, have a 5A ACS712 module and want to measure 0.1A, the measurement could be lost in the noise. The sketch collects the minimum and maximum peak, therefor the sketch collects also the noise peaks. A current transformer does not need direct contact and is a lot safer. – Jot Mar 31 '17 at 18:36
  • another issue is that AC has no current at the zero-cross, so you need some sort of timing to get RMS – dandavis Mar 31 '17 at 18:53
1

The code looks like it would produce rather larger values than you are seeing, if it gets correct inputs from the sensor. For that reason, you probably should carefully check your wiring. Also, with a DVM, measure the sensor output voltage with the light on and with it off, to verify sensor operation. If you measure ok sensor voltages but don't get good readings, your analog input pin may have a problem; you could try other analog input pins.

Note, when debugging an issue like this, it does not make sense to run a few numbers through five levels of processing before printing anything out. You should at least add serial prints in getVPP(), and just before returning the result, print out result, maxValue, and minValue.

Note, fix the erroneous comment “//root 2 is 0.707”; the square root of 2 is about 1.414213562, while 1/√2 = (√2)/2 is about 0.707106781.

  • 230v/100W = 0,44A so it should be a clear difference between off current and on current. – MatsK Sep 28 '17 at 17:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.