My task is to find the amount of current a light bulb uses, with that motive I used ACS712 current sensor of 30A connected all the connections properly as shown in the circuit diagram below
I tried all different codes available to calculate current...
Arduino Code :
void setup(){
Serial.begin(9600);
}
void loop(){
int rVal = 0;
int sampleDuration = 100; // 100ms
int sampleCount = 0;
unsigned long rSquaredSum = 0;
int rZero = 511; // For illustrative purposes only - should be measured to calibrate sensor.
uint32_t startTime = millis(); // take samples for 100ms
while((millis()-startTime) < sampleDuration)
{
rVal = analogRead(A0) - rZero;
rSquaredSum += rVal * rVal;
sampleCount++;
}
double voltRMS = 5.0 * sqrt(rSquaredSum / sampleCount) / 1024.0;
// x 1000 to convert volts to millivolts
// divide by the number of millivolts per amp to determine amps measured
// the 20A module 100 mv/A (so in this case ampsRMS = 10 * voltRMS
double ampsRMS = voltRMS * 10.0;
Serial.println(ampsRMS);
Serial.println(analogRead(A0));
}
Output
The output remains the same, even when the bulb is still lighting up.
Thank You in advance :)
rSquaredSum / sampleCount
andvoltRMS