Arduino Project
Speed Meter
Course Introduction
In this lesson, you’ll learn how to use an L9110 Motor Driver Module, a TT motor, and an OLED display with the Arduino to build a simple Motor Speed Control system.
A button press cycles through multiple speed levels, and the motor speed is displayed on the OLED as both a numeric RPM value and a bar graph.
Note
If this is your first time working with an Arduino project, we recommend downloading and reviewing the basic materials first.
1.1 Install Arduino IDE(Important)
1.2 Introduction of Arduino IDE
Wiring

Common Connections:
OLED Display Module
SDA: Connect to A4 on the Arduino.
SCK: Connect to A5 on the Arduino.
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.
Button
Connect to breadboard’s negative power bus.
Connect to 2 on the Arduino.
TT Motor
Connect to MOTOR A on the L9110 Motor Driver Module.
L9110 Motor Driver Module
GND: Connect to breadboard’s negative power bus.
VCC: Connect to breadboard’s red power bus.
A-1B: Connect to 6 on the Arduino.
A-1A: Connect to 5 on the Arduino.
Writing the Code
Note
You can copy this code into the Arduino IDE.
To install the library, use the Arduino Library Manager and search for Adafruit SSD1306 and Adafruit GFX and install it.
Don’t forget to select the board(Arduino UNO R4) and the correct port before clicking the Upload button.
#include
#include
#include
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET -1
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
// Motor pins (L9110)
#define MOTOR_PIN1 5
#define MOTOR_PIN2 6
// Button pin
#define BUTTON_PIN 2
// Motor speed levels (PWM values)
int speedLevels[5] = {0, 100, 150, 200, 255};
int currentLevel = 0;
// Button debounce
bool lastButtonState = HIGH;
unsigned long lastDebounceTime = 0;
const unsigned long debounceDelay = 200;
void setup() {
pinMode(MOTOR_PIN1, OUTPUT);
pinMode(MOTOR_PIN2, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
// Initialize OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
for (;;) ; // Stop if OLED not found
}
display.clearDisplay();
display.display();
}
void loop() {
handleButton();
updateMotor();
drawSpeed();
delay(50);
}
void handleButton() {
bool buttonState = digitalRead(BUTTON_PIN);
if (buttonState == LOW && lastButtonState == HIGH && (millis() - lastDebounceTime) > debounceDelay) {
currentLevel++;
if (currentLevel > 4) currentLevel = 0; // Loop back to stop
lastDebounceTime = millis();
}
lastButtonState = buttonState;
}
void updateMotor() {
int speed = speedLevels[currentLevel];
if (speed == 0) {
analogWrite(MOTOR_PIN1, 0);
analogWrite(MOTOR_PIN2, 0);
} else {
analogWrite(MOTOR_PIN1, speed);
analogWrite(MOTOR_PIN2, 0);
}
}
void drawSpeed() {
int pwm = speedLevels[currentLevel];
float rpm = (pwm / 255.0) * 200.0; // Approximate RPM (TT motor max ~200RPM)
// Calculate bar length (max 100px)
int barLength = map(pwm, 0, 255, 0, 100);
display.clearDisplay();
// --- Display numeric speed (big font) ---
display.setTextSize(2); // Large font
display.setTextColor(SSD1306_WHITE);
display.setCursor(0, 0); // Position at top-left
display.print("RPM");
display.setCursor(0, 20); // Second line
display.print((int)rpm);
// --- Draw bar graph ---
display.drawRect(10, 50, 100, 10, SSD1306_WHITE); // Outline
display.fillRect(10, 50, barLength, 10, SSD1306_WHITE); // Filled part
display.display();
}
