I would like to build a cube with a Pi Zero inside and have the Pie be able to detect and report which side of the cube is facing up ... conceptually similar to rolling a dice and knowing what number is facing up. Can anyone give me an idea of what sensors I would need to be able to detect which side is up? I've done some searching to try and come up with an approach to it, but am at the point where I don't even know the right verbiage to ask the right question. Any thoughts on how to accomplish this would be appreciated. Thanks!


1 Answer 1


You need to use 3 axes accelerometer to sense which side of your cube is facing up. Accelerometers sense the gravity g and the acceleration due to motion.

Eg. when you roll dice, one of the axis will face down towards earth, let us assume positive x-axis exactly facing downwards, so the sensor will sense g along its positive axis which will be +9.8m/s^2, now suppose number you assigned to the face which is facing down is #1 you know #6 face is facing up, if g is -9.8m/s^2, #6 face will be facing down and face with #1 will be facing up.

The sensors available in the market comes with various interfaces namely:

  • Digital interface:
    • I2C
    • SPI
    • PWM
  • Analog Interface:
    • ADC

I would suggest you go for either I2C or SPI interface. And also go through these two articles on accelerometer basics and buying guide:

Accelerometer Basics

Accelerometer, Gyro and IMU Buying Guide

For projects and tutorials regarding the same, you will find plenty on the internet.

  • @jsotola Edited the answer thanks for pointing it out
    – Ravi Mali
    Commented Nov 17, 2018 at 6:00
  • 1
    good answer .... upvote
    – jsotola
    Commented Nov 17, 2018 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.