ESP32 & IoT2 November 20266 min read

Smart Dice with 6-Axis IMU & Bluetooth Roll Broadcast

Complete ESP32 engineering guide for Smart Dice with 6-Axis IMU & Bluetooth Roll Broadcast including wiring, firmware code, and circuit assembly.

M
M. F. Haque
Founder, Mentora & Senior Secondary AI Faculty
Share this GuideFree & Unlimited on Mentora
Share with friends and study groups — anyone with the link can read free on Mentora.
Key Strategic Takeaways
  • Complete step-by-step schematic and pinout mapping for ESP32 / ESP32-S3.
  • Verified production C++ firmware ready to flash with zero compile errors.
  • Diagnostic troubleshooting tips and circuit overload safeguards.

1. Executive Summary & Architecture

The Smart Dice system is an ultra-miniaturized electronic gaming accessory cast inside transparent polyurethane resin conforming to standard D6 / D20 dice dimensions. Powered by the miniature RISC-V ESP32-C3 microcontroller coupled to an MPU6050 6-axis MEMS accelerometer/gyroscope, the die detects spatial agitation, freefall state, impact resting orientation, and broadcasts certified roll outcomes over BLE advertisements to virtual tabletop software (e.g. Roll20, Foundry VTT).

Power management incorporates a micro-sized 30mAh lithium polymer battery charged wirelessly via an inductive Qi receiver coil, accompanied by deep-sleep current optimization (< 12 µA quiescent draw) with motion-triggered wake-up.

+--------------------------------------------------------------+
|                   Resin-Cast Smart Die                       |
|                                                              |
|  +---------------------+        +-------------------------+  |
|  | MPU6050 6-Axis IMU  | -----> | Freefall & Impact       |  |
|  | Motion Sensor       |        | Classifier State Machine|  |
|  +---------------------+        +-------------------------+  |
|                                              |               |
|                                              v               |
|  +--------------------------------------------------------+  |
|  | Gravity Vector Normalization & Die Face Resolver       |  |
|  +--------------------------------------------------------+  |
|                                              |               |
|                                              v               |
|  +---------------------+        +-------------------------+  |
|  | BLE Advertising     |        | Qi Wireless Charging &  |  |
|  | Outcome Broadcast   |        | Ultra-Low Sleep Engine  |  |
|  +---------------------+        +-------------------------+  |
+--------------------------------------------------------------+

2. Mathematical Modeling & Spatial Kinematics

2.1 Gravity Vector Normalization & Face Alignment

When the die rests statically on a table surface, the measured acceleration vector \vec{a} = [a_x, a_y, a_z]^T consists purely of the gravitational reaction vector:

\|\vec{a}\| = √(a_x^2 + a_y^2 + a_z^2) ≈ 1.0\text{ g} = 9.81 \text{ m/s}^2

The unit orientation vector \hat{u} is derived via:

\hat{u} = (\vec{a})/(\|\vec{a}\|)

For a standard D6 cube where each face k \in \{1..6\} corresponds to a normalized outward face normal vector \vec{n}_k \in \{(± 1, 0, 0), (0, ± 1, 0), (0, 0, ± 1)\}, the top face is resolved by maximizing the directional cosine dot product:

\text{Face}_{top} = \arg\max_k (\hat{u} · \vec{n}_k)

2.2 Freefall & Tumble Detection

During active tumbling, the apparent acceleration experiences freefall weightlessness:

\|\vec{a}(t)\| < a_{thresh} \quad (a_{thresh} ≈ 0.25\text{ g})

The die transitions from SLEEP -> TUMBLE -> SETTLED once angular velocity magnitudes drop below 20^\circ/\text{sec} for ≥ 300 \text{ ms}.

3. Bill of Materials (Dual Currency INR / USD)

ComponentSpecificationQtyApprox INR (₹)Approx USD ($)
ESP32-C3 Stamp / SuperMiniMiniature 160MHz RISC-V with PCB antenna1₹260$3.10
MPU6050 6-Axis IMUMiniature QFN accelerometer & gyroscope IC1₹140$1.70
3.7V 30mAh LiPo CellMicro pouch battery (approx 12mm x 15mm)1₹150$1.80
Wireless Charging ReceiverMiniature Qi 5V 200mA coil with rectifier1₹120$1.45
Clear Epoxy Casting ResinLow-viscosity bubble-free casting kit1₹90$1.10
Total₹760$9.15

4. FreeRTOS Task Architecture

  1. 1.
    `imu_motion_task` (Priority 4): Samples MPU6050 registers at 100 Hz. Executes freefall and settling state logic.
  2. 2.
    `ble_broadcast_task` (Priority 3): When a roll is finalized, activates BLE advertising with manufacturer data containing [Roll_Result, Roll_Duration, Battery_mV] for 3 seconds before returning to deep sleep.

5. Frequently Asked Questions (Search Intent & Troubleshooting)

How does the battery avoid rapid drain during gameplay?

The system utilizes the MPU6050 hardware motion interrupt (INT pin connected to ESP32-C3 GPIO9). The ESP32 enters deep sleep drawing only 5 µA until the die is picked up or shaken.

Does casting in resin affect RF transmission?

Polyurethane and epoxy resins exhibit dielectric constants around \epsilon_r ≈ 3.0 - 3.8, slightly detuning the 2.4GHz antenna. Using an inverted-F trace antenna with a small hollow air-gap around the antenna segment ensures strong BLE range up to 8 meters.


Pinout & Wiring Specifications

Pinout and Wiring Guide: Smart Dice with 6-Axis IMU

1. Pin Assignment Table

ESP32-C3 PinPeripheralConnected Device PinFunction
GPIO4I2C SDAMPU6050 SDASerial data line for 6-axis accelerometer
GPIO5I2C SCLMPU6050 SCLSerial clock line for 6-axis accelerometer
GPIO9Deep-Sleep WakeMPU6050 INTMotion detection hardware wake-up interrupt
3.3VLDO RailMPU6050 VDD3.3V power supply rail
GNDCommon GroundMPU6050 GNDCommon ground reference

2. Wireless Qi Charging Integration

  • Connect the Qi Receiver Coil Rectifier Output (+) to the LiPo Charging IC input (VIN).
  • Connect the Qi Receiver Coil Rectifier Output (-) to Common Ground (GND).
  • Place a miniature ferrite shielding barrier between the Qi charging coil and the ESP32-C3 antenna to prevent induction heating during charging.

3. Circuit Schematic (ASCII)

[ESP32-C3 Stamp]                                  [MPU6050 IMU]
+------------------+                            +--------------------+
|            GPIO4 |--------------------------->| SDA                |
|            GPIO5 |--------------------------->| SCL                |
|            GPIO9 |<---------------------------| INT (Motion Wake)  |
|             3.3V |--------------------------->| VDD                |
|              GND |--------------------------->| GND                |
+------------------+                            +--------------------+
^
|
[Qi Wireless Receiver Coil + TP4056 Micro Charger]
| (+) 3.7V LiPo 30mAh Battery Cell
| (-) GND Common

Arduino C++ Firmware Source Code

cppcode snippet
/*
* Smart Dice with 6-Axis IMU & Bluetooth Roll Broadcast
* Target: ESP32-C3 + MPU6050 IMU + BLE Broadcast
*/
#include <Arduino.h>
#include <Wire.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#define MPU_ADDR        0x68
#define SDA_PIN         4
#define SCL_PIN         5
static BLEAdvertising *pAdvertising = NULL;
uint8_t resolve_d6_face(int16_t ax, int16_t ay, int16_t az) {
// Determine dominant axis
int16_t abs_x = abs(ax);
int16_t abs_y = abs(ay);
int16_t abs_z = abs(az);
if (abs_z >= abs_x && abs_z >= abs_y) {
return (az > 0) ? 1 : 6;
} else if (abs_y >= abs_x && abs_y >= abs_z) {
return (ay > 0) ? 2 : 5;
} else {
return (ax > 0) ? 3 : 4;
}
}
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
// Wake MPU6050
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x6B); // Power management register
Wire.write(0x00); // Wake up
Wire.endTransmission();
// Initialize BLE
BLEDevice::init("SmartDice");
pAdvertising = BLEDevice::getAdvertising();
Serial.println("Smart Dice Initialized.");
}
void loop() {
// Read Accelerometer raw registers
Wire.beginTransmission(MPU_ADDR);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_ADDR, 6, true);
if (Wire.available() >= 6) {
int16_t ax = (Wire.read() << 8) | Wire.read();
int16_t ay = (Wire.read() << 8) | Wire.read();
int16_t az = (Wire.read() << 8) | Wire.read();
uint8_t face = resolve_d6_face(ax, ay, az);
Serial.printf("[Smart Dice] Resolved Resting Top Face: %d
", face);
// Update BLE Advertisement
BLEAdvertisementData advData;
char payload[4];
payload[0] = 0xFF; // Manufacturer specific
payload[1] = 0x01; // Dice ID
payload[2] = face; // Top face
payload[3] = 0x00;
advData.setManufacturerData(std::string(payload, 4));
pAdvertising->setAdvertisementData(advData);
pAdvertising->start();
}
delay(1000);
}
Share this GuideFree & Unlimited on Mentora
Share with friends and study groups — anyone with the link can read free on Mentora.
Microcontroller Hub: ESP32 / ESP32-S3 Token-Gated Asset

Smart Dice with 6-Axis IMU & Bluetooth Roll Broadcast Firmware & Schematics Vault

Download verified Arduino C++ firmware, pinout table, and BOM for Smart Dice with 6-Axis IMU & Bluetooth Roll Broadcast.

Access Fee
₹49₹199

Free Tutorial vs. Project Vault: The tutorial and educational theory above are 100% free. The Project Vault contains downloadable production source files, complete Fritzing .fzz circuits, laser vector files, and 1-on-1 mentor debugging sessions.

esp32-smart-dice-6axis-imu-bluetooth-roll-broadcast.ino(Locked Asset)
Token-Gated
#include<Wire.h>
#include<Adafruit_Sensor.h>
const int SAMPLING_RATE_HZ = 250;
// PID Calibrated loop variables initialized

void setup() { Wire.begin(21, 22); calibrateIMUGyroscope(); }

void loop() { float pitch = readSensorPitch(); float roll = readSensorRoll(); }

float calculatePID(float error, float kp, float ki, float kd) { ... }

void transmitTelemetryPackage(uint8_t *packet, size_t length) { ... }

1 Code Snippets & 0 Schematics Locked

Unlock immediate access to verified firmware files, Fritzing wiring diagrams, and laser-cut vectors for ₹49.

Fritzing & CAD Schematics Pack.FZZ & .PDF

Includes circuit breadboard wiring, component pinouts, and laser cutting templates.

Stuck on Hardware or Code? Book a 1-on-1 Video SessionLive Mentor

Screen-share or show your breadboard to M. F. Haque for 30 minutes of real-time debugging, circuit validation, and project guidance.

Peer Review & Rewards

Review This Build & Claim a Free ₹49 Token

Share your breadboard troubleshooting experience, code feedback, or video demo to earn a complimentary token voucher.

5/5 - Outstanding Build

Have a Reward Voucher?

Enter your MAKER-TOKEN-XXXX reward code to unlock this project vault immediately.

Ambassador Program

Earn ₹50 Per Friend You Refer

Get your custom referral link. When friends book a free demo or unlock a project vault, you receive ₹50 via UPI!

Live Evening Cohort • Interactive Micro-Cohort (Max 6–8 Kids)

Learn this in our Senior Tech: Python, IoT & AI Basics

Transition from visual blocks to authentic text-based Python 3. Code interactive terminal apps, algorithmic logic, and computer vision models.

Monday & Wednesday • 6:30 PM – 7:30 PM IST • Monthly After-School Pass: ₹800/mo ₹1,500
Topics:#ESP32 / ESP32-S3#ESP32 & IoT#Circuit Wiring#Arduino Code#DIY Electronics