Raspberry Pi Pico - ACS712 Current Sensor
In this guide, we will learn to set up and use the ACS712 30A current sensor with the Raspberry Pi Pico. How much current does your motor pull? Is your LED strip drawing more than the adapter can give? The ACS712 answers these questions with a simple analog voltage, and the built-in ADC of the Pico can read it with no extra chip. We will cover the following details:
- How to connect the ACS712 module to a Raspberry Pi Pico, with two resistors that keep the ADC pin safe.
- How to find the real zero point of the sensor when the Pico starts.
- How to program the Raspberry Pi Pico in MicroPython to show the DC current of a 12 volts load in the Thonny Shell.
- How to measure AC current as an RMS value.

Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of ACS712 Current Sensor

The ACS712 (made by Allegro) measures current with the Hall effect. Inside the chip, the load current runs through a thick copper path. This current makes a small magnetic field, and a Hall sensor next to the copper turns the field into a voltage. The load side and the Pico side are not wired together (the chip has 2.1 kV RMS isolation), and the copper path has only about 1.2 mΩ of resistance, so the sensor barely changes your circuit. It works for both DC and AC.
The chip comes in three versions. They look the same, so read the text on the chip: this guide uses the 30A one (ACS712ELCTR-30A-T).
| ACS712 5A | ACS712 20A | ACS712 30A | |
|---|---|---|---|
| Current Range | -5 to +5 A | -20 to +20 A | -30 to +30 A |
| Sensitivity | 185 mV per amp | 100 mV per amp | 66 mV per amp |
| ACS712 30A (this guide) | |
|---|---|
| Supply Voltage | 5 volts (4.5 to 5.5 volts) - not 3.3 volts |
| Output at 0 A | about half of the supply, near 2.5 volts |
| Output at +30 A | about 4.48 volts |
| Output at -30 A | about 0.52 volts |
| Bandwidth | 80 kHz |
| Total Output Error | about ±1.5% at 25°C |
| Isolation | 2.1 kV RMS |
The output is ratiometric. This means the zero point and the 66 mV per amp both follow the real 5 volts supply. On the Pico, the sensor gets its 5 volts from the USB port, and USB is often a bit lower, like 4.9 volts. That is why the code measures the zero point by itself instead of trusting 2.5 volts.
The module has a 3-pin header for the Pico and a 2-pin screw terminal for the load:
- VCC pin: connect to 5 volts. On the Pico, use the VBUS pin.
- GND pin: connect to GND (0 volts).
- OUT pin: the analog output. It goes to an ADC pin of the Pico through a voltage divider (see the wiring part).
- IP+ and IP- screw terminals (some boards print no label): put them in series with the load. Cut one wire of the load and place the terminal in the gap. When current flows from IP+ to IP-, the reading is positive. Swap the two wires and the sign turns negative.
A small LED on the board turns on when the module gets power.
A note about small currents: the 30A version is not made for tiny loads. On the Pico, one ADC step is about 0.8 mV at the pin, which is about 1.2 mV at the sensor output after the divider, or about 18 mA. The noise of the sensor is bigger than that, so a reading that jumps between about -0.08 and +0.08 A with nothing connected is normal. This sensor is a good fit for loads from about 0.5 A up: motors, lamps, LED strips, heaters and chargers. For small loads, the 5A version gives finer steps.
How the Voltage Becomes Current
At 0 A, the output sits at the zero point. Every amp moves it by 66 mV, up for one direction and down for the other. So the formula is:
- Current (A) = (output voltage - zero voltage) / 0.066
For example, if the zero point is 2.472 volts and the output reads 2.538 volts, the current is (2.538 - 2.472) / 0.066 = 1.00 A.
Wiring Diagram
The ADC pins of the Raspberry Pi Pico accept 0 to 3.3 volts only, but the ACS712 is powered from 5 volts and its OUT pin can go up to about 4.5 volts. So we do not connect OUT straight to the Pico. Two resistors make a voltage divider that scales the signal to 2/3 of its value: 4.5 volts becomes 3.0 volts, which is safe. The code multiplies the reading by 1.5 to get the real sensor voltage back.

This image is created using Fritzing. Click to enlarge image
| ACS712 Module | Raspberry Pi Pico |
|---|---|
| VCC | VBUS (pin 40, 5 volts from USB) |
| GND | GND (pin 38) |
| OUT | 10 kΩ resistor to GP26 / ADC0 (pin 31) |
| (divider bottom) | 20 kΩ resistor from GP26 to GND (pin 33) |
The load side:
- 12 volts adapter + (through the DC power jack) to the IP+ screw terminal.
- IP- screw terminal to the + wire of the 12 volts DC device (such as a DC motor, LED strip or lamp).
- The - wire of the DC device goes back to the adapter -.
A few points to keep in mind:
- VBUS gives 5 volts only while the Pico is powered from the USB cable. If you power the Pico in another way, give the sensor its own 5 volts.
- Never put the 20 kΩ and 10 kΩ resistors the wrong way round. With 10 kΩ on top and 20 kΩ to GND, the pin sees 2/3 of OUT. Swapped, it would see only 1/3, and the code would read the wrong values.
- The 12 volts circuit does not need to share GND with the Pico. The sensor keeps the two sides apart.
※ NOTE THAT:
Mains AC (110 or 220 volts) can kill. If you are a beginner, practice only with a low voltage DC load like the 12 volts DC device in this guide. The screw terminal and the copper side of the module carry the full load voltage. Never touch them, or any load wire, while a mains circuit is live.
Raspberry Pi Pico Code - ACS712 DC Current
There is no library to install. The code only uses machine.ADC:
- At the start, it reads the sensor 1000 times while the load is off and saves the average as the zero point.
- In the loop, it averages 300 readings, turns the result into the sensor voltage (×3.3/65535, then ×1.5 for the divider), and uses the formula above to get the current.
- It prints the sensor voltage and the current every half second.
Detailed Instructions
Please follow these instructions step by step:
- Ensure that Thonny IDE is installed on your computer.
- Ensure that MicroPython firmware is installed on your Raspberry Pi Pico.
- If this is your first time using a Raspberry Pi Pico, refer to the Raspberry Pi Pico - Getting Started tutorial for detailed instructions.
- Wire the components as shown in the wiring diagram and table. Keep the 12 volts adapter unplugged (or the load switched off) for now.
- Connect the Raspberry Pi Pico to your computer using a Micro USB cable.
- Launch the Thonny IDE on your computer.
- Open Tools Options. On the Interpreter tab, select MicroPython (Raspberry Pi Pico) and the correct port.
- Copy the above code and paste it to the Thonny IDE's editor.
- Save the script to your Raspberry Pi Pico by:
- Click the Save button, or use Ctrl+S keys.
- In the save dialog, select Raspberry Pi Pico.
- Save the file as main.py
- Click the green Run button (or press F5). The load must still be off, because the first second is used to find the zero point.
- After the "Zero point" line shows up, plug in the 12 volts adapter so the DC device turns on.
- Check out the message in the Shell at the bottom of Thonny.
Here, the DC device is a 12 volts DC motor. The first lines show only noise, because no current flows yet. When the motor starts, it pulls a short peak (1.77 A here), then settles near 0.9 to 1.0 A. If you hold the motor shaft with your fingers for a moment, the current goes up. Unplug the adapter and the value falls back near 0 A.
If the current shows a minus sign while the DC device runs, the load wires are in the screw terminal the other way round. Swap them, or just read the number without the sign. If the zero point is far from 2.5 volts (for example, below 2.2 volts), check the divider resistors and make sure VCC is on VBUS, not on 3V3(OUT).
If you name your script main.py and save it to the root directory of the Raspberry Pi Pico, it will automatically run each time the Pico is powered on or reset. Remember to keep the load off at that moment, so the zero point is right.
Measuring AC Current
With AC, the current changes direction many times every second (50 or 60 times, depending on your country). The sensor output swings above and below the zero point, so the average is about 0 A. A single reading or a plain average tells us nothing. Instead, we use the RMS value, which is the number a clamp meter shows:
- Sample the output again and again for 200 ms. This covers 10 full cycles at 50 Hz, or 12 at 60 Hz.
- For every sample, take the distance from the zero point and square it.
- RMS current = square root of (average of the squares) / 0.066
The wiring stays the same. The screw terminal goes in series with one wire of the AC load.
※ NOTE THAT:
Again: mains voltage is dangerous. Only do this if you know how to work with mains safely, use a closed box, and never touch the screw terminal or wires while the power is on. The 30A module is rated for this, but your wires and connections must be too.
Raspberry Pi Pico Code - ACS712 AC Current
Detailed Instructions
- Keep the same Pico wiring, and keep the AC load switched off.
- Paste this code into Thonny, save it to the Pico as main.py, and click Run.
- Wait for the "Zero point" line, then switch the load on. Look at the Shell:
Here, a 100 W lamp at 230 volts was switched on and off. It should draw about 100 / 230 = 0.43 A, and the Pico shows 0.43 to 0.44 A. Note that the RMS value is never exactly 0 A with the load off: the noise also gets squared, so about 0.05 to 0.1 A is the floor of the 30A sensor. That is one more reason to use it for bigger loads.