Hardware
ACS712 stroommeter module op basis van de ACS712ELC-20A chip. Met deze sensor kun je zowel wissel- als gelijkstroom meten tot maximaal 20A. Geschikt voor het meten van 230V netspanning.
De sensormodule kan 20A positief en negatief meten. De output is 100mV per gemeten Ampere.
ACS712 chip:
Pinout
Pin: | Functie: |
---|---|
+5v | +5V |
OUT | DATA |
GND | GND |
Aansluiten op de Arduino
Sluit de stroommeter module aan volgens onderstaand overzicht:
Arduino Pin: | ACS712 Pin: |
---|---|
+5v | +5V |
A0 | DATA |
GND | GND |
Script #1
Sluit de stroommeter module aan zoals hierboven aangegeven.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
void setup() { Serial.begin(9600); //Start Serial Monitor to display current read value on Serial monitor } void loop() { unsigned int x=0; float AcsValue=0.0,Samples=0.0,AvgAcs=0.0,AcsValueF=0.0; for (int x = 0; x < 150; x++){ //Get 150 samples AcsValue = analogRead(A0); //Read current sensor values Samples = Samples + AcsValue; //Add samples together delay (3); // let ADC settle before next sample 3ms } AvgAcs=Samples/150;//Taking Average of Samples //((AvgAcs * (5.0 / 1024.0)) is converitng the read voltage in 0-5 volts //2.5 is offset(I assumed that arduino is working on 5v so the viout at no current comes //out to be 2.5 which is out offset. If your arduino is working on different voltage than //you must change the offset according to the input voltage) //0.100v(100mV) is rise in output voltage when 1A current flows at input AcsValueF = ((AvgAcs * (5.0 / 1024.0)) - 2.5 )/0.100; Serial.println(AcsValueF);//Print the read current on Serial monitor delay(50); } |
Resultaat seriële monitor:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
-0.00 0.00 -0.00 0.35 1.07 2.33 1.85 1.29 -0.00 0.00 1.84 3.64 7.81 0.00 |
Script #2
Dit script maakt geen gemiddelde waarden en komt wat zenuwachtiger over…
Sluit de stroommeter module aan zoals hierboven aangegeven.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
int sensorValue; long current; void setup() { // Start de seriele poort. Serial.begin(9600); } void loop() { // Lees de waarde van de analoge ingang. sensorValue = analogRead( 0 ); // Print de analoge waarde naar de console. Serial.print(sensorValue, DEC); Serial.print( " = " ); // Pas het maximale bereik aan. if( sensorValue < 103 ) sensorValue = 102; else if( sensorValue > 921 ) sensorValue = 922; sensorValue -= 102; // Calculeer de stroom. current = ( ( sensorValue * 49951 ) >> 10 ) - 20000; // Print de waarde naar de console. Serial.print( (int)current, DEC ); Serial.println( " mA" ); // Wacht 100 milliseconden delay(100); } |
Het resultaat
Bronnen:
microcontroller-project.com