← LOGBOOK LOG-348
WORKING · ELECTRONICS ·
ARDUINOI2CMPU6050OLEDSERVOSENSORS

Gyro, OLED & Servo — First Tests

Three new components arrive: MPU-6050 gyro, SSD1306 OLED display, and SG90 servo. First wiring, library install, and sketches for each.

The Arrivals

Three packages showed up today: MPU-6050 gyro/accelerometer, SSD1306 128×64 OLED, and an SG90 micro servo. All the parts that make a project feel like it’s actually sensing and responding to the world.

Tested each one in sequence on the same Uno from the blinker session.


MPU-6050 — Gyro & Accelerometer

The MPU-6050 packs a 3-axis gyroscope and a 3-axis accelerometer onto a single I2C chip. It’s the sensor inside most cheap drone flight controllers.

Wiring

I2C means just four wires:

MPU-6050    Arduino Uno
VCC      →  3.3V
GND      →  GND
SCL      →  A5
SDA      →  A4

The module’s AD0 pin pulled low sets the I2C address to 0x68.

Library

arduino-cli lib install "MPU6050"

This installs the Jeff Rowberg MPU6050 library along with the I2C device base class.

Sketch

#include <Wire.h>
#include <MPU6050.h>

MPU6050 mpu;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  mpu.initialize();
  Serial.println(mpu.testConnection() ? "MPU-6050 connected" : "connection failed");
}

void loop() {
  int16_t ax, ay, az, gx, gy, gz;
  mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

  Serial.print("ax="); Serial.print(ax);
  Serial.print(" ay="); Serial.print(ay);
  Serial.print(" az="); Serial.println(az);
  delay(200);
}

The raw values are 16-bit integers from the ADC. At the default ±2g range, divide by 16384 to get g-force. Tilting the board and watching the ax/ay values track was the first moment it felt like a real sensor.


SSD1306 — OLED Display

128×64 pixels, monochrome, I2C. Tiny but remarkably sharp. The same I2C bus as the MPU-6050 — different address (0x3C), so both can run simultaneously.

Wiring

SSD1306     Arduino Uno
VCC      →  3.3V
GND      →  GND
SCL      →  A5
SDA      →  A4

Library

arduino-cli lib install "Adafruit SSD1306"
arduino-cli lib install "Adafruit GFX Library"

Adafruit GFX is the graphics primitive layer — lines, rectangles, text, bitmaps. SSD1306 is the driver on top.

Sketch

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

#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

void setup() {
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("bench: 2026-03-23");
  display.display();
}

void loop() {}

The -1 in the constructor means no reset pin connected — the module handles its own reset. display.display() flushes the buffer to the screen; nothing appears until you call it.

Seeing text appear on a 0.96” screen wired directly to the Uno was disproportionately satisfying.


SG90 — Micro Servo

The SG90 is a 9g servo with ~180° range. Unlike the I2C modules, it uses a PWM signal on any digital pin — the Servo library handles the timing.

Wiring

SG90        Arduino Uno
Red      →  5V
Brown    →  GND
Orange   →  Pin 9 (PWM)

Servo needs 5V, not 3.3V — the motor stalls or behaves erratically at lower voltage.

Sketch

#include <Servo.h>

Servo sg90;

void setup() {
  sg90.attach(9);
}

void loop() {
  sg90.write(0);
  delay(1000);
  sg90.write(90);
  delay(1000);
  sg90.write(180);
  delay(1000);
}

The Servo library generates a 50Hz PWM signal. Pulse width between 1ms and 2ms maps to 0°–180°. sg90.write() abstracts the pulse math.

The snap to each position is fast and precise. The SG90’s plastic gears are audible at the limit stops — don’t hold it hard against 0° or 180° for long.


What’s Next

The obvious next step: feed the MPU-6050 gyro data into the servo — tilt the board, the servo follows. That’s the core of a gimbal stabilizer, just without the mechanical mount. After that, print live sensor readings on the OLED instead of Serial Monitor.

All three components on the same I2C bus (plus the servo on PWM) should fit without any conflicts.