Build a handheld retro game station powered by an ESP32 microcontroller and a small OLED display. This project combines simple push-button controls with four classic arcade-style games—Dodge, Catch, Paddle, and Target—each with multiple difficulty levels to master.
The guide provides a complete wiring diagram for connecting the SSD1306 OLED screen and six push buttons to the ESP32, a full parts list, step-by-step assembly instructions for building the handheld enclosure, and ready-to-upload firmware with all four games included. Readers will learn how to wire I2C displays, handle button input with debouncing, and create simple game logic on a microcontroller.
Wiring diagram

Gather all the parts
Assemble it in 4 steps
1. Connect the screen with USB unplugged
Use a 0.96-inch 128x64 SSD1306 I2C screen. VCC goes to 3V3 and GND to GND. SDA goes to GPIO21 (data); SCL goes to GPIO22 (clock).
- Read the printed pin labels: swapping VCC and GND can damage the screen. Do not use 5V for this circuit.
2. Make the controller
Arrange four momentary buttons as a direction pad and two as A and B. Connect one switched contact of every button to GND. Connect the other contact to GPIO32 for up, GPIO33 for down, GPIO25 for left, GPIO26 for right, GPIO27 for A, and GPIO13 for B. Internal pull-ups are enabled.
- On four-legged tactile switches, use contacts on opposite switched sides; two legs on the same side may already be joined. Check before soldering.
3. Mount and check the handheld
Secure the board, screen and buttons in an insulated small enclosure, leaving the USB connector accessible. Keep exposed contacts apart. Power through the board USB connector only; there is no battery or charger in this design.
4. Learn the controls
Up and down select one of four games. Left and right select challenge 1 through 100. A starts or retries; B returns to the menu. Dodge avoids falling blocks; Catch collects them; Paddle bounces the ball; Target uses all four directions to aim and A to fire. Higher challenges run faster or require more accurate aim.
Review all connections
1. Connections between "screen" and "ESP32"
2. Connections between "up" and "ESP32"
3. Connections between "down" and "ESP32"
4. Connections between "left" and "ESP32"
5. Connections between "right" and "ESP32"
6. Connections between "a" and "ESP32"
7. Connections between "b" and "ESP32"
Deploy the firmware
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
Adafruit_SSD1306 d(128,64,&Wire,-1);
const int pins[]={32,33,25,26,27,13};
bool held[6]={},edge[6]={},raw[6]={}; uint32_t changed[6]={};
const char* names[]={"DODGE","CATCH","PADDLE","TARGET"};
int game=0,level=1,score=0,px=60,x=20,y=12,vx=2,vy=2,targetX=40,targetY=30;
bool playing=false,over=false,dirty=true; uint32_t tick=0;
void text(int x0,int y0,const char* s){d.setCursor(x0,y0);d.print(s);}
void start(){score=0;px=60;x=20;y=14;vx=2;vy=2;targetX=random(8,120);targetY=random(20,56);playing=true;over=false;dirty=true;tick=millis();}
void draw(){
d.clearDisplay();d.setCursor(0,0);
if(!playing){d.print("400 CHALLENGES");text(0,14,names[game]);d.setCursor(0,26);d.print("Challenge ");d.print(level);text(0,39,"UP/DOWN: game");text(0,49,"L/R: level A: play");}
else if(over){text(0,12,"ROUND OVER");d.setCursor(0,27);d.print("Score: ");d.print(score);text(0,44,"A retry B menu");}
else {d.print(names[game]);d.print(" ");d.print(score);
if(game<3){d.fillRect(px,59,20,4,SSD1306_WHITE);d.fillRect(x,y,4,4,SSD1306_WHITE);}
else {d.drawCircle(targetX,targetY,4,SSD1306_WHITE);d.drawLine(x-3,y,x+3,y,SSD1306_WHITE);d.drawLine(x,y-3,x,y+3,SSD1306_WHITE);}
}
d.display();dirty=false;
}
void setup(){Serial.begin(115200);for(int p:pins)pinMode(p,INPUT_PULLUP);Wire.begin(21,22);if(!d.begin(SSD1306_SWITCHCAPVCC,0x3C)){Serial.println("Screen not found; check wiring");while(true)delay(100);}d.setTextSize(1);d.setTextColor(SSD1306_WHITE);randomSeed(micros());}
void loop(){
uint32_t now=millis();for(int i=0;i<6;i++){edge[i]=false;bool r=digitalRead(pins[i])==LOW;if(r!=raw[i]){raw[i]=r;changed[i]=now;}if(now-changed[i]>=25 && held[i]!=raw[i]){held[i]=raw[i];edge[i]=held[i];}}
if(edge[5]){playing=false;dirty=true;}
if(!playing){if(edge[0]){game=(game+3)%4;dirty=true;}if(edge[1]){game=(game+1)%4;dirty=true;}if(edge[2]){level=level==1?100:level-1;dirty=true;}if(edge[3]){level=level==100?1:level+1;dirty=true;}if(edge[4])start();}
else if(over){if(edge[4])start();}
else if(now-tick>=uint32_t(160-level)){
tick=now;
if(game<3){int old=px;px=constrain(px+(held[3]?5:0)-(held[2]?5:0),0,108);if(old!=px)dirty=true;
if(game<2){y+=2+level/25;if(y>=55){bool hit=x+4>=px&&x<=px+20;if((game==0&&hit)||(game==1&&!hit))over=true;else score++;y=12;x=random(0,124);}dirty=true;}
else {x+=vx;y+=vy;if(x<=0||x>=124){vx=-vx;x=constrain(x,0,124);}if(y<=11){vy=abs(vy);y=11;}if(y>=55&&vy>0){if(x+4>=px&&x<=px+20){vy=-abs(vy);score++;y=54;}else over=true;}dirty=true;}
}else {int ox=x,oy=y;x=constrain(x+(held[3]?3:0)-(held[2]?3:0),0,127);y=constrain(y+(held[1]?3:0)-(held[0]?3:0),12,63);if(x!=ox||y!=oy)dirty=true;}
}
if(playing&&!over&&game==3&&edge[4]){int radius=9-level/20;if(abs(x-targetX)<=radius&&abs(y-targetY)<=radius){score++;targetX=random(8,120);targetY=random(20,56);}else over=true;dirty=true;}
if(dirty)draw();delay(1);
}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.




