Skip to content

How to Make a Smart Inertial Sensor for Home Assistant Under $5

Smart Inertial Sensor for Home Assistant

I made a smart gyroscope and accelerometer a.k.a inertial sensor that works with Home Assistant for less than 5 dollars and I will show you how I did it, so you can make your own.

BMI160 will be used for the Smart Inertial Sensor for Home Assistant Under $5

I will also list the needed parts, I’ll show how I connected them, as well as the used configuration that can be re-used by anyone and I will make some demo Home Assistant Automations utilizing my new and shiny Smart gyroscope & accelerometer sensor.

Getting Started: Parts You’ll Need for Smart Inertial Sensor

To make this gyroscope and accelerometer a.k.a inertial sensor for Home Assistant, you’ll need:

  • BMI160 inertial measurement unit (IMU) – approximately $1
  • D1 mini board – under $3
  • Four jumper wires
  • Micro USB cable

And hey, if you purchase these parts through the provided links below, it helps support the YT channel and this site at no extra cost to you – win-win!

I don’t want to read anymore…

Tired of reading? No problem, check my video instead…

Step 1: Wiring the Components

Now let’s get down to business. Here’s how I connected the BMI160 sensor to the D1 mini board:

  • Connect VIN pin on the BMI160 to the 3v3 pin of the D1 Mini.
  • Connect the Ground pin on the BMI160 to the Ground pin on the D1 Mini.
  • Next, connect the SCL pin on the BMI160 to the D1 pin on the D1 Mini.
  • Finally, connect the SDA pin on the BMI160 to the D2 pin on the D1 Mini.
Wiring of the BMI160 and D1 Mini so that the smart gyroscope + accelerometer sensor for home assistant to be made
Wiring of the BMI160 and D1 Mini so that the smart gyroscope + accelerometer sensor for Home Assistant to be made

Step 2: Setting Up Home Assistant

Assuming you have a running Home Assistant, preferably with ESPHome dashboard add-on installed, let’s proceed.

If not, don’t worry – you can join my free Home Assistant webinar to get started.

Step 3: Configuring ESPHome

Now, open the ESPHome dashboard add-on in Home Assistant and create a new device. Enter the device name, your Wi-Fi credentials, and select ‘ESP8266’ as device type, since we’re using a D1 Mini board.

How to Make a Smart Inertial Sensor for Home Assistant Under $5 1

Then, instead of installing immediately, let’s edit the configuration. I used this code and you can re-use it:

My ESPHome code – https://gist.github.com/peyanski/bc86337f558a9f88ee4d035fd9b950be

In the above configuration, I added lines to describe the wiring of the sensor (the I2C section) and I included a web server for accessing sensor readings from any browser. Web server part is optional and you can comment it out if you don’t needed it.

The final thing in the code and a must have one is the sensor section, which is just like the one found in the ESPHome website documentation. And the most important thing here that may need some change is the address.

The default address is 0x68, but for my BMI160 sensor this address didn’t worked and I had to change it to 0x69.

Use either 0x69 or 0x68 as address
Use either 0x69 or 0x68 as address

So, if your sensor is not showing any values after ESPHome uploading try to change the address here. If you bought the BMI160 sensor from my links in the video description then start with 0x69 address first and only if it doesn’t work, then change the address to the default one which is 0x68 and upload the ESPHome again. 

Step 4: Uploading ESPHome

Connect the D1 Mini board with the attached BMI160 sensor to a USB port on your Home Assistant device.

connect the sensor to a usb port of the device where Home Assistant and ESPHome are running

Hit install, select the appropriate port, and let the installation process run. After a few minutes, you should see the sensor readings updating live on your screen and in the web interface of our Gyro + Accel Smart Sensor.

The web interface of the smart inertial sensor for Home Assistant
The web interface of the smart inertial sensor for Home Assistant

It is a promising sign of success, don’t you think?

Step 5: Adding a Case (Optional)

For a polished finish, consider 3D printing a case for your DIY sensor.

I’ve used this 3D model – https://www.thingiverse.com/thing:3698982

But feel free to explore other options – https://www.thingiverse.com/search?q=d1+mini&page=1

Smart Home Glossary

I just want to quickly admit that Smart home technology can be overwhelming, with all the different terms and acronyms out there. That’s why I’ve created a Smart Home Glossary to help you better understand the Smart Home terminology.

My glossary is absolutely free, it is coming as one big PDF file and you can instantly download it from my website – https://automatelike.pro/glossary

Step 6: Integrating with Home Assistant

Now here comes the fun part – integrating our DIY sensor with Home Assistant! Just go to Integrations section of Home Assistant and you will find it auto discovered there. Then click on Configure button and pretty much that is it.

Gyro BMI160 smart sensor auto discovered by Home Assistant

Step 7: Demo Automation

Using Home Assistant automations, you can unleash the full potential of our DIY gyroscope and accelerometer sensor. Recognize movement, rotation and gestures, etc.

In my demo automation, I’ve set up 4 triggers, which are triggered when you rotate the sensor in left, right, up & down directions. For every trigger different action is executed based on sensor movements. For example, if I rotate the sensor to the right it will turn on a Smart Bulb. If I turn it left it will turn it off.

You can find the complete YAML code of the automation here – https://gist.github.com/peyanski/bd553dc7fe9070a55ed1884489fe368b

Step 8: Expansion

To make our smart Inertial sensor for Home Assistant even better, it is possible a battery shield for the D1 mini to be added along with a compatible lithium battery.

This will make our Inertial sensor for Home Assistant battery powered and completely wireless, but that is entirely nice to have option and it is a topic for another article.

If you want to see such thing, let me know by type it in the comments and maybe I will make part two where I will add a battery to that sensor. 

Conclusion

Congratulations, you’ve successfully created your own smart inertial sensor for Home Assistant on a budget! If you enjoyed this project, don’t forget to drop a comment with #GyroOwned to share your success with the community.

For more DIY smart home projects like this, be sure to check out my smart DIY sensors category.

Thanks for reading, and I’ll catch you in the next one!

Leave a Reply

Your email address will not be published. Required fields are marked *