Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int VQ; //2.5 volts na saída quando corrente for 0A
- int ACSPin = A2;
- void setup()
- {
- Serial.begin(9600);
- VQ = determineVQ(ACSPin);
- delay(1000);
- }
- void loop()
- {
- Serial.print("ACS712@A2:");Serial.print(readCurrent(ACSPin),3);Serial.println(" mA");
- delay(150);
- }
- int determineVQ(int PIN)
- {
- Serial.print("estimating avg. quiscent voltage:");
- long VQ = 0;
- //read 5000 samples to stabilise value
- for (int i=0; i<10000; i++)
- {
- VQ += abs(analogRead(PIN));
- delay(1);
- }
- VQ /= 10000;
- Serial.print(map(VQ, 0, 1023, 0, 5000));Serial.println(" mV");
- return int(VQ);
- }
- float readCurrent(int PIN)
- {
- int current = 0;
- int sensitivity = 66;//sensibilidade para o sensor de 30 A
- for (int i=0; i<50; i++)
- {
- current += abs(analogRead(PIN)) - VQ;
- delay(1);
- }
- current = map(current/50, 0, 1023, 0, 5000);
- return float(current)/sensitivity;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement