ESP8266 - Car

One of the coolest things to try if you're just starting with ESP8266 is making a robot car. In this guide, we'll learn how to use ESP8266 to build a robot car and control it with a IR remote control. We'll learn how to make a Bluetooth robot car in another tutorial.

IR remote control car

Hardware Preparation

1×ESP8266 NodeMCU ESP-12F
1×Alternatively, ESP8266 D1 Mini NodeMCU ESP-12F
1×Micro USB Cable
1×Alternatively, ESP8266 NodeMCU ESP-12E (Uno-form)
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×RC Car
1×L9110S Motor Driver Module
1×IR Remote Controller Kit
1×CR2025 Battery (for IR Remote controller)
1×1.5V AA Battery (for ESP8266 and Car)
1×Jumper Wires
1×Breadboard
1×Recommended: Screw Terminal Expansion Board for ESP8266

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of Robot Car

In the ESP8266 context, the robot car is often called by different names like robot car, RC car, remote control car, smart car, or DIY car. It can be controlled from a distance without any wires. You can use either a special remote control that uses infrared light or a smartphone app through Bluetooth or WiFi. The robot car can go left or right and also go forward or backward.

A 2WD (Two-Wheel Drive) car for ESP8266 is a small robotic vehicle that you can build and control using an ESP8266 board. It typically consists of the following components:

  • Chassis: The base or frame of the car,where all other components are mounted.
  • Wheels: The two wheels that provide locomotion to the car. They are attached to two DC motor.
  • Motors: Two DC motors are used to drive the two wheels.
  • Motor Driver: The motor driver board is an essential component that interfaces between the ESP8266 and the motors. It takes signals from the ESP8266 and provides the necessary power and control to the motors.
  • ESP8266 Board: The brain of the car. It reads inputs from sensors and user commands and controls the motors accordingly.
  • Power Source: The 2WD car requires a power source, usually batteries and a battery holder, to power the motors and the ESP8266 board.
  • Wireless receiver: an infrared, Bluetooth or WiFi module for wireless communication with a remote control or smartphone.
  • Optional Components: Depending on your project's complexity, you may add various optional components like sensors (e.g., ultrasonic sensors for obstacle avoidance, line-following sensors), and more.

In this tutorial, to make it simple, we will use:

  • 2WD Car kit (including Chassis, wheels, motors, battery holder)
  • L9110S Motor Driver
  • IR infrared kit (including IR controller and IR receiver)

Check the hardware list at the top of this page.

How It Works

ESP8266 NodeMCU 2WD car how it work
  • ESP8266 connects to the DC motors of the robot car through L9110S motor driver module.
  • ESP8266 connects to an IR receiver.
  • The battery powers ESP8266, DC motors, motor driver, and IR receiver.
  • Users press the UP/DOWN/LEFT/RIGHT/OK keys on the IR remote controller.
  • ESP8266 receives the UP/DOWN/LEFT/RIGHT/OK commands through the IR receiver.
  • ESP8266 controls the car to move FORWARD/BACKWARD/LEFT/RIGHT/STOP by controlling the DC motor via the motor driver.

Wiring Diagram

The wiring diagram between ESP8266 NodeMCU and 2WD car

This image is created using Fritzing. Click to enlarge image

See more in ESP8266's pinout and how to supply power to the ESP8266 and other components.

The L9110S module powers the motors directly from its VCC and GND pins and does not have an onboard 5V regulator. This means you can power everything from a single power source — four 1.5V AA batteries (totaling 6V). Here's how to do it:

  • Connect the 6V battery to the VCC and GND pins of the L9110S module to power the motors.
  • Connect the same 6V battery to the Vin and GND pins of the ESP8266 to power the ESP8266 board (the IR receiver is powered from the board's own supply).
  • Make sure the L9110S module, the ESP8266, and the IR receiver share a common GND.

Unlike the L298N, the L9110S has no ENA/ENB enable jumpers and no 12V screw terminal, so the wiring is simpler.

ESP8266 Code

/* * This ESP8266 NodeMCU code was developed by newbiely.com * * This ESP8266 NodeMCU code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp8266/esp8266-car */ #include <DIYables_IRcontroller.h> // DIYables_IRcontroller library #define IR_RECEIVER_PIN D1 // The ESP8266 pin connected to IR receiver #define MOTOR_A_IA_PIN D2 // The ESP8266 pin connected to the A-IA pin of the L9110S (Motor A) #define MOTOR_A_IB_PIN D5 // The ESP8266 pin connected to the A-IB pin of the L9110S (Motor A) #define MOTOR_B_IA_PIN D6 // The ESP8266 pin connected to the B-IA pin of the L9110S (Motor B) #define MOTOR_B_IB_PIN D7 // The ESP8266 pin connected to the B-IB pin of the L9110S (Motor B) DIYables_IRcontroller_17 irController(IR_RECEIVER_PIN, 200); // debounce time is 200ms void setup() { Serial.begin(9600); irController.begin(); pinMode(MOTOR_A_IA_PIN, OUTPUT); pinMode(MOTOR_A_IB_PIN, OUTPUT); pinMode(MOTOR_B_IA_PIN, OUTPUT); pinMode(MOTOR_B_IB_PIN, OUTPUT); } void loop() { Key17 key = irController.getKey(); if (key != Key17::NONE) { switch (key) { case Key17::KEY_UP: Serial.println("MOVING FORWARD"); CAR_moveForward(); break; case Key17::KEY_DOWN: Serial.println("MOVING BACKWARD"); CAR_moveBackward(); break; case Key17::KEY_LEFT: Serial.println("TURNING LEFT"); CAR_turnLeft(); break; case Key17::KEY_RIGHT: Serial.println("TURNING RIGHT"); CAR_turnRight(); break; case Key17::KEY_OK: Serial.println("STOP"); CAR_stop(); break; default: Serial.println("WARNING: unused key:"); break; } } } void CAR_moveForward() { digitalWrite(MOTOR_A_IA_PIN, HIGH); digitalWrite(MOTOR_A_IB_PIN, LOW); digitalWrite(MOTOR_B_IA_PIN, HIGH); digitalWrite(MOTOR_B_IB_PIN, LOW); } void CAR_moveBackward() { digitalWrite(MOTOR_A_IA_PIN, LOW); digitalWrite(MOTOR_A_IB_PIN, HIGH); digitalWrite(MOTOR_B_IA_PIN, LOW); digitalWrite(MOTOR_B_IB_PIN, HIGH); } void CAR_turnLeft() { digitalWrite(MOTOR_A_IA_PIN, HIGH); digitalWrite(MOTOR_A_IB_PIN, LOW); digitalWrite(MOTOR_B_IA_PIN, LOW); digitalWrite(MOTOR_B_IB_PIN, LOW); } void CAR_turnRight() { digitalWrite(MOTOR_A_IA_PIN, LOW); digitalWrite(MOTOR_A_IB_PIN, LOW); digitalWrite(MOTOR_B_IA_PIN, HIGH); digitalWrite(MOTOR_B_IB_PIN, LOW); } void CAR_stop() { digitalWrite(MOTOR_A_IA_PIN, LOW); digitalWrite(MOTOR_A_IB_PIN, LOW); digitalWrite(MOTOR_B_IA_PIN, LOW); digitalWrite(MOTOR_B_IB_PIN, LOW); }

Detailed Instructions

To get started with ESP8266 on Arduino IDE, follow these steps:

  • Check out the how to setup environment for ESP8266 on Arduino IDE tutorial if this is your first time using ESP8266.
  • Connect the ESP8266 board to your computer using a USB cable.
  • Open Arduino IDE on your computer.
  • Choose the correct ESP8266 board, such as (e.g. NodeMCU 1.0 (ESP-12E Module)), and its respective COM port.
  • Install DIYables_IRcontroller library on Arduino IDE by following this instruction
  • Do the wiring as the diagram shown above.
  • Disconnect the wire from the Vin on the ESP8266 because we will power ESP8266 via USB cable when uploading code.
  • Flip the car upside down so that the wheels are on top.
  • Copy the provided code and open it in the Arduino IDE.
  • Click the Upload button in the Arduino IDE to transfer the code to the ESP8266.
  • Use the IR remote controller to make the car go forward, backward, left, right, or stop.
  • Check if the wheels move correctly according to your commands.
  • If the wheels move the wrong way, swap the wires of the DC motor on the L9110S module.
  • You can also see the results on the Serial Monitor in the Arduino IDE.
Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Nodemcu 1.0 (ESP-12E Module)
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Nodemcu 1.0 (ESP-12E Module)' on 'COM15')
New Line
9600 baud
CAR - MOVING FORWARD CAR - MOVING BACKWARD CAR - TURNING LEFT CAR - TURNING RIGHT CAR - STOP
Ln 11, Col 1
Nodemcu 1.0 (ESP-12E Module) on COM15
2
  • If everything is going well, unplug the USB cable from the ESP8266, and then connect the wire back into the Vin 5V pin. This will give power to the ESP8266 from the battery.
  • Flip the car back to its normal position with the wheels on the ground.
  • Have fun controlling the car!

Code Explanation

Read the line-by-line explanation in comment lines of code!

You can learn more about the code by checking the following tutorials:

You can extend this project by:

  • Adding obstacle avoidance sensors to immidilately stop the car if an obstacle is detected.
  • Adding function to control the speed of car (see ESP8266 - DC motor tutorial). The provided code controls car with full speed.

Video Tutorial

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!