
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
Components needed
| Component | Type | Qty | Buy |
|---|---|---|---|
| SSD1306 OLED Face | display | 1 | €4.30 |
| Feed Button | other | 1 | €8.30 |
| Play Button | other | 1 | €8.30 |
| Sleep Button | other | 1 | €8.30 |
| Piezo Buzzer | actuator | 1 | €4.75 |
| Status LED | actuator | 1 |
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
Create the face and controls
Wire OLED on I2C and connect Feed/Play/Sleep buttons to GPIO32/33/25.
- Use pull-up wiring and debounce if adding hardware switches.
Add emotion feedback outputs
Connect buzzer on GPIO26 and status LED on GPIO27 for mood responses.
- Use short chirps for positive events and longer tones for cranky state.
Pin assignments
| Pin | Connection | Type |
|---|---|---|
| GPIO 21 | clawdbot-oled-1 SDA | I2C |
| GPIO 22 | clawdbot-oled-1 SCL | I2C |
| GPIO 32 | feed-button-1 SIG | DIGITAL |
| GPIO 33 | play-button-1 SIG | DIGITAL |
| GPIO 25 | sleep-button-1 SIG | DIGITAL |
| GPIO 26 | clawdbot-buzzer-1 SIG | PWM |
| GPIO 27 | clawdbot-led-1 SIG | DATA |
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.ioReady to build this?
Open this project in Schematik to get the full wiring diagram, pin assignments, and deployable code for the ClawdBot Tamagotchi.
Open in Schematik →Related guides

How to Build a Cosmic Critter Pet with Raspberry Pi Pico
Raspberry Pi Pico · Beginner

How to Build a Gesture-Controlled Mood Lamp with ESP32
ESP32 · Beginner

How to Build an Arcade Reaction Tower with ESP32
ESP32 · Beginner

How to Build a Self-Balancing Rover with ESP32
ESP32 · Intermediate