Advertisement
Ruddog

Current sensor

Nov 3rd, 2018
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.96 KB | None | 0 0
  1. // EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
  2.  
  3. #include "EmonLib.h"             // Include Emon Library
  4.  
  5.  
  6.  
  7. #define VOLT_CAL 148.7
  8. #define CURRENT_CAL 62.6
  9.  
  10. EnergyMonitor emon1;             // Create an instance
  11.  
  12. void setup()
  13. {  
  14.   Serial.begin(9600);
  15.  
  16.   emon1.voltage(1, VOLT_CAL, 1.7);  // Voltage: input pin, calibration, phase_shift
  17.   emon1.current(0, CURRENT_CAL);       // Current: input pin, calibration.
  18. }
  19.  
  20. void loop()
  21. {
  22.   emon1.calcVI(20,2000);         // Calculate all. No.of half wavelengths (crossings), time-out
  23.  
  24.   float currentDraw            = emon1.Irms;             //extract Irms into Variable
  25.   float supplyVoltage   = emon1.Vrms;                    //extract Vrms into Variable
  26.  
  27.   Serial.print("Voltage: ");
  28.   Serial.println(supplyVoltage);
  29.  
  30.   Serial.print("Current: ");
  31.   Serial.println(currentDraw);
  32.  
  33.   Serial.print("Watts: ");
  34.   Serial.println(currentDraw * supplyVoltage);
  35.   Serial.println("\n\n");
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement