The mecanum robot
Four mecanum wheels: it drives forward, slides sideways and spins, all at the same time. Everything for the robotics club lives here, and it all works from a phone.
The ten lessons
- Robot or Not? - what makes a machine a robot
- Same Job, Different Physics - laser, sonar and infrared
- Did It Actually Turn? - open loop vs closed loop
- Every Robot Is Different - measuring your own robot's numbers
- Sideways Is a Direction - mecanum wheels and adding arrows
- Too Much, Too Little, Just Right - tuning the line follower
- Roll Call on Two Wires - I2C buses and addresses
- When in Doubt, Stop - a robot that fails safely
- Robots Go Wrong - debugging like an engineer
- The 32 KB Backpack - engineering is choosing
Wiring at a glance
The L293D motor shield sits on the Uno and owns pins 3, 4, 5, 6, 7, 8, 11 and 12. Everything else plugs in here. The robot finds the optional parts by itself at start-up.
| Pin | What | Notes |
|---|---|---|
| A0 / A1 | HC-06 Bluetooth | As the kit ships. The app and the sticks talk to it. |
| A2 / A3 | HC-SR04 sonar (echo / trig) | Used only while no sensor is wired straight to A2 / A3. |
| A4 / A5 | I2C (SDA / SCL) | IMU, laser and ADS1115 boards, see below. |
| D2 | IR remote receiver (S) | Middle pin to 5V, "-" to GND. D2 has no header on the shield: solder to its pin. |
| D9 / D10 | Servo headers | Free digital pins (no PWM: Timer1 times the IR remote). |
| D13 | Heartbeat LED | Free if you set USE_HEARTBEAT 0. |
On the I2C bus (A4 / A5)
Give every board 5V into its VIN. The 3.3V boards (IMU, laser) go through a BSS138 level shifter: HV 5V, LV 3.3V, SDA and SCL on two of its channels.
| Address | Board | Notes |
|---|---|---|
| 0x68 | MPU-6050 (GY-521) | Heading hold. Keep the robot still for a second at power-on. |
| 0x28 | or BNO055 | ADD to GND (the cheap boards default to 0x29). PS0 and PS1 must read 0 V for I2C mode. |
| 0x29 | VL53L0X laser | Distance ahead, wall stop at 120 mm. Peel the film off the window. |
| 0x48-0x4A | ADS1115 x3 | ADDR to GND / VDD / SDA. 8 line sensor channels and the light sensors. Powered from 5V. |
The IR remote
| arrows | Hold to drive forward / back / slide left / slide right. Let go and it stops. |
| 1 / 3 | Hold to spin left / right |
| OK, 5 | Stop. Any key stops a running demo. |
| 4 / 6 | Slower / faster |
| 9 | Circle strafe facing in (the one built-in demo; programs do the rest) |
| * / # | Follow the line / seek the light |
Fitting it all in
The Uno has 32 KB for the sketch, and the default build uses about 32.2 KB.
Calibration runs live in a separate program, calibration.ino,
which saves its numbers in the robot's EEPROM for this one to read.
Every optional part is a USE_... line at the top of the sketch:
1 = in, 0 = out. Lesson 10
turns this into a challenge.
| Flag | Part | Flash |
|---|---|---|
| USE_IMU | MPU-6050 / BNO055 heading hold | 1.9 KB |
| USE_TOF | VL53L0X laser | 1.3 KB |
| USE_IR_REMOTE | IR remote on D2 | 0.8 KB |
| USE_ADS1115 | ADS1115 inputs | 0.35 KB |
| USE_SONAR | HC-SR04 on A2 / A3 | 0.3 KB |
| USE_ANALOG_MUX | 74HC4051 multiplexer (off by default) | 0.34 KB |
| USE_EXTRA_DEMOS | 20 more demos (off; fits with USE_IR_REMOTE 0) | 0.75 KB |