GPS speedometer and clock
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Shop by category
Shop all componentsA GNSS receiver works out position and speed from satellites. This trip computer reads the receiver's NMEA sentences with TinyGPSPlus, adds up distance, and shows speed and time on an OLED. A BMI160 6-axis IMU watches for a sudden shock followed by stillness, the pattern of a fall, and starts a loud beep so passers-by notice.
Do not look at the screen while riding fast; glance only when safe.
This alert is a learning project, not a certified safety device.
Tick anything you already have and the total updates.
GPS + BeiDou receiver with UART and I2C
GNSS module with a built-in clock that keeps time between rides
BMM150 magnetometer for a compass heading at standstill
3D Hall angle sensor for a handlebar menu joystick
Attitude angle module that outputs angles directly
Follow the colours: red is power, dark grey is ground, blue is a signal.
Power the ESP32 from a USB power bank in a bar bag.
trip_computer.inoVerify & upload in Electrolark#include <Wire.h>
#include <TinyGPSPlus.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
TinyGPSPlus gps;
HardwareSerial gnss(2);
Adafruit_SSD1306 oled(128, 64, &Wire, -1);
uint8_t IMU = 0x69;
const int BUZ = 14;
double km = 0, lastLat = 0, lastLng = 0;
unsigned long startMs, shockAt = 0;
bool alarm = false;
void imuWrite(uint8_t r, uint8_t v) { Wire.beginTransmission(IMU); Wire.write(r); Wire.write(v); Wire.endTransmission(); }
float accelG() {
Wire.beginTransmission(IMU); Wire.write(0x12); Wire.endTransmission(false);
Wire.requestFrom(IMU, (uint8_t)6);
int16_t x = Wire.read() | (Wire.read() << 8);
int16_t y = Wire.read() | (Wire.read() << 8);
int16_t z = Wire.read() | (Wire.read() << 8);
return sqrt((float)x * x + (float)y * y + (float)z * z) / 16384.0; // ±2 g range
}
void setup() {
Serial.begin(115200);
gnss.begin(9600, SERIAL_8N1, 16, 17);
Wire.begin(21, 22);
Wire.beginTransmission(0x69);
if (Wire.endTransmission() != 0) IMU = 0x68; // board address depends on SA0
Serial.printf("BMI160 at 0x%02X\n", IMU);
imuWrite(0x7E, 0x11); // accelerometer to normal mode
delay(50);
pinMode(BUZ, OUTPUT);
oled.begin(SSD1306_SWITCHCAPVCC, 0x3C);
startMs = millis();
}
void loop() {
while (gnss.available()) gps.encode(gnss.read());
if (gps.location.isUpdated() && gps.location.isValid() && gps.speed.kmph() > 2) {
if (lastLat != 0) km += TinyGPSPlus::distanceBetween(lastLat, lastLng, gps.location.lat(), gps.location.lng()) / 1000.0;
lastLat = gps.location.lat(); lastLng = gps.location.lng();
}
float g = accelG();
if (g > 3.0) shockAt = millis(); // hard shock
if (shockAt && millis() - shockAt > 5000 && fabs(g - 1.0) < 0.1) alarm = true; // then still
if (shockAt && millis() - shockAt > 10000) shockAt = 0;
digitalWrite(BUZ, alarm && (millis() / 250) % 2);
unsigned long mins = (millis() - startMs) / 60000;
oled.clearDisplay(); oled.setTextColor(WHITE);
oled.setTextSize(3); oled.setCursor(0, 0); oled.print(gps.speed.isValid() ? gps.speed.kmph() : 0.0, 1);
oled.setTextSize(1); oled.print(" km/h");
oled.setCursor(0, 34); oled.printf("%.2f km %lu min", km, mins);
oled.setCursor(0, 48); oled.printf("Sats %d %s", gps.satellites.value(), alarm ? "FALL!" : "");
oled.display();
delay(50);
}
The sketch above runs here on a simulated ESP32. Move the sliders for the sensors and buttons it reads, and watch the Serial monitor, display and outputs change.
Go outdoors with a clear sky and wait a few minutes for the first fix. Check TX and RX are not swapped.
GPS position wanders slightly; the code ignores fixes below 2 km/h for that reason.
Raise the 3.0 g shock threshold or the five-second stillness time.
No. GNSS only receives satellite signals.
Yes, add the 4G modem from the SMS door alarm project.
RTK adds corrections from a base station for centimetre accuracy; it needs an RTK-capable receiver.
11 parts: ESP32-WROOM-32 38-Pin Development Board, DFRobot Gravity GNSS GPS BeiDou Receiver Module – I2C & UART, Generic GY-BMI160 6DOF 6-Axis IMU Module – I2C/SPI Interface, 0.96" OLED Display 128x64, Buzzer Module 3.3–5V, DFRobot Gravity GNSS GPS BeiDou Positioning Module with RTC – I2C & UART, DFRobot Fermion BMM150 Triple Axis Magnetometer Sensor Breakout – I2C/SPI Interface, Melexis MLX90333 MCU-93 Joystick Sensor Position Digital 3D Angle – Triaxis Hall Module, Generic Raspberry Pi-1031 4DOF Attitude Angle Sensor Module – I2C/SPI Interface, Solderless Breadboard, plus 1 more. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 3 hours. The build on this page has 6 steps.
No. This page has the complete, tested code (trip_computer.ino).
Yes. The Run it panel under the code runs this exact sketch on a simulated board. Move the sliders or press the buttons for the sensors it reads, and the Serial monitor, display and outputs react as they will on the real build. It is a simulation, so real readings depend on your parts and wiring.
About ₹7,344 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Parsing NMEA with TinyGPSPlus; Adding distance from GPS fixes; Simple fall detection from accelerometer data.
Do not look at the screen while riding fast; glance only when safe. This alert is a learning project, not a certified safety device.
Ideas that reuse this build: 4G SMS door alarm. They are listed under Take it further on this page.
A bike or car speedometer that needs no wheel sensor: satellites do the measuring.
Records where you went every five seconds, ready to open on a map.
Two boards, two radios: press the button at the gate and it rings indoors.
Check temperature, humidity and pressure from any phone on your Wi-Fi.
Learning project. Check every circuit and the datasheet of each part before you power it up.
BMI160 at 0x68
A simulation of the sketch above, so you know what to expect. Real readings vary with your parts and wiring.