✅ COMPLETED IN LAB Day 10 (18 Nov) 🎮 40Hz Web Serial

Session 3: Push Buttons & 2-in-1 Motion Game Controller

Swapped 2 external LEDs for 2 tactile Push Buttons (Gas & Brake using internal INPUT_PULLUP). MPU-6050 tilt steers the car left/right, and 2-way feedback flashes the onboard RGB LED on crashes!

🎮 Play 2-in-1 Browser Game (/game) ← Course Book
Connect Robo Logo Connect Robo Kit

⚡ 4-Step Visual System Flow

No Text Walls • 1-Glance Architecture
Step 1 🔘
Dual Push Buttons
INPUT_PULLUP Logic

GAS (GPIO 4) & BRAKE (GPIO 5) active LOW triggers.

Step 2 🏎️
Hand Tilt Steering
MPU-6050 6-Axis

Tilt board left/right to steer car on the virtual track.

Step 3 ⚡
40Hz Serial Stream
115200 Baud Web Serial

Streams real-time binary telemetry packets to browser.

Step 4 🎮
Live Motion Game
connectrobo.in/game

Play car racing & airplane flight with 2-way RGB glow!

1

🧰 Components Used in Session 3

ESP32-S3
ESP32-S3 Dev Board Brain • Dual USB-C
MPU-6050 IMU
MPU-6050 Motion IMU SDA 8 / SCL 9 (400kHz I2C)
Push Buttons
2x Tactile Push Buttons Gas (GPIO 4) & Brake (GPIO 5)
Breadboard
Breadboard & Wires Common GND (No Resistors!)
★

🎮 Interactive Game Controller Simulator (Touch to Steer & Gas/Brake!)

40Hz USB Telemetry
Virtual MPU-6050 Tilt Steering
0.0° (Center)
GPIO 48 RGB: IDLE (Green)
Tilt Slider (MPU-6050 Roll): 0°
⟵ Turn Left (-30°) Center Turn Right (+30°) ⟶
🎮 Play Full Game (/game) →
3

🔌 Circuit Diagram & Exact Pinout (Zero External Resistors)

Circuit Wiring MPU-6050 (I2C) + 2x Push Buttons (INPUT_PULLUP)
MPU-6050 VCC
Red Jumper Wire to 3.3V Power Rail
3.3V Power
Common Ground (GND)
Black Jumper connecting MPU GND and Button Legs
GND
MPU-6050 SDA
Yellow Jumper Wire for I2C Data
GPIO 8
MPU-6050 SCL
Green Jumper Wire for I2C Clock
GPIO 9
GAS Push Button
Blue Jumper Wire (Internal Pullup Resistor Active)
GPIO 4
BRAKE Push Button
Orange Jumper Wire (Internal Pullup Resistor Active)
GPIO 5
Built-in WS2812 RGB
Onboard LED: Green=Gas, Red=Brake, Cyan=Ready
GPIO 48
4

⚡ Step-by-Step Verified Code (1-Click "Open in IDE")

step1_buttons_test.ino ESP32-S3 24 lines
/* Step 1: INPUT_PULLUP Button Check */
#define BTN_GAS 4
#define BTN_BRAKE 5

void setup() {
  Serial.begin(115200);
  pinMode(BTN_GAS, INPUT_PULLUP);
  pinMode(BTN_BRAKE, INPUT_PULLUP);
}

void loop() {
  bool gas = !digitalRead(BTN_GAS);
  bool brake = !digitalRead(BTN_BRAKE);
  Serial.printf("Gas: %d | Brake: %d\n", gas, brake);
  delay(100);
}
Preview (8 of 24 lines) — Click ⚡ Open in IDE to auto-load code & board!
✅ Output: Pressing buttons prints Gas: 1 / Brake: 1 on Serial Monitor!
step2_final_motion_game_controller.ino ESP32-S3 62 lines
/* Connect Robo 2-in-1 Motion Game Controller Firmware */
#include <Wire.h>
#define BTN_GAS 4
#define BTN_BRAKE 5
#define MPU_ADDR 0x68
#define RGB_PIN 48

void setup() {
  Serial.begin(115200);
  Wire.begin(8, 9);
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x6B);
  Wire.write(0);
  Wire.endTransmission();
  pinMode(BTN_GAS, INPUT_PULLUP);
  pinMode(BTN_BRAKE, INPUT_PULLUP);
  neopixelWrite(RGB_PIN, 0, 40, 20);
}

void loop() {
  // Read MPU-6050 Gyro Accel
  Wire.beginTransmission(MPU_ADDR);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_ADDR, 6, true);
  int16_t ax = (Wire.read() << 8) | Wire.read();
  int16_t ay = (Wire.read() << 8) | Wire.read();
  float steer = (ay / 16384.0) * 45.0;
  bool gas = !digitalRead(BTN_GAS);
  bool brake = !digitalRead(BTN_BRAKE);

  // 40Hz Web Serial Stream
  Serial.printf("S:%.1f,G:%d,B:%d\n", steer, gas, brake);
  delay(25);
}
Preview (8 of 62 lines) — Click ⚡ Open in IDE to auto-load code & board!
✅ Output: Streams 40 packets/sec! Drives 2-in-1 Car Racer & Jet Fighter at https://www.connectrobo.in/game
← Session 2: Tilt Spirit Level Session 4: SG90 Servo Motor →