ASC712 current sensors

Hello. I want to use ASC712 current sensors, but unfortunately I can’t figure out what a line of code should look like. If someone already has experience using this sensor, I will be very grateful for your help.

I am building a game steering wheel from a gyro scooter motor, the driver is assembled and tested (3pwm). But unfortunately, there are no instructions in the examples for connecting the current sensor. I want to use ASC712

1 Like

Hi @nikolaewich1988,

How are you planning to use the current sensors? You have the bare IC and are going to add it to the stripboard in the picture?

Current sensing can be done in different ways - what voltage are you running your system at, what currents are you expecting?

The ACS712 as a hall effect current sensor is quite easy to use. I would recommend inline sensing (without knowing more about your target voltage/current and looking at your setup picture…)
Inline sensing is easier to manage on the software side, and the hall effect sensors make it easy circuit-wise. Just put the current sensors directly on the path of the motor phases, between the half-bridge (FETs) and the motor wires. In this way all current passing to and from the motor will always pass through the sensors, and there will be no dependency on the FET switching times to sense the current.

It looks like a BluePill as MCU? If so, then you need to constrain the analog voltage to be in the 0-3.3V range… but the ACS712 has 5V supply and outputs its reading centred around VCC / 2, or 2.5V. So 0A == 2.5V, values <2.5V represent negative current (flowing opposite direction), values above 2.5V represent positive current.
Depending on the range you need to sense, you’ll have to transform the 0-5V output from the ACS712 to the 0-3.3V needed by the STM32 MCU… the simplest way to do this is with a simple voltage divider (2 resistors).

This part of the circuit will be analog, so you should take some care, but in the end it is very very hard to make a good analog circuit on a motor controller board, especially when using strip board :slight_smile:. So I think wiring it up neatly, and making sure all components have a nice stable power supply (VCC) will be a good start. Make sure to include the filter and bypass capacitors as recommended by the ACS712 datasheet.

An oscilloscope will be very handy to check the output signal.

Is this description understandable? Please feel free to ask more questions if I was unclear!

1 Like

Thanks for your reply.
I am using an arduino nano. I have the acs712 modules ready but I ordered the 30 amp version by mistake. I did not quite understand how I can specify the desired restriction in the firmware code.
Let’s say I want to limit the current per phase to 4 amps, what would the example code look like?

Nano is 5V, so that’s ok, but it might be a bit slow for FOC + current sensing. You’ll have to try.

For the code, see the example:

When you construct the current sensing, change the pins to the ones you are using. I think the following values would work for the 66mV/A version:

InlineCurrentSense current_sense = InlineCurrentSense(1.0f, 1.0f/0.066f, A0, A1, A2);


  motor.current_limit = 4.0f; // 4A limit
1 Like

Thank you very much, I will definitely test it.