Introduction: Controlling LEGO Tank by ESP8266 With Scratch or RoboRemo

I'd like to use wireless control to LEGO motors without expensive and huge Mindstorms brick for a long time ago. After some software and hardware development, I success: my LEGO tank works!

It's a description how a custom LEGO tank can be built and can be controlled by ESP8266. ESP8266 can be controlled by MIT Scratch 2 or RoboRemo. One ESP8266 controls the tank chassis, another ESP8266 controls the tank tower. There are several ESP8266 boards, WeMos D1 mini was selected. The tank tower uses an ultrasonic sensor to report distance (HC-SR04). H-bridges are cheap L9110S.

Software part is described at ESP4S2 (including Scratch and RoboRemo usage examples).

Step 1: Building a Custom LEGO Tank

The first step is making a custom LEGO tank, see pictures. Electronic parts are marked by transparent light blue color. Other design is also possible.

Step 2: Preparing LEGO Connectors

LEGO uses own connectors to LEGO motors. In order to control LEGO motors by a microcontroller, custom connector should be prepared (harmless) or the connector of LEGO motor (harmful) should be prepared. Because of small spaces of the design, I cut the cable of LEGO motors and soldered jumper cables (only yellow and green cables are required).

Step 3: Pinout Plan for ESP8266

WeMos D1 mini has some additional resistors and dedicated pins for shields, see schematic diagram. These constraints determine a logical pinout:

| ESP-8266 Pin | Pin | WeMos Function  |     Function     |
| A0           | A0  | Analog input,   | Analog input     |
|              |     | max 3.3V input  |                  |
| GPIO16       | D0  | IO              | HC-SR04 Trig     |
| GPIO5        | D1  | IO, SCL         | I2C for shields  |
| GPIO4        | D2  | IO, SDA         | I2C for shields  |
| GPIO0        | D3  | IO, 10k Pull-up | H-bridge B2      |
| GPIO2        | D4  | IO, BUILTIN_LED | Blue LED         |
|              |     | 10k Pull-up     | DHT Data         |
| GPIO14       | D5  | IO, SCK         | H-bridge A1      |
| GPIO12       | D6  | IO, MISO        | H-bridge A2      |
| GPIO13       | D7  | IO, MOSI        | H-bridge B1      |
| GPIO15       | D8  | IO, SS          | HC-SR04 Echo     |
|              |     | 10k Pull-down   | + 4k7: 5V-->3.3V |
|              |     |                 | voltage divider  |

D8 pin works well with Pololu DRV8833 as B2 input, but activates motor B with cheap L9110 at power on. D3 works well with cheap L9110. I2C pins are used by WeMos shields OLED and Motor.
HC-SR04 needs 5V power, Echo pin output is 5V, too (3.3V input is good for Trig). A 4k7 with built-in 10k Pull-down resistor behave as a voltage divider, see: HC-SR04 Ultrasonic Range Sensor on the Raspberry Pi. Pin D4 is used by WeMos shields DHT and DHT Pro.

Step 4: Wiring ESP8266 for Tank Chassis

Pins should be soldered tricky on ESP8266, to use serial pins, see 1st picture. Any 3.3V USB-serial adapter can be used. ESP8266 should be flashed on USB port before attaching to the breadboard. ESP8266 is wired on a small bread board. WeMos D1 mini has a built-in voltage regulator, so external voltage regulator is not required. Third picture shows running it from external power for debugging.

Step 5: Wiring Tank Chassis

A custom main switch can be tinkered, which can be attached on the front of tank. Seven AAA battery are grouped to one 3x and one 4x battery holder in the front of tank chassis.

Step 6: Wiring ESP8266 for Tank Tower

For connecting WeMos OLED display on the top of WeMos D1 mini in the future, male-female pins are soldered on ESP8266. Main switch should be prepared (pins should be removed), see 5th picture. The 4.7K resistor wiring can be seen on 1st picture. External step-down converter is used to get 5V (Mini-360/LM2596s, I think). The main switch is a small button. For running it from external power, main switch should be removed and substituted by a jumper cable, see the 4th picture. Five AAA battery are grouped to one 3x and one 2x battery holder on the top of tank tower. Battey holders are glued each other by glue gun.

Step 7: Integration

Using some cords, tapes and patience, whole things can be assembled. ESP8266 consumes a lot power, so external power should be used during software integration, see picture. Software, including firmware, scripts, examples are described at ESP4S2.

Step 8: Play

It is the best step: switch the tank on and play!


Circuits Contest 2016

Participated in the
Circuits Contest 2016