Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Interfacing ADXL335 Accelerometer with Raspberry Pi Pico
Raspberry Pi Raspberry Pi Pico Projects

Interfacing ADXL335 Accelerometer with Raspberry Pi Pico

Mamtaz AlamBy Mamtaz AlamUpdated:August 3, 20231 Comment5 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
ADXL335 Raspberry Pi Pico
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Overview

In this guide, we will interface the ADXL335 3-axis Accelerometer with Raspberry Pi Pico using the MicroPython Code. The Raspberry Pi Pico is an affordable, versatile, and powerful microcontroller, while the ADXL335 is a compact and low-power accelerometer. When combined, these two components can be used to create a wide variety of exciting projects, such as gesture control systems, tilt sensors, or even simple game controllers.

Throughout this guide, we will provide you with step-by-step instructions on connecting the Raspberry Pi Pico and the ADXL335 accelerometer. We will also walk you through writing the necessary code to read and interpret the accelerometer data. By the end of this tutorial, you will have a solid understanding of the Raspberry Pi Pico and the ADXL335 accelerometer, as well as the knowledge required to create your own projects using these components.

Earlier, we built some projects using ADXL335, you may check them before proceeding:

  • Earthquake Detector Project
  • Gesture Controlled Robot
  • Measurement of Accelerometer
  • Tilt Angle & Distance Meter

Components Required

We need the following components for this guide.

S.N.ComponentsQuantityPurchase Link
1Raspberry Pi Pico1Amazon | AliExpress
2ADXL335 3-Axis Accelerometer1Amazon | AliExpress
3Breadboard1Amazon | AliExpress
4Connecting Wires1Amazon | AliExpress



ADXL335 3-Axis Accelerometer

The ADXL335 is a small, thin, low-power triple-axis accelerometer produced by Analog Devices. It is designed to measure acceleration with a full-scale range of ±3 g, where g is the acceleration due to gravity (approximately 9.81 m/s²). The ADXL335 measures acceleration in three orthogonal axes: X, Y, and Z, allowing it to detect movement and orientation in three-dimensional space.

ADXL335 3 Axis Accelerometer

The ADXL335 outputs analog voltage signals proportional to the acceleration experienced by the sensor. These analog signals can be read by a microcontroller or other device with an analog-to-digital converter (ADC), such as an Arduino or Raspberry Pi Pico, to process and interpret the data.


Specifications of ADXL335

The ADXL335 is a triple-axis accelerometer with the following key specifications:

  • Measurement Range: ±3 g (where g is the acceleration due to gravity, approximately 9.81 m/s²)
  • Sensitivity: Typically around 300 mV/g (millivolts per g) at room temperature, with slight variations depending on the axis.
  • Output: Analog voltage proportional to acceleration, one output for each axis (X, Y, and Z).
  • Power Supply Voltage: 1.8 V to 3.6 V, with a typical operating voltage of 3.3 V.
  • Power Consumption: Low power, typically around 350 µA in measurement mode.
  • Bandwidth: User-selectable, up to 1.6 kHz for the X and Y axes and up to 550 Hz for the Z axis.
  • Noise Density: Approximately 350 µg/√Hz (micro-g per square root hertz).
  • Zero-g Offset: 1.5 V (typical) at the output when there is no acceleration.
  • Zero-g Offset Drift: Up to 25 µV/°C (microvolts per degree Celsius) over the operating temperature range.
  • Operating Temperature Range: -40°C to +85°C (-40°F to +185°F).

Pinout of ADXL335

The ADXL335 3-axis Accelerometer 5 pins.

ADXL335 Pinout

  1. VCC: Power supply pin (2.8V to 3.6V)
  2. X_OUT: X-axis analog output.
  3. Y_OUT: Y-axis analog output.
  4. Z_OUT: Z-axis analog output.
  5. GND: Ground pin



Interfacing ADXL335 Accelerometer with Raspberry Pi Pico

To interface the ADXL335 accelerometer with a Raspberry Pi Pico using MicroPython, you’ll need to connect the ADXL335 to the Pico’s analog pins and read the acceleration values from the sensor. Here is the connection between Raspberry Pi Pico & ADXL335 Accelerometer.

ADXL335 Accelerometer Raspberry Pi Pico

  • Connect the ADXL335 VCC to the Pico’s 3.3V pin.
  • Connect the ADXL335 GND to the Pico’s GND pin.
  • Connect the ADXL335 X-OUT to the Pico’s GP26 pin (ADC0).
  • Connect the ADXL335 Y-OUT to the Pico’s GP27 pin (ADC1).
  • Connect the ADXL335 Z-OUT to the Pico’s GP28 pin (ADC2).

MicroPython Code to use ADXL335 Accelerometer with Raspberry Pi Pico

You can use a breadboard and jumper wires for connection.


MicroPython Code to Read Acceleration Values

Here’s a sample MicroPython code to read the Acceleration Values in the x, y, and z-axis by interfacing the ADXL335 & Raspberry by Pico.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import machine
import utime
 
# ADXL335 analog pins connected to Pico's ADC channels
X_PIN = 26
Y_PIN = 27
Z_PIN = 28
 
# Create ADC objects for each axis
adc_x = machine.ADC(machine.Pin(X_PIN))
adc_y = machine.ADC(machine.Pin(Y_PIN))
adc_z = machine.ADC(machine.Pin(Z_PIN))
 
def read_acceleration(adc):
    # Read the ADC value and convert it to voltage
    voltage = adc.read_u16() * 3.3 / 65535
    # Convert the voltage to acceleration (assuming 3.3V supply)
    acceleration = (voltage - 1.65) / 0.330
    return acceleration
 
while True:
    # Read the acceleration values from the ADXL335
    x = read_acceleration(adc_x)
    y = read_acceleration(adc_y)
    z = read_acceleration(adc_z)
    
    # Print the acceleration values
    print("X: {:.2f}g, Y: {:.2f}g, Z: {:.2f}g".format(x, y, z))
    
    # Wait for a while before reading again
    utime.sleep(0.1)

Upload this code to your Raspberry Pi Pico, and the acceleration values will be printed on the screen.

Note that the actual sensitivity of the ADXL335 might be different from the theoretical value used in the code (0.330 V/g), so you may need to calibrate the sensor to get accurate results.



MicroPython Code to Read Rotational Angle Values

To calculate the tilt angles (pitch and roll) from the acceleration values, you can use the following equations:

  • pitch = atan(y / sqrt(x^2 + z^2))
  • roll = atan(x / sqrt(y^2 + z^2))

Here’s the updated MicroPython code for ADXL335 and Raspberry Pi Pico to read the X, Y, Z acceleration values and calculate the pitch and roll angles:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import machine
import utime
import math
 
# ADXL335 analog pins connected to Pico's ADC channels
X_PIN = 26
Y_PIN = 27
Z_PIN = 28
 
# Create ADC objects for each axis
adc_x = machine.ADC(machine.Pin(X_PIN))
adc_y = machine.ADC(machine.Pin(Y_PIN))
adc_z = machine.ADC(machine.Pin(Z_PIN))
 
def read_acceleration(adc):
    # Read the ADC value and convert it to voltage
    voltage = adc.read_u16() * 3.3 / 65535
    # Convert the voltage to acceleration (assuming 3.3V supply)
    acceleration = (voltage - 1.65) / 0.330
    return acceleration
 
def calculate_tilt_angles(x, y, z):
    pitch = math.atan2(y, math.sqrt(x**2 + z**2))
    roll = math.atan2(x, math.sqrt(y**2 + z**2))
    
    # Convert the angles to degrees
    pitch = math.degrees(pitch)
    roll = math.degrees(roll)
    
    return pitch, roll
 
while True:
    # Read the acceleration values from the ADXL335
    x = read_acceleration(adc_x)
    y = read_acceleration(adc_y)
    z = read_acceleration(adc_z)
    
    # Calculate the tilt angles
    pitch, roll = calculate_tilt_angles(x, y, z)
    
    # Print the acceleration values and tilt angles
    print("X: {:.2f}g, Y: {:.2f}g, Z: {:.2f}g, Pitch: {:.2f}°, Roll: {:.2f}°".format(x, y, z, pitch, roll))
    
    # Wait for a while before reading again
    utime.sleep(0.1)

Upload this code to your Raspberry Pi Pico, and the acceleration values along with the pitch and roll angles will be printed on the screen.

Note that the ADXL335 is a 3-axis accelerometer, which means it can measure acceleration along the X, Y, and Z axes. While it can provide valuable data for many applications, it is not designed to directly measure yaw values.

Yaw is a rotational motion around the Z-axis, which is usually associated with changes in heading or orientation. To measure yaw values, you would typically use a gyroscope or a combination of sensors known as an Inertial Measurement Unit (IMU).

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleWhat is Blockchain Technology & How it Works
Next Article ESP32 UWB Pro – Ultra Wideband Module with Amplifier

Related Posts

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

ADXL375 Accelerometer with Raspberry Pi Pico & MicroPython

Updated:July 24, 2025
Interface BMI160 with Raspberry Pi Pico & MicroPython

Interface BMI160 with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Shift Register 74HC595 with Raspberry Pi Pico & MicroPython

Updated:February 2, 202513K
Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Interfacing XBee Module with Raspberry Pi Pico & MicroPython

Updated:February 2, 20253K
Modbus RTU with Raspberry Pi Pico & Micropython

Modbus RTU with Raspberry Pi Pico & MicroPython

Updated:February 2, 20258K
Fever Detector with MLX90640 & OpenCV Raspberry Pi

Thermal Fever Detector with MLX90640 & OpenCV Raspberry Pi

Updated:February 2, 20256K
View 1 Comment

1 Comment

  1. DiY Projecst Lab on May 1, 2023 7:57 AM

    Thanks buddy 🙂

    Reply

CommentsCancel reply

Latest Posts
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

May 31, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

DIY Colorimeter using AS7265x Spectroscopy Sensor & ESP32

February 1, 2026
Top Posts & Pages
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • IoT Based Drinking Water Quality Monitoring with ESP32
    IoT Based Drinking Water Quality Monitoring with ESP32
  • LD2410 Sensor with ESP32 - Human Presence Detection
    LD2410 Sensor with ESP32 - Human Presence Detection
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • DIY IoT Water pH Meter using pH Sensor & ESP32
    DIY IoT Water pH Meter using pH Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (204)
    • ESP32 MicroPython (7)
    • ESP32 Projects (81)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.