Advertisement
RuiViana

Medidor de Corrente ACS712

Nov 15th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. int VQ; //2.5 volts na saída quando corrente for 0A
  2. int ACSPin = A2;
  3. void setup()
  4. {
  5. Serial.begin(9600);
  6. VQ = determineVQ(ACSPin);
  7. delay(1000);
  8. }
  9. void loop()
  10. {
  11. Serial.print("ACS712@A2:");Serial.print(readCurrent(ACSPin),3);Serial.println(" mA");
  12. delay(150);
  13. }
  14.  
  15. int determineVQ(int PIN)
  16. {
  17. Serial.print("estimating avg. quiscent voltage:");
  18. long VQ = 0;
  19. //read 5000 samples to stabilise value
  20. for (int i=0; i<10000; i++)
  21. {
  22. VQ += abs(analogRead(PIN));
  23. delay(1);
  24. }
  25.  
  26. VQ /= 10000;
  27. Serial.print(map(VQ, 0, 1023, 0, 5000));Serial.println(" mV");
  28. return int(VQ);
  29. }
  30.  
  31. float readCurrent(int PIN)
  32. {
  33. int current = 0;
  34. int sensitivity = 66;//sensibilidade para o sensor de 30 A
  35. for (int i=0; i<50; i++)
  36. {
  37. current += abs(analogRead(PIN)) - VQ;
  38. delay(1);
  39. }
  40. current = map(current/50, 0, 1023, 0, 5000);
  41. return float(current)/sensitivity;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement