@michael-rudek Lol, well that does make a difference!
Above mentioned sketch still gives me weird readings. However, i found another sketch and now i see readings that start to make some sense.
With nothing plugged in, I get:
sensor_max = 385 (rises to 386 sometimes)
The amplitude of the current is(in mA) -6201.2
The effective value of the current is(in mA) -4385.6
With power usage according to power consumption meter:
385 watt (1,687 A, voltage 228)
sensor_max = 422 (rises to 423 sometimes)
The amplitude of the current is(in mA) -4394.5
The effective value of the current is(in mA) -3107.9
Now i would have to find a way to calculate the difference between the sensor_maxes, telling me the power usage is 385 watt.
The sketch I’m currently using:
#define CURRENT_SENSOR A0 // Define Analog input pin that sensor is attached
float amplitude_current; // Float amplitude current
float effective_value; // Float effective current
void setup()
{
Serial.begin(9600);
pins_init();
}
void loop()
{
int sensor_max;
sensor_max = getMaxValue();
Serial.print("sensor_max = ");
Serial.println(sensor_max);
//the VCC on the Arduino interface of the sensor is 5v
amplitude_current=(float)(sensor_max-512)/1024*5/100*1000000; // for 5A mode(185),you need to modify this with 20 A (100) and 30A (66) mode;
effective_value=amplitude_current/1.414;
//for minimum current=1/1024*5/185*1000000/1.414=18.7(mA)
//Only sinusoidal alternating current
Serial.println("The amplitude of the current is(in mA)");
Serial.println(amplitude_current,1);
//Only one number after the decimal point
Serial.println("The effective value of the current is(in mA)");
Serial.println(effective_value,1);
}
void pins_init()
{
pinMode(CURRENT_SENSOR, INPUT);
}
/*Function: Sample for 1000ms and get the maximum value from the S pin*/
int getMaxValue()
{
int sensorValue; //value read from the sensor
int sensorMax = 0;
uint32_t start_time = millis();
while((millis()-start_time) < 1000) //sample for 1000ms
{
sensorValue = analogRead(CURRENT_SENSOR);
if (sensorValue > sensorMax)
{
/*record the maximum sensor value*/
sensorMax = sensorValue;
}
}
return sensorMax;
}