AS5600 + ESP32: Pinout, Wiring Diagram and Working Code
Share
AS5600 + ESP32: Pinout, Wiring Diagram and Working Code
Quick answer: wire VCC to 3V3, GND to GND, SDA to GPIO21 and SCL to GPIO22, and tie DIR to GND so the angle increases clockwise. Leave OUT and GPO unconnected. The sensor answers on I2C address 0x36 and gives a 12-bit angle (0–4095 per turn) from a diametrically magnetised magnet held over the chip.
What is the AS5600 module pinout?
The pin labels are printed on the board and are legible in the listing photo: a 3-pin group VCC, OUT, GND and a 4-pin group DIR, SCL, SDA, GPO. Functions come from the AS5600 datasheet, where GPO appears as PGO (program option).
| Pin | Function | Source |
|---|---|---|
| VCC | Module supply; listing gives 3.0–5.5 V | Silkscreen + listing |
| OUT | Analog or PWM angle output | Silkscreen + datasheet |
| GND | Ground | Silkscreen + datasheet |
| DIR | Direction: GND = angle increases clockwise, VDD = counter-clockwise | Silkscreen + datasheet |
| SCL | I2C clock | Silkscreen + datasheet |
| SDA | I2C data | Silkscreen + datasheet |
| GPO (PGO) | Program option input; leave unconnected | Silkscreen + datasheet |
How do you wire the AS5600 to an ESP32?
| AS5600 pin | ESP32 DevKit pin | Why this pin |
|---|---|---|
| VCC | 3V3 | Keeps the board's I2C pull-ups at 3.3 V |
| GND | GND | Common ground |
| SDA | GPIO21 | Default I2C data pin |
| SCL | GPIO22 | Default I2C clock pin |
| DIR | GND | Fixes the direction; do not leave it floating |
| OUT, GPO | Not connected | Not needed when reading over I2C |
Which ESP32 pins should you avoid?
Every GPIO choice on this page follows the same rules for the 30-pin ESP32-WROOM-32 DevKit (the board Compoden stocks as the ESP32 30-pin CP2102 development board). Espressif's ESP32 GPIO reference is the source:
- Never use GPIO6–11. They connect to the module's SPI flash.
- Avoid the strapping pins GPIO0, 2, 5, 12 and 15 for sensors. Their level at reset decides boot mode and flash voltage, so a sensor holding one of them can stop the board booting. GPIO0 is not even on the 30-pin header; it only goes to the BOOT button.
- GPIO34, 35, 36 and 39 are input-only and have no internal pull-up or pull-down. They are ideal for analog inputs and useless for outputs or clocks.
- Use ADC1 (GPIO32–39) for analog readings. ADC2 pins (GPIO0, 2, 4, 12–15, 25–27) cannot be read while Wi-Fi is running.
- Leave GPIO1 and GPIO3 alone. They carry the USB serial link used for uploads and the Serial Monitor.
- ESP32 GPIOs are 3.3 V only. They are not 5 V tolerant.
What voltage does the AS5600 need with an ESP32?
The AS5600 chip has two supply modes: 4.5–5.5 V on its VDD5V pin, or 3.0–3.6 V with VDD5V and VDD3V3 tied together (AS5600 datasheet). The module exposes a single VCC pin, and the listing says it accepts 3.0–5.5 V and that its I2C pull-ups go to the supply voltage. That last point decides it: with an ESP32, power VCC from 3V3 so SDA and SCL are never pulled to 5 V.
Use a diametrically magnetised magnet centred over the chip, like the disc in the photo. The sketch reads the STATUS register, which reports whether a magnet is detected and whether it is too weak or too strong. Adjust the gap until it reports detected with neither warning.
Working Arduino code for the AS5600 on ESP32
No library is needed. The sketch talks to the registers listed in the AS5600 datasheet: STATUS (0x0B) for the magnet bits and RAW ANGLE (0x0C/0x0D) for the 12-bit angle, which it converts to degrees.
// AS5600 magnetic angle sensor + ESP32 DevKit (ESP32-WROOM-32)
// Wiring: VCC -> 3V3, GND -> GND, SDA -> GPIO21, SCL -> GPIO22, DIR -> GND; OUT and GPO unconnected
// From the AS5600 datasheet: I2C address 0x36, STATUS 0x0B, RAW ANGLE 0x0C/0x0D.
#include <Wire.h>
const int SDA_PIN = 21;
const int SCL_PIN = 22;
const uint8_t AS5600_ADDR = 0x36;
uint8_t readReg8(uint8_t reg) {
Wire.beginTransmission(AS5600_ADDR);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(AS5600_ADDR, (uint8_t)1);
return Wire.available() ? Wire.read() : 0;
}
uint16_t readReg12(uint8_t reg) {
Wire.beginTransmission(AS5600_ADDR);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(AS5600_ADDR, (uint8_t)2);
if (Wire.available() < 2) return 0;
uint16_t hi = Wire.read();
uint16_t lo = Wire.read();
return ((hi << 8) | lo) & 0x0FFF;
}
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
Wire.beginTransmission(AS5600_ADDR);
if (Wire.endTransmission() != 0) {
Serial.println("AS5600 not found at 0x36. Check VCC, GND, SDA and SCL.");
while (true) delay(1000);
}
}
void loop() {
uint8_t status = readReg8(0x0B);
bool md = status & 0x20; // magnet detected
bool ml = status & 0x10; // magnet too weak
bool mh = status & 0x08; // magnet too strong
uint16_t raw = readReg12(0x0C);
float deg = raw * 360.0f / 4096.0f;
Serial.printf("Angle: %6.2f deg raw=%4u magnet:%s%s%s\n", deg, raw,
md ? " detected" : " NOT detected", ml ? " too weak" : "", mh ? " too strong" : "");
delay(200);
}
Compile check: this exact sketch compiled for the esp32:esp32:esp32 board (ESP32 Dev Module, ESP32 Arduino core 3.3.10) on 5 October 2026. A clean compile proves the code and libraries agree. It does not prove your wiring, so test it on the bench with the Serial Monitor at 115200 baud.
Do not write to the BURN register (0xFF) while experimenting. Burn commands program the chip's one-time-programmable memory permanently.
Common mistakes with the AS5600 and ESP32
- DIR left floating. The direction becomes undefined; tie it to GND or VCC.
- VCC at 5 V on an ESP32. The board's pull-ups would then hold SDA and SCL at 5 V.
- Axially magnetised magnet. The field must run across the magnet's diameter.
- Magnet off-centre or too far away. Watch the status bits until it reports detected.
- Two AS5600s on one bus. The address 0x36 is fixed; use the ESP32's second I2C controller.
- Burning OTP registers by accident. Leave register 0xFF alone.
Where can you get the parts?
| Item | Role | Link |
|---|---|---|
| AS5600 magnetic encoder module | 12-bit contactless angle sensor | View AS5600 module |
| ESP32 30-pin CP2102 development board | Controller with Wi-Fi and Bluetooth | View ESP32 board |
Want this sensor in a bigger build? Describe the whole device in Soldr, for example “I want to build a smart volume knob with an ESP32 and an AS5600”. Soldr returns the exact parts, a wiring map and code that compiles, all from one parts list, so the pins in the code match the pins in the wiring. Compoden stocks the parts and delivers across India.
Sources
Supply modes, I2C address, registers, DIR behaviour and burn warnings: ams AS5600 datasheet (the product line now sits with Infineon). Pin labels: the board silkscreen in the Compoden listing photo. ESP32 pin rules: Espressif ESP32 GPIO reference.
Related ESP32 wiring guides
- Vibe coding hardware: build an ESP32 project from one sentence
- TCS34725 colour sensor + ESP32
- DHT22 temperature and humidity + ESP32
- XKC-Y25-V non-contact liquid level + ESP32
- INMP441 I2S microphone + ESP32
- 5 mm LDR light sensor + ESP32
- Capacitive soil moisture sensor v2.0 + ESP32
- HX711 and 5 kg load cell + ESP32
- Water level sensor + ESP32
- AHT21B temperature and humidity + ESP32
Frequently asked questions
Which ESP32 pins should I use for the AS5600?
SDA to GPIO21 and SCL to GPIO22, VCC to 3V3 and GND to GND. Tie DIR to GND and leave OUT and GPO unconnected.
What is the AS5600 I2C address?
0x36. It is fixed, so a second AS5600 needs the ESP32's second I2C bus.
Why does my AS5600 angle jump or not change?
Usually DIR is floating, the magnet is not diametrically magnetised, or it is off-centre or too far away. The STATUS register reports whether the magnet is detected, too weak or too strong.