How to Build a ClawdBot Tamagotchi with ESP32

A lobster-bot companion with moods, needs, and personality loops

ESP32RoboticsBeginner45 minutes6 components

Updated

How to Build a ClawdBot Tamagotchi with ESP32
For illustrative purposes only
On this page

What you'll build

This project guides you through creating ClawdBot, a Tamagotchi-inspired lobster companion that lives on an ESP32 with an OLED screen, three tactile buttons, and a piezo buzzer. ClawdBot has three core needs -- hunger, entertainment, and energy -- that decay over time. Press the Feed button to top up hunger with a satisfying crunch sound, the Play button to boost entertainment with a cheerful jingle, or the Sleep button to let ClawdBot recharge with a snoring animation and soft pulsing tone. Neglect any need for too long and ClawdBot's expressive OLED face shifts from happy to grumpy to downright furious, complete with claw-snapping animations and an annoyed buzz.

What makes this project a great learning experience is the care loop at its core. You will implement a time-based state machine that ticks down each need independently, transitions between mood states using threshold checks, and triggers different face animations and sound effects depending on ClawdBot's overall wellbeing score. This teaches you event-driven programming, debounced button handling, non-blocking timers with millis(), and how to manage multiple concurrent state variables -- all fundamental patterns that apply to every embedded system you will build in the future.

The finished ClawdBot is a charming desk companion that demands just enough attention to stay engaging without becoming annoying. The code is structured so you can easily add new needs like social interaction via Bluetooth proximity, introduce personality traits that make each ClawdBot unique, or add a growth system where consistent care unlocks new animations and sounds. If you enjoyed this build, the Cosmic Critter Pico project makes an excellent follow-up that explores motion-based interaction on a different platform.

Wiring diagram

Wiring diagram

Interactive wiring diagram

Components needed

ComponentTypeQtyBuy
SSD1306 OLED Facedisplay1€4.30
Feed Buttonother1€8.30
Play Buttonother1€8.30
Sleep Buttonother1€8.30
Piezo Buzzeractuator1€4.75
Status LEDactuator1

Prices and availability are indicative and may have been updated by the supplier. Schematik may earn a commission from purchases made through affiliate links.

Assembly

1

Create the face and controls

Wire OLED on I2C and connect Feed/Play/Sleep buttons to GPIO32/33/25.

2

Add emotion feedback outputs

Connect buzzer on GPIO26 and status LED on GPIO27 for mood responses.

Pin assignments

PinConnectionType
GPIO 21clawdbot-oled-1 SDAI2C
GPIO 22clawdbot-oled-1 SCLI2C
GPIO 32feed-button-1 SIGDIGITAL
GPIO 33play-button-1 SIGDIGITAL
GPIO 25sleep-button-1 SIGDIGITAL
GPIO 26clawdbot-buzzer-1 SIGPWM
GPIO 27clawdbot-led-1 SIGDATA

Code

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

#define SDA_PIN 21
#define SCL_PIN 22
#define BTN_FEED 32
#define BTN_PLAY 33
#define BTN_SLEEP 25
#define BUZZER_PIN 26
#define STATUS_LED 27

Adafruit_SSD1306 display(128, 64, &Wire, -1);
enum Mood { HAPPY, HUNGRY, SLEEPY, BORED, CRANKY };
Mood mood = HAPPY;
unsigned long lastCareMs = 0;

void setup() {
  Wire.begin(SDA_PIN, SCL_PIN);
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  pinMode(BTN_FEED, INPUT_PULLUP);
  pinMode(BTN_PLAY, INPUT_PULLUP);
  pinMode(BTN_SLEEP, INPUT_PULLUP);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(STATUS_LED, OUTPUT);
  lastCareMs = millis();
}

void loop() {
  unsigned long idleMs = millis() - lastCareMs;
  if (idleMs > 90000) mood = CRANKY;
  else if (idleMs > 60000) mood = BORED;
  else if (idleMs > 30000) mood = HUNGRY;

  if (!digitalRead(BTN_FEED)) { mood = HAPPY; lastCareMs = millis(); tone(BUZZER_PIN, 1760, 70); }
  if (!digitalRead(BTN_PLAY)) { mood = HAPPY; lastCareMs = millis(); tone(BUZZER_PIN, 1480, 70); }
  if (!digitalRead(BTN_SLEEP)) { mood = SLEEPY; lastCareMs = millis(); tone(BUZZER_PIN, 980, 90); }

  display.clearDisplay();
  display.setCursor(0, 0);
  display.println("ClawdBot Tamagochi");
  display.println("------------------");
  display.print("Mood: ");
  display.println(mood == HAPPY ? "Happy" : mood == HUNGRY ? "Hungry" : mood == SLEEPY ? "Sleepy" : mood == BORED ? "Bored" : "Cranky");
  display.println("Feed/Play/Sleep");
  display.display();

  digitalWrite(STATUS_LED, mood == CRANKY ? (millis() / 180) % 2 : HIGH);
  delay(35);
}

// Run this and build other cool things at schematik.io
Libraries: Adafruit SSD1306, Adafruit GFX Library