Interface ADXL335 Sensor on Raspberry Pi 4B in 4 Steps

Introduction: Interface ADXL335 Sensor on Raspberry Pi 4B in 4 Steps

In this Instructable we are going to interface an ADXL335 (accelerometer) sensor on Raspberry Pi 4 with Shunya O/S


  1. Raspberry Pi 4B (any variant)
  2. Raspberry Pi 4B compliant power supply
  3. 8GB or bigger micro SD card
  4. Monitor
  5. micro-HDMI Cable
  6. Mouse
  7. Keyboard
  8. laptop or another computer to program the memory card
  9. ADXL3355 Accelerometer sensor - Buy
  10. PCF8591 ADC module - Buy
  11. Breadboard
  12. Connecting wires

Step 1: Install Shunya OS on Raspberry Pi 4

You will need a laptop or computer with a micro SD card reader/adapter to load the micro SD card with Shunya OS.

  1. Download Shunya OS from the official releas e site
  2. Shunya OS guys have a decent tutorial on Flashing Shunya OS on Raspberry Pi 4.
  3. Insert micro SD card into Raspberry Pi 4.
  4. Connect mouse & keyboard to Raspberry Pi 4.
  5. Connect Monitor to Raspberry Pi 4 via micro-HDMI
  6. Connect the power cable and Power ON the Raspberry Pi 4.

The Raspberry Pi 4 should boot up with Shunya OS.

Step 2: Install Shunya Interfaces

Shunya Interfaces is a GPIO library for all boards supported by Shunya OS.

To install Shunya Interfaces we need to connect it to the wifi with internet access.

1. Connect to the wifi using the command

$ nmtui

2. Installing the Shunya Interfaces is easy, just run the command

$ sudo apt install shunya-interfaces

Step 3: Sensor Connections

ADXL335 is an analog sensor, but Raspberry Pi 4 is a digital device. Hence we need a converter PCF8591 (ADC) which converts all the analog values given by ADXL335 to digital values understandable by the Raspberry Pi 4.

The circuit diagram is given in the image above.

  1. Connect SDA & SCL pins on PCF8591 to pin 3 & pin 5 on the Raspberry Pi 4.
  2. Connect VCC & GND on PCF8591 to pin 4 (5V) & pin 6 (GND) on Raspberry Pi 4.
  3. Connect VCC & GND on ADXL335 to VCC & GND on PCF8591.
  4. Connect Ain1 on PCF8591 to X on ADXL335.
  5. Connect Ain2 on PCF8591 to Y on ADXL335.
  6. Connect Ain3 on PCF8591 to Z on ADXL335.

Step 4: Example Code

  • Download the code given below.
  • Compile it using the command
$ gcc -o adxl335 adxl335.c -lshunyaInterfaces
  • Run it using the command
$ sudo ./adxl335

Be the First to Share


    • Game Design: Student Design Challenge

      Game Design: Student Design Challenge
    • For the Home Contest

      For the Home Contest
    • Make It Bridge

      Make It Bridge



    Question 2 years ago

    hello there, im a beginner user of raspberry pi 4 model B. please show me how to install shunya interfaces in the raspberry pi as i am having trouble when to open the image file. thankyou in advance


    3 years ago

    Thanks for sharing your RasPi Tips!