Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. int sensitive = 185; // สำหรับ 5A
  2. // int sensitive = 100; // สำหรับ 20A
  3. // int sensitive = 66; // สำหรับ 30A
  4.  
  5. int offset = 2525; // ค่าเริ่มต้น 2500 ปรับค่าตรงนี้เพื่อให้ค่ายังไม่มีโหลดเป็น 0.00
  6.  
  7. void setup() {
  8. Serial.begin(9600);
  9. }
  10.  
  11. void loop() {
  12. double c = getCA();
  13. Serial.println(c);
  14. delay(1000);
  15. }
  16.  
  17. // หาค่ากระแสเฉลี่ย
  18. double getCA() {
  19. int count = 200;
  20. double sum = 0;
  21. for (int i = 0; i < count; i++) {
  22. sum += getC();
  23. }
  24. double val = sum / count;
  25. return val;
  26. }
  27. // อ่านค่ากระแส
  28. double getC() {
  29. int a = analogRead(A0);
  30. double v = (a / 1024.0) * 5000;
  31. double c = (v - offset) / sensitive;
  32. return c;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement