Desk Buddy is a focus timer that detects when you're away from your desk using motion sensing and displays your work session status on a compact OLED screen. Built around an ESP32 microcontroller, it combines an accelerometer to track movement with a push button for manual control, creating a simple yet effective productivity companion.
This guide provides a complete wiring diagram for breadboard assembly, a full parts list, and the complete firmware needed to get started. Follow the step-by-step assembly instructions to connect the SSD1306 display and MPU-6050 motion sensor, then deploy the code to your ESP32 and begin tracking your focus sessions.
Wiring diagram

Gather all the parts
Assemble it in 3 steps
1. Wire the 60-point breadboard
With USB unplugged, use the short six-hole power rail on your 60-point breadboard for GND and a separate connected group in the main grid for 3V3. Check which holes are connected with a continuity meter if available. Connect ESP32 3V3, OLED VCC and MPU6050 VCC to the 3V3 group (three holes). Connect the ESP32 GND beside 3V3, OLED GND and MPU6050 GND to the GND rail, leaving a fourth hole for the button. Use one hole per wire; do not assume all six rail holes are connected. If the rail does not have four connected holes, use a separate group of four or more connected holes in the main grid for GND.
- Keep 3V3 and GND separate. Do not use 5V or VIN. Leave the Li-Po disconnected.
2. Connect the signals and mount the focus button
Use two more separate connected groups in the main grid. Join ESP32 GPIO21 to both SDA pins in one group, and GPIO22 to both SCL pins in the other. Leave AD0, INT, XDA and XCL unconnected. Fit the tactile switch across the center gap, in the main hole grid. Use one leg from each internally connected pair. Run one leg's hole group to GPIO27 and the other leg's group to the fourth hole on the GND rail. Neither button group should overlap the 3V3 group. If checking with a meter before plugging in USB, the two chosen legs should have continuity only while pressed.
3. Deploy and try Blink
Plug in USB and press Deploy. Tilt Blink to make its eyes look sideways. Move it to wake it. Tap the button to start focus or hold it to cancel.
Review all connections
1. Connections between "face" and "ESP32"
2. Connections between "motion" and "ESP32"
3. Connections between "key" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <U8g2lib.h>
U8G2_SSD1306_128X64_NONAME_F_HW_I2C face(U8G2_R0, U8X8_PIN_NONE, 22, 21);
constexpr int button = 27;
constexpr uint32_t duration = 25UL * 60 * 1000;
uint8_t imu = 0;
int offset = 0;
uint32_t sampled;
int previous[3];
bool haveSample;
uint32_t active;
void sampleMotion(uint32_t now) {
if (!imu || now-sampled<40) return;
sampled=now;
Wire.beginTransmission(imu);
Wire.write(0x3B);
if (Wire.endTransmission(false) || Wire.requestFrom(imu, uint8_t(6))!=6) return;
int a[3];
for (int i=0;i<3;i++) {
int hi=Wire.read(), lo=Wire.read();
a[i]=int16_t((hi<<8)|lo);
if (haveSample && abs(a[i]-previous[i])>1400) active=now;
previous[i]=a[i];
}
haveSample=true;
offset=a[0]>4500?7:a[0]<-4500?-7:0;
}
bool running, done, raw, pressed;
uint32_t started, changed, down;
void setup(){
pinMode(button, INPUT_PULLUP);
Wire.begin(21,22);
Wire.beginTransmission(0x3C);
if(Wire.endTransmission()!=0) face.setI2CAddress(0x3D*2);
face.begin(); face.setFont(u8g2_font_6x10_tf);
for (uint8_t addr : {0x68,0x69}) {
Wire.beginTransmission(addr);
Wire.write(0x6B);
Wire.write(0);
if (Wire.endTransmission()==0) { imu=addr; break; }
}
active=millis();
}
void loop(){
uint32_t now=millis();
bool b=!digitalRead(button);
if(b!=raw){raw=b; changed=now;}
if(raw!=pressed && now-changed>=30){
pressed=raw; active=now;
if(pressed) down=now;
else if(now-down>=700){running=false; done=false;}
else if(!running){started=now; running=true; done=false;}
}
if(running && now-started>=duration){running=false; done=true;}
sampleMotion(now);
bool asleep=!running && !done && now-active>=30000;
bool blink=asleep || now%4100<130;
int state=done?3:running?2:asleep?1:0;
int seconds=running?(duration-(now-started)+999)/1000:0;
static int oldState=-1, oldSec=-1, oldOffset=99; static bool oldBlink=false;
if(state==oldState && seconds==oldSec && offset==oldOffset && blink==oldBlink){delay(5);return;}
oldState=state;oldSec=seconds;oldOffset=offset;oldBlink=blink;
face.clearBuffer();
for(int x:{30,78}) face.drawRBox(x+offset,blink?23:13,20,blink?3:21,blink?1:5);
face.drawLine(55,39,60,44); face.drawLine(60,44,68,44); face.drawLine(68,44,73,39);
char line[22];
if(running) snprintf(line,sizeof(line),"FOCUS %02d:%02d",seconds/60,seconds%60);
else snprintf(line,sizeof(line),"%s",done?"Time for a break!":asleep?"Zzz...":"Button: 25 min focus");
face.drawStr((128-face.getStrWidth(line))/2,61,line);
face.sendBuffer();
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




