High current measuring with hall effect will not work with PWM


I'm trying to measure current using a hall effect current sensor (0-50 amps). I also want to vary the power supplied to the load using PWM through some MOSFETS. My power source is a 12V car battery, my load is a common headlight

I have a circuit built and it works fine, I can read the current, and when I adjust the power by changing the duty cycle the power is reduced--and I can watch the headlight become dimmer, but the hall effect current sensor no longer works. I can only assume the sensor can NOT handle current that is modulated. I have tried frequency at 31250 and 490 Hz (note the latter produces an expected hum in the headlights.

According to this data sheet, this sensor has a high fequency bandwidth. Anyone know how I can use this sensor on a PWM design?


Thanks in advance.

I may be on to something here...

Perhaps the Arduino Analog input cant' read a PWM signal without some code.

Anyone know?

I suppose you have to measure during the time the PWM signal is “high” (lights on).
That value, and the PWM duty cycle, will give you average current.

Or sample continiously/fast, and calculate the average from that.

Maybe <200hz PWM is better. Low voltage lights are “slow”.

Yeah... I assume you need to average the readings. What kind of readings do you get at 100%, 50%, and zero?

Do the readings jump-around with 50% PWM as you would expect?

Or, maybe you don't need to measure current with PWM? You already know the PWM setting.... You may not know the actual current because the filament resistance goes down at lower temperatures, but does that matter?

I created a basic low pass filter 10k resistor in series and a 1000 MFD cap between input and ground. I still get a reading that bounces around. If i measure the sensor output, my DMM can read it just fine (not sure if it's accurate though.

I'm not sure how to read the voltage when at the pulse is high. Eventually my PWM current will be suppying a DC motor (with all kinds of nasty other issues).

I'll keep digging, but the end is no where in sight.


Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom… :slight_smile:

Here is my code (I removed all the LCD stuff, the SD card writing stuff, etc. This is stripped down to make it easier to diagnose

I should post a YouTube Video…

OOPS in my image i listed R1 twice the lower series R1 is actually R2 (and is 10K)


  Pin connections
  Arduino   device
  A0        current meter (hall effect device) (pin 1 on amp meter)
  A1        input from pot
  9     PWM output to the MOSFET, duty controlled by vadjust on A1


#define PWMMOSFET  9
#define PWMADJ  A1
#define hallvolts A0

float amvolts = 0;
float amamps = 0;
int setduty = 0;

void setup() {


  pinMode(PWMADJ, INPUT);

  // set PWM to 30K to avoid humming
  TCCR1B = TCCR1B & B11111000 | B00000001;

void loop() {

  // step 1 get the desired duty cycle (analog voltage 0 to 5)
  setduty = analogRead(PWMADJ);
  // since voltage is 0-1023 we need to scale down to 0-255
  setduty = setduty / 4;

  // step 2 write the duty cycle
  analogWrite(PWMMOSFET, setduty);

  // step 3  find the hall effect amps
  amvolts = analogRead(hallvolts);
  //connvert to actual volts
  amvolts = (amvolts / 204.6);
  // note, although i'm using a low pass filter, i'm NOT currently accounting for the duty cyle
  // in the voltage calculations
  // use equation to convert volts to amps (simple linear curve supplied by hall effect mfg.
  amamps = (amvolts - 2.5) * (50.0 / 1.50);

  // the issue is even with the low pass filter, the aamps is all over the map (-17.3, 22.1, 6.5, -0.1, 3.2)
  // some times it lock up my Arduino, some times it dumps crazy characters to my LCD (code removed)

  // print the results
  // give a delay



Place you 10k that the manufacture wants as in my attachment.
Move it back so its connected directly to the sensor output.

Your DMM will be reading the average of the PWM current.

Try 10uF and 1K…

Tom… :slight_smile:


Thank you for taking the time to look at this. Im at work but I'll look at it as soon as I get home.


Hi, Try these sites about filtering PWM to get an average reading.



Tom.... :)