← Back to Projects

ESP32 Radar & Tamagotchi Monitor

A hardware tribute to 30 years of Tamagotchi, featuring a real-time OLED radar, binary clock, and MQTT presence detection.

The Concept

To celebrate the 30th anniversary of the Tamagotchi, I built a custom desktop monitor using an ESP32 and an SSD1306 OLED display. Unlike a standard toy, this device acts as a smart home sensor node.

It features a "sonar" radar interface that visualizes physical distance data in real-time, while simultaneously broadcasting that data to my Home Assistant server via MQTT.

Demo Video

Watch the radar sweep and binary clock in action.

(Video placeholder: Add your video file tag here)

Gallery

(Gallery placeholder: Paste your <img> tags here)

Key Features

  • Ultrasonic Radar: HC-SR04 sensor visualizes objects on a semi-circular grid.
  • Binary Clock: (Integrated feature) Displays time in binary format for geeky aesthetics.
  • Temp Sensor: Environmental monitoring sent to the dashboard.
  • MQTT Integration: Publishes distance and presence state to office/distance.

Source Code (C++ / Arduino)

Below is the core logic for the Radar visualization and MQTT loop. Sensitive credentials have been redacted.

#include <WiFi.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

// ================= USER CONFIG =================
const char* ssid     = "YOUR_WIFI_SSID";      // <--- EDIT THIS
const char* password = "YOUR_WIFI_PASSWORD";  // <--- EDIT THIS
const char* mqtt_server = "192.168.1.XXX";    // <--- EDIT THIS

// Pins
#define TRIG_PIN 25
#define ECHO_PIN 26

// Radar Geometry
#define RADAR_RADIUS 46
#define RADAR_CENTER_X 64
#define RADAR_CENTER_Y 16 // Below yellow info area

// ... [Setup and loop logic for Radar drawing] ...

void drawRadar() {
  // Draw distance rings at 30, 60, 120cm
  int r30  = cmToRadius(30);
  int r60  = cmToRadius(60);
  
  // Sweep line calculation
  float rad = sweepAngle * PI / 180.0;
  int sx = RADAR_CENTER_X + cos(rad) * RADAR_RADIUS;
  int sy = RADAR_CENTER_Y + sin(rad) * RADAR_RADIUS;

  display.drawLine(RADAR_CENTER_X, RADAR_CENTER_Y, sx, sy, SSD1306_WHITE);
}

void loop() {
  // 1. Maintain Connection
  tryReconnectMQTT();
  client.loop();
  
  // 2. Read Sensor
  int cm = readDistanceCM();
  
  // 3. Update Display & Publish
  display.clearDisplay();
  drawInfoArea(); // Draws time and text
  drawRadar();    // Draws the cool visuals
  display.display();
}