SHARE
TWEET

115 Volt AC current sensing sketch

Ruddog Nov 28th, 2018 (edited) 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // R Trujillo
  2. // 11/28/2018
  3. // Monitoring current draw on a 115VAC line.
  4.  
  5. #include "EmonLib.h"                    // Include Emon Library
  6. EnergyMonitor emon1;                    // Create an instance
  7.  
  8. void setup()
  9. {
  10.   Serial.begin(115200);
  11.   delay(2000);
  12.   emon1.current(A0, 111.1);// Current: input pin, cal
  13. }
  14. double Irms = emon1.calcIrms(1480);  // Calculate Irms only
  15. //int ON = 0;
  16. int washer=0;
  17. void loop()
  18. {
  19. delay(2000);
  20. Irms = emon1.calcIrms(1480);  // Calculate Irms only
  21. // This first if statement allows the current to
  22. // settle as there is some garbage displayed
  23. // in the com port serial monitor port.
  24. if (Irms > 3)
  25. {
  26. Serial.println("Current settling");
  27. }
  28. // This statement is executed only if the  conditions
  29. // are met. With washer = 0 it will be bypassed even
  30. // if the current conditions are met.
  31. if (Irms > 2.4 && Irms <=2.5 && washer==1)
  32. {
  33. Serial.println("Contents Washer ON");
  34. washer = 0;
  35. Serial.println(washer);
  36. Serial.println(Irms);
  37.  
  38. }
  39. // Conditions zero current and washer equaling zer0
  40. // is the condition that must be met to carry out
  41. // the push statement(which has not been written
  42. // yet and help is needed to get this working
  43. // I would like the IFTTT code to live in the if statement
  44. // below and call the IFTTT.
  45. if (Irms < 0.5 && washer==0)
  46.  
  47.   {
  48.     Serial.println("Contents Washer OFF");
  49.     washer = 1;
  50.     Serial.println(washer);
  51.     Serial.println(Irms);
  52.   }
  53. delay(1000);
  54. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top