Build
Car
Four wheels, a distance sensor, and nowhere it will not go.
Everything in this build comes in the Big Kit: $159.
- 14-Port Motherboard×1
- USB-C×1
- DC Motor×4
- Distance Sensor×1
- Screen×1
- Button×1
Smart Home · Wi-Fi · Bluetooth
What it does
- 1Four motors, one in each wheel. The distance sensor at the front sees what is in the way and the car steers around it.
- 2The screen shows how far away the nearest thing is. The button starts and stops it.
How to build it
- 1Slide the DC motor into port 1.
- 2Slide the DC motor into port 6.
- 3Slide the DC motor into port 9.
- 4Slide the DC motor into port 14.
- 5Slide the distance sensor into port 7.
- 6Slide the screen into ports 3 and 4.
- 7Slide the button into port 11.
- 8Slide the USB-C into port 8 and plug the cable into your computer.
- 9Plug it in and press Upload to board.
Uploading works from Chrome or Edge on a computer. Open this page there with the board plugged in.
On the board
- 1DC MotorFront left wheel
- 6DC MotorRear left wheel
- 9DC MotorFront right wheel
- 14DC MotorRear right wheel
- 7Distance SensorLooks ahead
- 3+4ScreenDistance in cm and what it is doing
- 11ButtonTap: go / stop · hold: slow mode
- 8USB-CPower and programming
The code
car.cpp · 101 linesDownload
// Car — 14-port board, four DC motors (the kit car), Distance Sensor, Screen, Button.
// Tap the button = drive / stop. It drives forward; anything closer than 20 cm makes it stop, back up, turn right and carry on.
// Hold the button 1 s = slow mode on/off (half speed). The screen shows the distance in cm and what the car is doing.
#include <Arduino.h>
#include <Wire.h>
#include "modules/display/st7735_tft.h"
#include "modules/input/button.h"
#include "modules/motor/dc_motor.h"
#include "modules/distance/vl53l5cx.h"
ST7735_TFT screen(SCR_SCLK, SCR_CS, SCR_MOSI, SCR_DC);
ButtonModule button(BTN_SW);
VL53L5CX_Sensor distance(Wire);
DCMotor motors[4] = { {M1A, M1B}, {M2A, M2B}, {M3A, M3B}, {M4A, M4B} }; // left top, left bottom, right top, right bottom
const int MOTOR_SIGN[4] = { 1, 1, -1, -1 }; // right side faces the other way
static const int STOP_CM = 20; // closer than this = obstacle
static const uint32_t BACK_MS = 400; // reverse this long
static const uint32_t TURN_MS = 500; // then turn right this long
static const int FULL = 200; // forward speed (0..255)
enum State { READY, DRIVE, BACK, TURN };
State state = READY;
bool slow = false, sensorOk = false;
…




