How to Make a Simple IoT Car

code/arduino-c/iot-car/featured_image.jpg

Introduction

Gear up for an exciting venture into the world of remote-controlled RC cars! In this tutorial, we’ll guide you through the process of crafting your very own RC car that you can command over the internet using the Blynk app on your smartphone.

Prerequisites:

Tools

Components

NameSpecificationQuantity
NodeMCU board-1
RC Car kit4 Wheel1
Motor driverL298N1
Rocker switch-1
Lithium-ion battery18650 3.7V2
Dual 18650 battery holder-1
Dual 18650 battery charger-1
Jumper wiresF to F10
Jumper wiresM to M5
Multi-stand wires-1 Meter
Double tape-1
Screw driverM3 (3mm) Star1
Wire stripper - cutter (optional)-1

Arduino IDE:

  1. Download Arduino IDE software:

    • Visit the official Arduino website at www.arduino.cc/en/software
    • Click on the “Windows Installer” link to download the latest version of the Arduino IDE for Windows. This will typically be a .exe file.
  2. Run the Installer:

    • Locate the downloaded installer file and double-click on it to run it.
    • Follow the software’s recommended settings and click ‘Next’ for all the prompts.
  3. Driver Installation (if needed):

    • During the installation, you may be prompted to install drivers for certain Arduino boards (e.g., Arduino Uno). Follow the on-screen instructions to install the necessary drivers.
  4. Completing the Installation:

    • Once the installation is complete, you’ll see a “Completing the Arduino” window. Ensure that the “Launch Arduino” option is checked and click “Finish.”
  5. Additional Driver installation for ESP8266 boards:

    • Plug your NodeMCU board into a USB port on your computer using a suitable USB cable and open “Device manager” tool.
    • In the Device Manager, expand the “Ports (COM & LPT)” section and look for device entry that has warning icon in it.
    • If you don’t see warning icon you can skip this step.
    • Visit https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers and click on “Downloads” tab.
    • Click on “CP210x Universal Windows Driver” link and a download should start.
    • Once download is completed locate the downloaded driver package (usually a .zip file) and extract its contents to a folder on your computer (open zip file with File explorer and click on “Extract all” button).
    • Using Windows File Explorer, locate the driver folder (that you previously unzipped)
    • Right click on the silabser.inf file and select Install & Follow the instructions.
    • Once the installation is complete, you should see a message indicating that the driver installation was successful. Click “Finish” to exit the installer.
    • To verify that the driver has been installed correctly, open the Windows Device Manager. You should see an entry for “Silicon Labs CP210x USB to UART Bridge” with a COM port number assigned to it (e.g., COM3).
    • If you’re using the Arduino IDE to program your NodeMCU board, close and restart the IDE to ensure it recognizes the newly installed driver.
  6. Install Additional Board Packages:

  7. Install Additional Libraries:

    • You can install libraries to extend the functionality of your Arduino projects. Go to “Sketch” > “Include Library” > “Manage Libraries” to browse and install libraries from the Arduino Library Manager.
    • For this project download
      NameVersionAuther
      Blynk1.3.0 or aboveVolodymyr Shymanskyy

Blynk setup

Programming

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#define BLYNK_TEMPLATE_ID "..."
#define BLYNK_TEMPLATE_NAME "..."
#define BLYNK_AUTH_TOKEN "..."
#define BLYNK_PRINT Serial

#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>

// Motor PINs
#define ENA D1
#define IN1 D2
#define IN2 D3
#define IN3 D5
#define IN4 D6
#define ENB D7

#define SPD_VPIN V0
#define DIR_VPIN V1

const char ssid[] = "...";
const char pass[] = "...";

int car_speed = 1;
int car_dir = 0; // 1 -> forward, 2 -> right, 3 -> backward, 4 -> left, stop

void setup() {
  pinMode(LED_BUILTIN_AUX, OUTPUT);
  digitalWrite(LED_BUILTIN_AUX, HIGH);

  pinMode(ENA, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  pinMode(ENB, OUTPUT);

  Serial.begin(9600);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);

  // reset
  Blynk.virtualWrite(SPD_VPIN, car_speed);
  Blynk.virtualWrite(DIR_VPIN, car_dir);
  digitalWrite(LED_BUILTIN_AUX, LOW);
}

BLYNK_WRITE(SPD_VPIN) {
  car_speed = param.asInt();
  Serial.print("speed =>> ");
  Serial.println(car_speed);
}

BLYNK_WRITE(DIR_VPIN) {
  car_dir = param.asInt();
  Serial.print("direction =>> ");
  Serial.println(car_dir);
}

void loop() {
  Blynk.run();

  analogWrite(ENA, car_speed);
  analogWrite(ENB, car_speed);

  switch (car_dir) {
  case 1: // forward
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    break;

  case 2: // right
    digitalWrite(IN1, HIGH);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    break;

  case 3: // backward
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, HIGH);
    digitalWrite(IN4, LOW);
    break;

  case 4: // left
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, HIGH);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, HIGH);
    break;

  default: // stop
    digitalWrite(IN1, LOW);
    digitalWrite(IN2, LOW);
    digitalWrite(IN3, LOW);
    digitalWrite(IN4, LOW);
    break;
  }
}

Hardware setup

Circuit diagram of IoT Car (4 wheel)

Congratulations on successfully creating your own Internet-controlled RC car using Blynk and NodeMCU! You’ve not only mastered the art of crafting a customized RC vehicle but also explored the realm of remote control through the power of the internet. As you reflect on your journey, remember that this project is just the beginning. The skills you’ve developed can be expanded to create even more sophisticated projects in the world of electronics and remote control.

Feel free to experiment with additional features, such as adding sensors for obstacle detection or enhancing the app interface on Blynk. The possibilities are limitless, and your newfound knowledge opens doors to a myriad of exciting possibilities in the DIY electronics space.

Thank you for joining us on this adventure. Keep innovating, exploring, and building! Happy making!