Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. //Michael Klements
  2. //The DIY Life
  3. //27 October 2014
  4.  
  5. int currentPin = A7; //Assign CT input to pin 1
  6. double kilos = 0;
  7. int peakPower = 0;
  8.  
  9. void setup()
  10. {
  11. Serial.begin(9600); //Start serial communication
  12. Serial.println("Running");
  13. }
  14.  
  15. void loop()
  16. {
  17. int current = 0;
  18. int maxCurrent = 0;
  19. int minCurrent = 1000;
  20. for (int i=0 ; i<=200 ; i++) //Monitors and logs the current input for 200 cycles to determine max and min current
  21. {
  22. current = analogRead(currentPin); //Reads current input and records maximum and minimum current
  23. if(current >= maxCurrent)
  24. maxCurrent = current;
  25. else if(current <= minCurrent)
  26. minCurrent = current;
  27. }
  28. if (maxCurrent <= 517)
  29. {
  30. maxCurrent = 516;
  31. }
  32. double RMSCurrent = ((maxCurrent - 516)*0.707)/11.8337; //Calculates RMS current based on maximum value
  33. int RMSPower = 220*RMSCurrent; //Calculates RMS Power Assuming Voltage 220VAC, change to 110VAC accordingly
  34. if (RMSPower > peakPower)
  35. {
  36. peakPower = RMSPower;
  37. }
  38. kilos = kilos + (RMSPower * (2.05/60/60/1000)); //Calculate kilowatt hours used
  39. delay (2000);
  40. Serial.print(RMSCurrent);
  41. Serial.println("A");
  42. Serial.print(RMSPower);
  43. Serial.println("W");
  44. Serial.print(kilos);
  45. Serial.println("kWh");
  46. Serial.print(peakPower);
  47. Serial.println("W");
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement