Home Creators Posts Import Register Favorites Logout

Content

Hello, and Happy 2021 to you all! 

This project was inspired by an advert that popped up in my Facebook feed for a product called "Smart Dice" - a set of dice that wirelessly connected to a mobile phone app, which reported the value of what you rolled. I don't actually know the exact details of how they worked, but I decided to recreate the functionality they were described as having, using the linear accelerometer sensor in an MPU6050 chip (on a GY-521 module), and a Wemos D1 Mini.

Having used the accelerometer to work out which face of the dice is pointing upwards, I then broadcast that information as an MQTT message sent over Wi-Fi to a Node-RED server, which updates a display to show the value rolled. I'm sure you can think of lots of possible uses for this!

I've also used this video to talk about a couple of topics that I haven't really mentioned much in previous projects: firstly, how to provide battery power to portable props. And, secondly, how you can write "Arduino" code (or ESP8266/ESP32) to write and read values to any I2C sensor, without using any third-party library. This is useful information to know should you ever find yourself wanting to use an I²C component in a project and these is not an existing library available!

Even though I'm using a Wemos D1 Mini, which is based on an ESP8266 chip, I've tried to structure the wiring and the code so that it will be portable to work on ESP32 or Arduino UNO/Nano (although the Arduinos don't have Wi-Fi built-in, so you'll either have to add a Wi-Fi shield, or replace that bit of code with something that creates an entirely self-contained response - i.e. popping open a side of the cube once it has been rotated in the correct sequence of turns)

Components

GY-521 board (MPU-6050 chip), https://www.banggood.com/custlink/v33hSP1shT

Wemos D1 Mini (ESP8266 chip), https://www.banggood.com/custlink/v33RJLItSj

D1 Mini Battery Shield, https://www.banggood.com/custlink/mvGhSFfsh2

Total cost = ~$7

Timings

00:00:00-00:03:23 Introduction and Demonstration

00:03:23-00:07:17 Hardware Overview

00:07:18-00:19:02 Wiring and power requirements

00:19:03-01:00:07 Arduino/ESP8266/ESP32 Code

01:00:08-01:15:36 Node-RED flow

01:15:37-01:17:27 Wrapup

I'll put up another post shortly with all the downloads for folks to access but, in the meanwhile, please ask if you have any questions or comments!

 

Files

DIY Wireless "Smart" Dice with ESP8266 and Node-RED

In this video tutorial, I'll explain how you can build your own "Smart Dice" - wireless cubes that use the MPU6050 linear accelerometer on a GY-521 board to detect which way up they are, and broadcast that information via an MQTT message to a Node-RED broker. You can use these to build an escape room puzzle where players need to arrange a set of dice to make a certain total of the face-up sides, or rotate them in a particular way to follow a numeric sequence, for example. I'm using a Wemos D1 Mini, ESP8266-based board which is ideal for portable escape room props, because: - it's physically small - it has a convenient battery shield to provide portable power from a single Li-Po cell - it has built in Wi-Fi - it runs at 3.3V logic, which means that there is no logic-level conversion required on the I2C wires between the processor and the (3.3V) sensor However, you can also follow exactly the same steps described here to connect the MPU-6050 sensor an ESP32 board, or an Arduino UNO or Nano (even though that won't have Wi-Fi unless you add a suitable Wi-Fi shield). To demonstrate how you can create code that is portable between several different target devices, I'm also not going to use any third-party libraries designed for the MPU-6050 chip - instead I'll teach you how you can write and read values directly to any I2C component using the built-in, generic "Wire" library. This is useful information to know should you ever find yourself wanting to use an I²C component in a project and these is not an existing library available! Components --- GY-521 board (MPU-6050 chip), https://www.banggood.com/custlink/v33hSP1shT Wemos D1 Mini (ESP8266 chip), https://www.banggood.com/custlink/v33RJLItSj D1 Mini Battery Shield, https://www.banggood.com/custlink/mvGhSFfsh2 Total cost = ~$7 Timings --- 00:00:00-00:03:23 Introduction and Demonstration 00:03:23-00:07:17 Hardware Overview 00:07:18-00:19:02 Wiring and power requirements 00:19:03-01:00:07 Arduino/ESP8266/ESP32 Code 01:00:08-01:15:36 Node-RED flow 01:15:37-01:17:28 Wrapup Code & Wiring Downloads --- If you'd like to support me making more video tutorials explaining how to use tech in escape rooms and other playful settings, please check out my Patreon at https://www.patreon.com/playfultech, where you can also find code downloads, wiring diagrams, and additional resources for this and all my other tech projects.

Comments

Euan Hair

You’re a mind reader! This is exactly the content I’ve been looking for. Thanks for another brilliant project!

Antonio Padilla

Great!!!!! A very good idea to implement this type of puzzle in an escape room. I'm coming up with a lot of ideas. Thanks a lot!!!!

Johannes Beersaft

Hi Alastair, this is like always a nice Puzzle-conzept! But i thinking about using a wireless charing option to charge the Batterie. So you dont have to open the Box unless its brokken. Can you make a Tutotrial about this? Do you use something for wirelesscharging in your last projects ? Greetings Johannes

Steve Baudains

I'm very keen to play with this, as I have a couple of new rooms in design at the moment and I'm super impressed with my first foray into ESP32 coming from an arduino background. Charging was my first "concern" when starting to watch the video, but I think I can probably make a box with some secretly exposed charging pads and a simple "base station" that the boxes get placed on overnight to recharge. I'll let you know how I get on.

Steve Baudains

Infact I may even embed some leds and program a simple "Simon" type app so the cube has to be turned over in a certain sequence....hmmmmm :)