Siddhant Kumar
Project 090 · Automotive

Two-Wheeler Anti-Theft GPS.

Feels a parked motorcycle being tampered with, warns and alerts the owner instantly, and tracks it live if it is taken — deterrence, alarm and recovery in one.

Intermediate 12–18 hours 28 min read GPSGeofenceSecurity
Jump to source Bill of materials
Two-Wheeler Anti-Theft GPS — reference build illustration MCU VCC · GND · SIG · NC
Difficulty
Intermediate
Build time
12–18 hours
Indicative cost
₹2,500 – ₹4,500
Platform
ESP32 DevKit V1 (ESP-WROOM-32)
Category
Automotive
Last updated
28 July 2026
Contents — 26 sections

Project Overview

Feels a parked motorcycle being tampered with, warns and alerts the owner instantly, and tracks it live if it is taken — deterrence, alarm and recovery in one.

Motorcycles and scooters are stolen far more easily than cars — they are light enough to lift into a van, quick to hot-wire, and often parked in the open — and once gone they are rarely recovered because there is no way to follow them. This project builds an anti-theft tracker that covers the whole timeline of a theft: it detects tampering on a parked bike, alerts the owner instantly, and if the bike is taken, tracks it live so it can be recovered. Deterrence, alarm and recovery in one small, hidden unit.

The core is motion-based tamper detection. While the bike is parked and armed, an accelerometer watches for the signatures of theft — the bike being lifted, wheeled, tilted onto its stand, knocked, or started — distinguishing a real tampering event from harmless nudges (wind, a passer-by brushing past) so it does not cry wolf. On a genuine event it does two things at once: sounds a local alarm as a deterrent, and sends the owner an instant alert over cellular. If motion continues — the bike is actually being taken — it switches to live GPS tracking, streaming location so the owner and, where appropriate, the police can follow and recover it.

The design is built around the realities of a hidden, battery-lean device on a parked vehicle: it spends almost all its life in low-power sleep, woken by the accelerometer only when something moves, so a small battery lasts; it is hidden and tamper-resistant so a thief cannot simply pull it off; and it escalates sensibly (nudge → warn, sustained motion → alarm + track). It is honest that no tracker guarantees recovery, that thieves may find and disable a unit, and that recovery should go through the police rather than owner heroics. But as a motion-triggered, alerting, live-tracking anti-theft device tuned for two-wheelers, it turns a bike from an easy, untraceable target into one that fights back — noisy when touched, and followable if taken.

A GPS navigation satellite in orbit
A hidden anti-theft tracker deters, alarms and tracks — covering the whole timeline of a two-wheeler theft. Photograph sourced from Wikimedia Commons — GPS satellite.jpg. Reused under the licence stated on that page; please check it before republishing.

What this project does

  • Detects tampering on a parked bike via motion (lift/tilt/wheel/knock)
  • Distinguishes real theft from harmless nudges
  • Sounds a local alarm as a deterrent
  • Alerts the owner instantly over cellular
  • Switches to live GPS tracking if the bike is taken
  • Sleeps in ultra-low power, woken only by motion
  • Stays hidden and tamper-resistant

Real-World Applications

SettingHow it is used
Personal two-wheeler securityDeterrence, alarm and recovery tracking for a bike or scooter.
Delivery-fleet two-wheelersAnti-theft across many riders' vehicles.
Rental / shared mobilityTamper alerts and location for shared scooters/bikes.
High-value parked assetsMotion-triggered alerting for anything parked and portable.

Deployment contexts where a build of this kind earns its keep.

Features & Capabilities

  • Motion/tamper detection with false-alarm rejection
  • Instant owner alert + local alarm
  • Live GPS tracking on sustained motion
  • Escalation (nudge → warn → alarm + track)
  • Ultra-low-power sleep, accelerometer wake
  • Hidden, tamper-resistant install
  • Honest about recovery limits and lawful process

Difficulty, Time & Required Skills

AttributeValue
Difficulty levelIntermediate
Estimated completion time12–18 hours
Indicative build cost₹2,500 – ₹4,500
Primary disciplineAutomotive
Reference platformESP32 DevKit V1 (ESP-WROOM-32)

Skills you should have (or will pick up)

  • Accelerometer motion/tamper classification
  • False-alarm rejection (real theft vs nudge)
  • Ultra-low-power sleep + motion wake
  • GPS tracking and cellular alerting
  • Hidden, tamper-resistant installation

Bill of Materials

Every part below is commonly available from Indian and international hobby-electronics suppliers. Prices are indicative 2026 retail figures in Indian rupees and will drift — treat them as a budgeting guide, not a quotation.

ComponentKey specificationQtyApprox. cost
ESP32 DevKit V1 (ESP-WROOM-32)
Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC1₹450
MPU-6050 6-axis IMU
Gyro bias drifts with temperature — re-zero at boot while the device is still.
3-axis gyro ±250–2000 °/s, 3-axis accel ±2–16 g, 16-bit ADC, on-chip DMP1₹190
u-blox NEO-6M GPS module + ceramic patch antenna
Needs clear sky view; indoors it will never get a first fix.
50 channels, −161 dBm tracking, 2.5 m CEP, 1–5 Hz update, cold start 27 s1₹550
SIM800L GSM/GPRS module
Transmit bursts hit 2 A — needs a 4.0 V supply and a 1000 µF bulk capacitor.
Quad-band 850/900/1800/1900 MHz, GPRS class 12, SMS + TCP/IP1₹550
Active piezo buzzer 5 V
Active buzzers make tone on DC; passive ones need a PWM carrier.
85 dB at 10 cm, 2.3 kHz resonance, 12 mm diameter1₹25
18650 Li-ion cell 3400 mAh + holder
Never charge below 0 °C; always use a protected cell or a BMS.
3.7 V nominal, 4.2 V full, 3400 mAh, ~12.6 Wh, 2 C discharge1₹450
Accelerometer
Wakes the MCU only when moved
Motion/tilt with wake-on-motion interrupt1₹150
GPS + cellularLive location and alerting1₹1,200
Hidden enclosureConcealed, tamper-resistant mount + wiring1₹300
Battery + chargerLi-ion with charge from the bike (with cutoff)1₹400

Estimated total: ₹4,265, excluding tools, shipping and consumables.

Tools and consumables

  • Soldering iron (temperature controlled, 350 °C) with 0.8 mm 60/40 or lead-free solder
  • Digital multimeter — continuity, DC volts and current ranges
  • Wire strippers, flush cutters and a small set of precision screwdrivers
  • Heat-shrink tubing and a heat gun (or a lighter, carefully)
  • A laptop with a USB port and the toolchain listed above

Hardware Specifications

PartSpecificationSupplyInterfaceReference
ESP32 DevKit V1 (ESP-WROOM-32)Dual-core Xtensa LX6 @ 240 MHz, 520 KB SRAM, 4 MB flash, Wi-Fi 802.11 b/g/n + BLE 4.2, 34 GPIO, 18× 12-bit ADC, 2× 8-bit DAC3.3 V logic / 5 V USBUART, SPI, I²C, I²S, CAN, PWMDatasheet
MPU-6050 6-axis IMU3-axis gyro ±250–2000 °/s, 3-axis accel ±2–16 g, 16-bit ADC, on-chip DMP2.375–3.46 V (module 5 V tolerant)I²C (0x68/0x69)Datasheet
u-blox NEO-6M GPS module + ceramic patch antenna50 channels, −161 dBm tracking, 2.5 m CEP, 1–5 Hz update, cold start 27 s3.3–5 VUART NMEA 9600Datasheet
SIM800L GSM/GPRS moduleQuad-band 850/900/1800/1900 MHz, GPRS class 12, SMS + TCP/IP3.4–4.4 V (NOT 5 V)UART AT commandsDatasheet
Active piezo buzzer 5 V85 dB at 10 cm, 2.3 kHz resonance, 12 mm diameter3–5 VDigital / PWMDatasheet
18650 Li-ion cell 3400 mAh + holder3.7 V nominal, 4.2 V full, 3400 mAh, ~12.6 Wh, 2 C discharge3.0–4.2 VHolder / spot-welded tabsDatasheet

Consolidated electrical and interface specifications for every active part in the build.

Power Budget & Supply Sizing

Add up the typical active current of every part, then size the supply with at least 50 % headroom so transmit bursts and motor inrush never brown out the controller.

LoadSupply railTypical current (mA)Notes
ESP32 DevKit V1 (ESP-WROOM-32)3.3 V logic / 5 V USB160Wi-Fi transmit bursts peak near 500 mA — size the regulator accordingly.
MPU-6050 6-axis IMU2.375–3.46 V (module 5 V tolerant)3.9Gyro bias drifts with temperature — re-zero at boot while the device is still.
u-blox NEO-6M GPS module + ceramic patch antenna3.3–5 V45Needs clear sky view; indoors it will never get a first fix.
SIM800L GSM/GPRS module3.4–4.4 V (NOT 5 V)2000Transmit bursts hit 2 A — needs a 4.0 V supply and a 1000 µF bulk capacitor.
Active piezo buzzer 5 V3–5 V30Active buzzers make tone on DC; passive ones need a PWM carrier.

Summed typical draw is 2238.9 mA. With a 1.5× design margin the supply should deliver at least 3400 mA continuously at the stated rail voltage.

Software Requirements & Development Environment

Reference toolchain: Arduino IDE 2.3.x with the ESP32 board package 3.x (or PlatformIO on VS Code). Anything newer normally works; anything older may lack the board definitions used here.

  • Install the Arduino IDE 2.3.x (or PlatformIO if you prefer a real editor and dependency locking).
  • Add https://espressif.github.io/arduino-esp32/package_esp32_index.json under File → Preferences → Additional Board Manager URLs, then install esp32 from the Boards Manager.
  • Set the correct port under Tools → Port. On Linux add yourself to the dialout group: sudo usermod -aG dialout $USER and log out and back in.
  • Open the Serial Monitor at 115200 baud — every sketch here logs its state there.
  • Keep File → Preferences → Show verbose output during: compilation switched on while you are debugging build errors.

Required libraries

LibraryWhy it is neededInstall
WiFi (ESP32 core) bundledStation/AP connection management for the ESP32.Bundled with the ESP32 Arduino core
MPU6050_light / Adafruit MPU6050 1.3.xIMU register access, calibration and complementary-filter angles.Library Manager → "MPU6050_light" by rfetick
TinyGPSPlus 1.0.3Streaming NMEA parser producing latitude, longitude, speed and time.Library Manager → "TinyGPSPlus" by Mikal Hart
PubSubClient 2.8Lightweight MQTT 3.1.1 client for constrained devices.Library Manager → "PubSubClient" by Nick O'Leary
Preferences (NVS) bundledWear-levelled key/value storage in ESP32 flash for settings.Bundled with the ESP32 core
FreeRTOS (ESP-IDF) bundledTask scheduling so networking never blocks sensor sampling.Bundled with the ESP32 core

Block Diagram

The block diagram shows the functional decomposition of the system — what senses, what decides, what acts, and where the data ends up.

Two-Wheeler Anti-Theft GPS — system block diagramFunctional block diagram of the Two-Wheeler Anti-Theft GPS system. Parked (armed)Deep sleepultra-low powerAccel INTwake on motionClassifyTamper?lift/tilt/wheelReject nudgewind/passer-byAlarm + alertLocal alarmdeterrentOwner alertinstantTrackLive GPSif takenRecovervia policerightrightnone
Two-Wheeler Anti-Theft GPS — system block diagram

Circuit Diagram & Wiring

Every signal line in the build is shown below, followed by a pin-by-pin connection table you can work through with a multimeter in hand.

Two-Wheeler Anti-Theft GPS — wiring schematicConnection schematic showing which controller pin drives each peripheral. Sensors / InputsControllerActuators / OutputsESP32 DevKit V1(ESP-WROOM-32)3.3 V logic / 5 V USBAccelerometerGPIO 21/22Motion/tiltAccel INT (wake)GPIO 33 (RTC)Wake-on-motionGPSGPIO 26/25LocationCellular modemGPIO 27/14Alert/trackAlarm/buzzerGPIO 2Local deterrentBatteryBATPowerBike chargereg+cutoffTrickle charge
Two-Wheeler Anti-Theft GPS — wiring schematic
PeripheralPeripheral pinController pinSignal
AccelerometerSDA/SCLGPIO 21/22Motion/tilt
Accel INT (wake)INTGPIO 33 (RTC)Wake-on-motion
GPSTX/RXGPIO 26/25Location
Cellular modemUARTGPIO 27/14Alert/track
Alarm/buzzerINGPIO 2Local deterrent
Battery+BATPower
Bike charge12Vreg+cutoffTrickle charge

Wire one row at a time and tick it off — most "it does not work" reports trace back to a single swapped pair.

Wiring explanation

  • Wire the accelerometer's motion interrupt to an RTC-capable GPIO so it can wake the ESP32 from deep sleep.
  • Add GPS and a cellular modem for location and alerting.
  • Add a loud local alarm as a deterrent.
  • Charge from the bike through a regulator with a cutoff; the battery must ride through when parked/off.
  • Install hidden and tamper-resistant — a thief must not be able to find and pull the unit off easily.
An ESP32 development board with the ESP-WROOM-32 module and USB connector
The accelerometer wakes the sleeping ESP32 only on motion, so a small battery lasts through days of parking. Photograph sourced from Wikimedia Commons — ESP32 Espressif ESP-WROOM-32 Dev Board.jpg. Reused under the licence stated on that page; please check it before republishing.

System Architecture

Read the stack from the bottom up: physical hardware, the firmware that drives it, the transport that moves data off the device, and the software a human actually looks at.

Two-Wheeler Anti-Theft GPS — architecture stackLayered architecture from hardware to user interface. Hardware layerESP32 DevKit V1 (ESP-WROOM-32) · MPU-6050 6-axis IMU · u-blox NEO-6M GPSmodule + ceramic patch antennaDriver layerwifi · mpu · tinygps · pubsubApplication logicsampling loop · filtering · thresholds · state machineTransport layerCellular → owner app + tracking platform · TLS · retry and backoffPresentation layerdashboard · mobile notifications · historical charts
Two-Wheeler Anti-Theft GPS — architecture stack

Working Principle

A theft is not a single instant but a timeline — the bike is approached and tampered with, then taken, then moved away — and an effective anti-theft device intervenes at every stage of it. Tamper detection deters and warns at the start; a loud alarm and an instant alert can stop the theft before it completes; and live tracking gives a chance of recovery if it does. Covering the whole timeline, rather than just one stage, is what makes the difference for a vehicle as easy to steal and as hard to recover as a two-wheeler.

The heart of it is motion-based tamper detection, and its central engineering problem is discrimination. An accelerometer on a parked bike sees the theft signatures — being lifted off the stand, tilted, wheeled, knocked, or started — but it also sees harmless motion: wind, a passer-by brushing past, a neighbouring vehicle. If the device alarms on every nudge, the owner disables it and thieves learn to ignore it; if it is too deaf, it misses the theft. So it classifies motion by pattern, magnitude and persistence — a sustained lift or a continued wheeling is theft, a single small jolt is a nudge — to alarm on real tampering while rejecting the noise. That discrimination is what keeps the alarm credible.

On a genuine event the device acts on two fronts simultaneously. It sounds a local alarm — a deterrent that often ends the attempt, since a thief wants a quiet, quick job — and it sends the owner an instant remote alert over cellular, because the owner may be nearby and able to intervene, or to call the police immediately. Then it escalates: if motion continues and the bike is actually being taken, it switches from alarming to live GPS tracking, streaming location so the bike can be followed and recovered. This escalation — nudge tolerated, tamper alarmed and alerted, removal tracked — matches the response to the threat.

Making all this work on a hidden device on a parked, engine-off vehicle imposes two hard constraints that shape the design. First, power: the device may sit armed for days, so it lives in ultra-low-power sleep, drawing almost nothing, and is woken by the accelerometer's motion interrupt only when something actually moves — this "sleep until moved" architecture is what lets a small battery last, and it means the accelerometer, not a polling loop, is the trigger. Second, tamper resistance: a tracker a thief can find and rip off in seconds is useless, so the unit is hidden and mounted to resist quick removal, ideally alerting the moment it is interfered with. The design is honest about the limits — no tracker guarantees recovery, a determined thief may locate and disable a unit or jam signals, and recovery should be pursued through the police, not by the owner confronting thieves. Within those honest bounds, it does what two-wheeler security most needs: make an easy, untraceable target into one that is noisy when touched and followable if taken.

The maths behind it

Tamper vs nudge classification

plainTamper vs nudge classification
From accelerometer magnitude a and tilt θ over a window:

  jolt      = |a − 1g| > A_jolt            (a knock)
  lift/tilt = |θ − θ_park| > θ_thr          (moved off stand)
  motion    = jolts/tilt SUSTAINED > t_persist

  tamper if (lift/tilt) OR sustained motion
  nudge  if a single brief jolt only  → ignore

Discrimination keeps the alarm credible.

Escalation

plainEscalation
nudge         → stay armed (no alarm)
tamper        → LOCAL ALARM + instant owner alert
sustained/    → also LIVE GPS TRACKING (being taken)
  removal

Response matched to threat stage.

Ultra-low-power arm

plainUltra-low-power arm
Armed & parked:
  deep sleep (µA-scale), accel INT wired to RTC GPIO
  motion interrupt → WAKE → classify
  no theft → back to sleep

"Sleep until moved" makes a small battery last days.

Program Flowchart

The firmware is a single cooperative loop. Nothing blocks for long, so networking, sensing and the user interface all stay responsive.

Two-Wheeler Anti-Theft GPS — firmware flowchartControl flow through the main program loop. Parked + armed: deep sleepMotion wake (accel INT)Real tamper (not a nudge)?Alarm + instant owner alertBack to sleepBack to sleepAlarm + instant owner alertMotion sustained (beingtaken)?Live GPS trackingRe-arm after quietLive GPS trackingRe-arm after quiet
Two-Wheeler Anti-Theft GPS — firmware flowchart

Assembly Instructions

Build on a breadboard first and only commit to solder once the whole system has run for an hour without a fault.

  1. Wire the wake-on-motion core

    Connect the accelerometer with its motion interrupt to an RTC-capable GPIO so it wakes the ESP32 from deep sleep; add GPS, cellular and a loud alarm.

    Charge from the bike via a regulator with a cutoff so the battery rides through when parked.

  2. Tune tamper vs nudge

    Calibrate the parked orientation and thresholds so a real lift/wheel/knock alarms while wind and passers-by do not.

  3. Set escalation and alerting

    Configure alarm + instant alert on tamper, and live tracking on sustained motion; verify low-power sleep and wake.

Step-by-Step Implementation Guide

Work through these in order. Each step ends in something you can observe, so a failure is always localised to the step you just finished.

  1. Classify motion: tamper or nudge

    On a motion wake, classify the event — a sustained lift/tilt/wheeling is tampering; a single brief jolt is a harmless nudge to ignore.

    cpptamper.ino
    #define A_JOLT   0.30f     // g deviation = a knock
    #define TILT_THR 15.0f     // deg off parked orientation
    #define PERSIST_MS 1500    // sustained motion => real tamper
    
    float parkedTilt = 0;      // learned when armed
    
    // Returns: 0 none, 1 nudge, 2 tamper
    int classifyMotion(){
      uint32_t start = millis(); int jolts = 0; float maxTilt = 0;
      while (millis() - start < PERSIST_MS){
        float a = accelMagnitude();          // g
        float tilt = fabsf(currentTilt() - parkedTilt);
        if (fabsf(a - 1.0f) > A_JOLT) jolts++;
        if (tilt > maxTilt) maxTilt = tilt;
        delay(50);
      }
      if (maxTilt > TILT_THR) return 2;        // lifted/tilted off stand -> tamper
      if (jolts >= 6)          return 2;        // sustained knocking -> tamper
      if (jolts >= 1)          return 1;        // a single/brief jolt -> nudge
      return 0;
    }
    while (millis() - start < PERSIST_MS){Motion is judged over a persistence window — sustained motion is theft, a momentary blip is not — which is what rejects false alarms.
    if (maxTilt > TILT_THR) return 2; // lifted/tilted off stand -> tamperA change in tilt from the learned parked orientation means the bike was lifted or moved off its stand — a strong theft signature.
    if (jolts >= 6) return 2; // sustained knocking -> tamperRepeated jolts indicate active tampering (wheeling, forcing), escalated to a tamper event.
    if (jolts >= 1) return 1; // a single/brief jolt -> nudgeA single brief jolt (wind, a passer-by) is classified as a harmless nudge and does not trigger the alarm, keeping it credible.
  2. Alarm, alert and escalate to tracking

    On a tamper, sound the alarm and alert the owner instantly; if motion continues (the bike is being taken), switch to live GPS tracking.

Complete Source Code

The listing below is complete and compiles as written — there are no elided sections. Read the annotations under each block before you upload it.

cppantitheft-tracker.ino
/* ═══════════════════════════════════════════════════════════════
   Two-Wheeler Anti-Theft GPS Tracker — ESP32

   Armed & parked: deep sleep, woken by the accelerometer's motion
   interrupt. Classifies tamper vs nudge; on tamper sounds a local alarm
   and alerts the owner instantly; if the bike is taken, tracks it live.
   Hidden, tamper-resistant, ultra-low-power. Recover via the police.
   ══════════════════════════════════════════════════════════════════ */

#include "esp_sleep.h"
#include <TinyGPS++.h>

#define ACCEL_INT_GPIO GPIO_NUM_33      // RTC-capable: wakes from deep sleep
#define TRACK_PERSIST_MS 4000           // sustained motion => being taken

RTC_DATA_ATTR bool armed = true;
TinyGPSPlus gps; HardwareSerial gpsSer(2);

void armAndSleep(){
  configureAccelWakeInterrupt();        // accel INT on motion
  esp_sleep_enable_ext0_wakeup(ACCEL_INT_GPIO, 1);
  esp_deep_sleep_start();               // µA sleep until MOVED
}

void alarm(bool on){ digitalWrite(2, on); }       // local deterrent
void alertOwner(const char* what){
  cellularSend("bike/alert", what);     // instant remote alert
}
void trackLive(){
  while (motionContinues()){            // being taken -> stream location
    while (gpsSer.available()) gps.encode(gpsSer.read());
    char m[128];
    snprintf(m,sizeof m,"{\"lat\":%.6f,\"lon\":%.6f}",
             gps.location.lat(), gps.location.lng());
    cellularSend("bike/track", m);      // owner/police can follow
    delay(5000);
  }
}

void setup(){
  Serial.begin(115200);
  gpsSer.begin(9600, SERIAL_8N1, 26, 25);
  pinMode(2, OUTPUT);
  accelInit(); learnParkedOrientation();

  if (esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_EXT0){
    int m = classifyMotion();           // 0 none, 1 nudge, 2 tamper
    if (m == 2){
      alarm(true);
      alertOwner("TAMPER on your bike");         // alarm + instant alert
      if (motionSustained(TRACK_PERSIST_MS)){     // actually being taken
        alertOwner("Bike being MOVED - tracking");
        trackLive();                              // live GPS tracking
      }
      alarm(false);
    }
    // nudge or none -> just re-arm
  }
  if (armed) armAndSleep();             // back to ultra-low-power sleep
}

void loop(){}                          // all work is wake-driven
esp_sleep_enable_ext0_wakeup(ACCEL_INT_GPIO, 1);The accelerometer's motion interrupt wakes the ESP32 from deep sleep, so the device draws almost nothing until the bike is actually moved — the key to battery life.
int m = classifyMotion(); // 0 none, 1 nudge, 2 tamperEvery wake is classified, so harmless nudges are dismissed and only real tampering triggers a response — keeping the alarm credible.
alarm(true); alertOwner("TAMPER on your bike"); // alarm + instant alertOn a real tamper the device deters locally and alerts the owner instantly — acting on both fronts at the start of the theft.
if (motionSustained(TRACK_PERSIST_MS)){ // actually being takenEscalation: only when motion is sustained (the bike is being taken) does it switch to live tracking — matching response to threat.
trackLive(); // live GPS trackingIf the bike is taken, it streams live location so the owner and police can follow and recover it.

Configuration & Calibration

Configuration steps

  • Configure the accelerometer wake interrupt and parked-orientation learning.
  • Configure tamper vs nudge thresholds (jolt, tilt, persistence).
  • Configure alarm, instant alert, and the sustained-motion tracking trigger.
  • Configure GPS/cellular and low-power sleep behaviour.

Calibration procedure

An uncalibrated sensor produces confident, precise, wrong numbers. Do this once per physical unit and record the constants.

  1. Tamper thresholds

    Tune jolt/tilt/persistence so lifting, wheeling and knocking alarm while wind and passers-by do not.

  2. Power

    Verify deep-sleep current and reliable wake-on-motion; confirm battery life meets the parked duration.

  3. Tracking

    Confirm GPS fix time and cellular streaming once tracking starts.

Network Architecture & Connectivity

Two-Wheeler Anti-Theft GPS — network topologyPath taken by telemetry from field node to end user. Edge nodesGatewayCloudClientsBike trackerESP32Other bikesfleetCellularCarrierto platformMQTT/HTTPSTracking platformalerts + live locationOwnerapp alerts/trackPolicerecovery (lawful)
Two-Wheeler Anti-Theft GPS — network topology

Communication protocol

The tracker sends instant tamper alerts and, if the bike is taken, streams live location; it sleeps otherwise to save battery.

Topic / endpointDirectionPayload
bike/<id>/alerttracker → ownertamper / being-moved
bike/<id>/tracktracker → owner/policelive location
bike/<id>/healthtracker → platformbattery, armed, signal

Message contract between the device and the broker.

Cloud platform configuration

A platform delivers instant alerts and live tracking to the owner, and supports lawful, police-led recovery.

Dashboard setup

Owner app: armed status, tamper alerts, live map when taken, and device health.

Mobile app integration

Instant tamper alerts and a live recovery map; arm/disarm.

Security considerations

  • Hidden, tamper-resistant install; authenticate the tracker.
  • Recovery is lawful and police-led — not owner confrontation.
  • Location data is sensitive — secure it and restrict access to the owner.

Testing Procedure & Expected Output

Test from the bottom up. Confirm power, then each sensor in isolation, then the integrated loop — the first failing step tells you exactly where to look.

TestWhat you should see
Nudge the parked bike lightlyClassified as nudge — no alarm (credible)
Lift it off the standTamper: alarm + instant owner alert
Wheel it awaySustained motion → live GPS tracking
Leave armed for a dayDeep sleep holds battery; wakes on motion
Try to find/remove the unitHidden; interference alerts
Recover scenarioLive location shared for police-led recovery

Bench-test checklist. If a row fails, stop and fix it before moving on.

Expected output

Instant tamper alerts, a local alarm, and live location if the bike is taken.

jsonbike-alert.json
{
  "event": "tamper",
  "escalation": "being-moved",
  "alarm": true,
  "lat": 19.0760,
  "lon": 72.8777,
  "battery": "ok"
}

A tamper that escalated to the bike being moved: the alarm sounded, the owner was alerted instantly, and live location began streaming for a police-led recovery.

An 18650 lithium-ion cell
If the bike is taken, live GPS location streams to the owner and police for a lawful recovery. Photograph sourced from Wikimedia Commons — 18650 Li-ion battery.jpg. Reused under the licence stated on that page; please check it before republishing.

Troubleshooting: Common Errors & Fixes

Alarms on every nudge

Likely cause. Thresholds too sensitive

Fix. Require sustained motion/tilt; reject single brief jolts

Misses a real theft

Likely cause. Thresholds too deaf

Fix. Lower tilt/persistence thresholds; test lifting/wheeling

Battery dies while parked

Likely cause. Not truly sleeping

Fix. Deep sleep with accel-interrupt wake; measure µA current

Thief finds/removes unit

Likely cause. Poor concealment

Fix. Hide better; tamper-resistant mount; alert on interference

No fix when tracking

Likely cause. GPS cold start/coverage

Fix. Allow fix time; keep antenna clear; use cellular-assisted location

The sketch will not upload — "Failed to connect" or "avrdude: stk500_recv()"

Likely cause. The bootloader is not being reached: wrong port, wrong board, a serial monitor holding the port open, or a USB cable that only carries power.

Fix. Close every serial monitor, confirm Tools → Board and Port, and swap to a known data-capable USB cable. On an ESP32 hold BOOT while the IDE prints "Connecting…", then release. If a peripheral is wired to the UART pins (GPIO 1/3 on ESP32, D0/D1 on Uno) unplug it — it fights the programmer.

The board resets in a loop, or the serial monitor prints "Brownout detector was triggered"

Likely cause. The supply cannot deliver peak current. Wi-Fi transmit bursts, relay coils and servos all pull far more than their average draw.

Fix. Power peripherals from a separate regulated supply with a common ground rather than from the board 5 V pin. Add a 470–1000 µF electrolytic capacitor across the supply near the load, and use a real power adapter rather than a laptop USB port.

Serial monitor shows garbage characters

Likely cause. Baud rate mismatch between Serial.begin() and the monitor, or a floating/shared UART line.

Fix. Set the monitor to 115200 to match the sketch. If it still garbles, the crystal or the USB bridge is being confused by noise — shorten the cable and keep motor wiring away from the USB lead.

An I²C device is not detected

Likely cause. Wrong address, missing pull-ups, swapped SDA/SCL, or a bus too long for the pull-up value.

Fix. Run an I²C scanner sketch first — it should print the device address. Most breakout boards include 4.7 kΩ pull-ups, but if you have chained four of them the parallel resistance is too low; remove the pull-ups from all but one board. Keep the bus under 30 cm at 100 kHz.

Wi-Fi connects but MQTT never does (state -2)

Likely cause. Wrong broker address or port, a firewall in the way, or the broker requiring credentials the sketch is not sending.

Fix. Test from a laptop on the same network first: mosquitto_sub -h <broker> -t "#" -v. If that works, the problem is on the device — check the IP literal, port 1883 (or 8883 for TLS), and that client.setServer() runs before connect(). PubSubClient state codes are documented in its header.

Readings arrive for a while and then stop

Likely cause. The Wi-Fi or MQTT session dropped and the sketch never reconnects, or the broker dropped the client on keep-alive timeout.

Fix. Never assume the link stays up. Check WiFi.status() and client.connected() at the top of every loop and reconnect with exponential backoff. Add a watchdog so a wedged network stack reboots the device instead of going silent.

Performance Optimisation

  • Ultra-low-power sleep with accelerometer wake for long parked life.
  • Classify tamper vs nudge to keep the alarm credible.
  • Escalate: alarm/alert on tamper, live-track only if taken.
  • Fast, reliable location once tracking starts.
  • Replace every delay() with a millis() comparison — blocking delays are the single most common cause of dropped readings.
  • Sample sensors on a fixed cadence and publish on a slower one; you almost never need to transmit at the sampling rate.
  • Move networking into its own FreeRTOS task so a slow DNS lookup cannot stall the control loop.
  • Use uint8_t / uint16_t where the range allows; on an 8-bit AVR a 32-bit add costs four times as much.
  • Batch several samples into one MQTT publish. Radio time, not CPU time, dominates the energy budget.
  • Set the MQTT keep-alive to a value that matches your reporting interval so the broker does not churn reconnections.
  • For battery builds use deep sleep between samples: an ESP32 drops from ~160 mA awake to about 10 µA asleep, which is the difference between days and months of runtime.

Safety Precautions

  • No tracker guarantees recovery — treat it as deterrence and a recovery aid, not a certainty.
  • Recovery must be lawful and police-led; never confront thieves yourself.
  • Install charging from the bike safely (regulator + cutoff); avoid fire/short risks.
  • Location data is sensitive personal data — secure it and restrict it to the owner.
  • Lithium cells vent and burn when abused. Only use protected cells or a proper BMS, never charge below 0 °C, and never leave a charging pack unattended on a wooden desk.
  • Never power an RF module without its antenna fitted — the reflected power destroys the output stage. Check your local licence-free band and duty-cycle limits before transmitting.
  • Wear eye protection when soldering or cutting, and solder in a ventilated space — rosin flux fumes are a respiratory irritant.
  • Power the circuit through a bench supply with a current limit while you are testing. A 300 mA limit turns a wiring mistake into a beep instead of a dead board.
  • Disconnect power before changing any wiring. Hot-plugging a sensor onto a live bus is the fastest way to lose a controller.

Maintenance

  • Check battery health and deep-sleep current periodically.
  • Re-verify tamper thresholds after re-mounting.
  • Confirm GPS/cellular coverage in usual parking spots.
  • Keep the install hidden and tamper-resistant after servicing.
  • Re-check every screw terminal and header after the first week — thermal cycling loosens connections that felt tight on day one.
  • Log pack voltage. When resting voltage after a full charge drops below about 4.0 V, the cell is near end of life — replace it.
  • Keep the broker and dashboard containers patched, and rotate device credentials at least once a year.
  • Recalibrate at the interval given in the calibration section, and keep the constants in a text file next to the firmware — not only in flash.
  • Keep a short logbook of firmware versions and what changed. Six months later you will not remember why that constant is 1.083.

Future Improvements & Upgrades

A working v1 is a platform, not a finish line. These are the upgrades that add the most capability for the least rework.

  • Add geofencing (alert if the bike leaves a zone).
  • Add remote immobilisation (lawfully and safely engineered).
  • Add BLE owner-presence auto-arm/disarm.
  • Add crash/fall detection and emergency alerting.
  • Design a proper PCB. Once the breadboard version has run for a month, moving to a two-layer board removes the intermittent-contact failures that dominate prototype faults.
  • Add over-the-air firmware updates so you never have to physically reach a deployed node again.
  • Add persistent local storage (microSD or the on-chip flash) so a network outage does not create a hole in your data.
  • Move configuration out of the source: a captive-portal setup page or a JSON config file makes the build reusable without a recompile.
  • Add a battery and solar option so the unit survives a power cut and can be sited away from a socket.
  • Write a small test harness that feeds synthetic sensor values through the decision logic, so you can validate thresholds without physically triggering the event.

Frequently Asked Questions

How does it avoid false alarms?

It classifies motion by pattern and persistence — a sustained lift, tilt off the stand, or continued wheeling is tampering, while a single brief jolt from wind or a passer-by is a nudge it ignores. A credible alarm is one that does not cry wolf.

How does it last on battery while parked?

It spends almost all its time in ultra-low-power deep sleep and is woken by the accelerometer's motion interrupt only when the bike actually moves. "Sleep until moved" is what makes a small battery last days.

What happens if the bike is actually stolen?

It escalates from alarm-and-alert to live GPS tracking, streaming location so the owner and police can follow and recover it.

Can a thief just remove it?

It is installed hidden and tamper-resistant so it is hard to find and pull off quickly, and it can alert the moment it is interfered with — but no tracker is invincible, which is why it deters, alarms and tracks rather than relying on any one defence.

Should I chase down my stolen bike?

No. Recovery should be lawful and police-led — share the live location with the police. The tracker's job is to give them what they need, not to send you into a confrontation.

References & Learning Resources

These are the primary sources worth reading in full. Manufacturer datasheets always outrank forum posts when the two disagree.

  1. Vehicle tracking systemReference
  2. Motorcycle theftReference
  3. AccelerometerReference
  4. ESP32 deep sleep / wake sourcesEspressif
  5. GPSReference