Devices & Components
Arduino Uno Rev3
DC Motor, 12 V
Slide Switch
Dual H-Bridge motor drivers L298
thingSoC ESP32 WiFi Module
Jumper wires (generic)
Li-Ion Battery 1000mAh
Maker Essentials - Micro-motors & Grippy Wheels
Hardware & Tools
Hot glue gun (generic)
Project description
Code
Arduino Code
c_cpp
1#include <ESP8266WiFi.h> 2#include <WiFiClient.h> 3#include <ESP8266WebServer.h> 4//defining pins 5#define ENR D1 // Enables motors Right 6#define ENL D2 // Enables motors Left 7#define IN1 D5 // L298N in1 motors Right 8#define IN2 D6 // L298N in2 motors Right 9#define IN3 D7 // L298N in3 motors Left 10#define IN4 D8 // L298N in4 motors Left 11String command; //String to store web command "state" 12int Speed = 450; // initial speed 400-1024 13int SpeedDiv = 3; //value that speed will be divided by 14 15const char* ssid = "WiFi Car";// wifi ssid name 16ESP8266WebServer server(80);//server port-80, 80 is http port 17 18void setup() { 19pinMode(ENR, OUTPUT);//declaring pins as input or output in this case all are outputs 20pinMode(ENL, OUTPUT); 21pinMode(IN1, OUTPUT); 22pinMode(IN2, OUTPUT); 23pinMode(IN3, OUTPUT); 24pinMode(IN4, OUTPUT); 25Serial.begin(115200);//establishing serial communication between Arduino board and pc 26 27// Connecting WiFi 28WiFi.mode(WIFI_AP);//wifi mode set as wifi access point 29WiFi.softAP("WifiCar", "Password", 1, 0, 1); 30//WiFi.softAP(ssid, pwd, channel, hidden, max_connection) 31IPAddress myIP = WiFi.softAPIP(); 32Serial.print("AP IP address: ");//prints AP IP..... in serial monitor 33Serial.println(myIP);//ip address prints in arduino serial monitor 34// Starting WEB-server 35server.on ( "/", HTTP_handleRoot ); 36server.onNotFound ( HTTP_handleRoot ); 37server.begin(); 38} 39 40void Forward(){ //function for car forward 41digitalWrite(IN1, LOW); 42//if this is turned high l298n bridge would switch the polarities(+,-) and motor will turn backward 43digitalWrite(IN2, HIGH); 44//when this is turned high l298n bridge would switch the polarities(-,+) and motor will turn forward 45analogWrite(ENR, Speed);//enables l298N right side according to speed 46 47digitalWrite(IN3, LOW); 48digitalWrite(IN4, HIGH); 49analogWrite(ENL, Speed);//enables l298N left side according to speed 50} 51 52void Reverse(){ //function for reverse 53digitalWrite(IN1, HIGH); 54digitalWrite(IN2, LOW); 55analogWrite(ENR, Speed); 56 57digitalWrite(IN3, HIGH); 58digitalWrite(IN4, LOW); 59analogWrite(ENL, Speed); 60} 61 62void Right(){ //fuction for turning right 63//In this fuction when left side wheels are going backward the other side of wheel turns 64//backwards by doing that it gives the ability to turn in the same place(like in tanks) 65 digitalWrite(IN1, HIGH); 66 digitalWrite(IN2, LOW); 67 analogWrite(ENR, Speed); 68 69 digitalWrite(IN3, LOW); 70 digitalWrite(IN4, HIGH); 71 analogWrite(ENL, Speed); 72 } 73 74void Left(){//function for turning left 75//In this fuction when right side wheels are going forward the other side of wheel turns backwards 76//by doing that it gives the ability to turn in the same place(like in tanks) 77 digitalWrite(IN1, LOW); 78 digitalWrite(IN2, HIGH); 79 analogWrite(ENR, Speed); 80 81 digitalWrite(IN3, HIGH); 82 digitalWrite(IN4, LOW); 83 analogWrite(ENL, Speed); 84 } 85 86void goAheadRight(){//fuction for turning right while moving 87 digitalWrite(IN1, LOW); 88 digitalWrite(IN2, HIGH); 89 analogWrite(ENR, Speed/SpeedDiv); 90 //speed get divided by speeddiv and reduces the speed of right side wheels 91 92 digitalWrite(IN3, LOW); 93 digitalWrite(IN4, HIGH); 94 analogWrite(ENL, Speed); 95 } 96 97void goAheadLeft(){//fuction for turning left while moving; 98 digitalWrite(IN1, LOW); 99 digitalWrite(IN2, HIGH); 100 analogWrite(ENR, Speed); 101 102 digitalWrite(IN3, LOW); 103 digitalWrite(IN4, HIGH); 104 analogWrite(ENL, Speed/SpeedDiv); 105 //speed get divided by speeddiv and reduces the speed of left side wheels 106 } 107 108void goBackRight(){ //fuction for going right while reversing 109 digitalWrite(IN1, HIGH); 110 digitalWrite(IN2, LOW); 111 analogWrite(ENR, Speed/SpeedDiv); 112 113 digitalWrite(IN3, HIGH); 114 digitalWrite(IN4, LOW); 115 analogWrite(ENL, Speed); 116 } 117 118void goBackLeft(){ //fuction for going left while reversing 119 digitalWrite(IN1, HIGH); 120 digitalWrite(IN2, LOW); 121 analogWrite(ENR, Speed); 122 123 digitalWrite(IN3, HIGH); 124 digitalWrite(IN4, LOW); 125 analogWrite(ENL, Speed/SpeedDiv); 126 } 127 128void Stop(){ //stop 129 digitalWrite(IN1, LOW); 130 digitalWrite(IN2, LOW); 131 analogWrite(ENR, 0); 132 133 digitalWrite(IN3, LOW); 134 digitalWrite(IN4, LOW); 135 analogWrite(ENL, 0); 136 } 137 138void loop() { 139 server.handleClient(); 140 command = server.arg("State"); //functioning the fuctions according to user input 141 if (command == "F") Forward(); 142 else if (command == "B") Reverse(); 143 else if (command == "L") Left(); 144 else if (command == "R") Right(); 145 else if (command == "I") goAheadRight(); 146 else if (command == "G") goAheadLeft(); 147 else if (command == "J") goBackRight(); 148 else if (command == "H") goBackLeft(); 149 else if (command == "1") Speed = 470; 150 else if (command == "2") Speed = 540; 151 else if (command == "3") Speed = 680; 152 else if (command == "4") Speed = 750; 153 else if (command == "5") Speed = 1023; 154 else if (command == "S") Stop(); 155} 156void HTTP_handleRoot() 157{ 158if(server.hasArg("State"))//when server recives a command 159 { 160 Serial.println(server.arg("State"));//prints present state in arduino serial monitor 161 } 162 server.send ( 200, "text/html", "" );//getting the command 163 delay(1);} 164 165
Downloadable files
Connecting Wires to the L298N Motor Driver & ESP 32
So, let’s make this smart car step by step. The required components are as follows: - Used the necessary items and quantity with the help of the above hardware required table. • Secondly, glue the four gear motors to the car kit board, to do this, use the hot glue gun. • Thirdly, attach the motor driver board to the top of the foam board. Afterward, connect the gear motors to the Motor driver board. For that, use the below circuit diagram. • OK, now glue the breadboard as follows. Then, attach the Node MCU board to the breadboard. Next, connect the motor driver board to the Node MCU board. For that, use the above circuit diagram. • Now, connect the battery holder with the GND and 12v terminals on the motor drive board. After, glue it onto the car kit board. • OK. let’s set up the website. After connecting your device to the WIFI and go to the link in the above “web & app interface made to send commands” page. • Lastly, attach the batteries to the battery holder and turns ON your smart car. Now, go to the site: - http://wificar.c1.biz/ project and control it easily. OK, enjoy this project.
Connecting Wires to the L298N Motor Driver & ESP 32

Documentation
Design Architectural Structure - CAD Plan
Design Architectural Structure - CAD Plan

Comments
Only logged in users can leave comments