Changing expression for 30 A Current sensor

This is the code

#include <LiquidCrystal.h>
#define CURRENT_SENSOR A0  // Define Analog input pin that sensor is attached
float Current;      // Float current

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
void loop()
    int Volts;

    int sensor_max;
    sensor_max = getMaxValue();
void pins_init()
/*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;

I am using 30 A current sensor and what values do I need to change for this expression

what values do I need to change for this expression

The ones that are not relevant for your sensor. Why did you put those values in the code?

If you didn't write the code, why are you using code some other clue-less twit wrote?

I did my project following this link :

you dont have to be rude you know :S :o

you dont have to be rude you know

You don't have to be thin-skinned, you know!

One obvious thing is that the calculation


will be evaluated using integer arithmetic and only converted to float after the calculation. Looking at it I suspect it will always result as zero. I don't know where you got the magic formula from or whether it valid for your device but change the constants to be floats (e.g. 1000.0) rather than integers.

You may also need to force the order of evaluation by surrounding terms with braces.

Why not use the values from that project you said you based yours on?

 float average = 0;
  for(int i = 0; i < 1000; i++) {
    average = average + (.0264 * analogRead(A0) -13.51) / 1000;

//5A mode, if 20A or 30A mode, need to modify this formula to
    //(.19 * analogRead(A0) -25) for 20A mode and
    //(.044 * analogRead(A0) -3.78) for 30A mode


Hi, What current sensor are you using? Can you post a link to its spec/data sheet please?

Thanks . Tom... :)

ACS712 (30A)

i need to measure realtime AC on sensor ACS712 (30A).

220V is Voltage , and I get like 7 Ampers current , but I need to get 5 Ampers.

The message I just got in the Sensors forum here was that this sensor is not save to use at 2xxV mains. Looking at the datasheet, I am not sure (Base Isolation Voltage finish, Reinforced Isolation Voltage too low, don't know whats important?). If taking into account some safety margins and voltage spikes, definitely not fine. The creepage distance is also at least questionable.

How do you expect to measure AC current by taking 1 sample every second? Line voltage is a 50/60 Hz sine wave, you will be sampling one point on the wave at fairly arbitrary times. That will look like garbage.