RC Car using L298N, HC-06, and Arduino Uno
Introduction
With this article, we will create a remote control (RC) car with the use of HC-06 bluetooth module to make it wireless and L298N motor driver to control speed and direction of rotations of the motors.
Bill Of Materials
- Arduino Uno as the main board
- HC-06 bluetooth module to receive commands via bluetooth communication protocol.
- L298N motor driver module
- DC motors to move the RC car.
Video Demonstration
Source Code
1#include "SoftwareSerial.h"
2
3#define IN3Br 2
4#define IN4Br 4
5#define PWMBr 3
6
7#define IN1Al 7
8#define IN2Al 5
9#define PWMAl 6
10
11#define HC_06_Rx 12
12#define HC_06_Tx 11
13
14#define NORMAL_SPEED 60
15#define TURNS_SPEED 10
16
17SoftwareSerial swSerial(HC_06_Rx,HC_06_Tx);
18String cmd="";
19bool isAlEnabled = false;
20bool isBrEnabled = false;
21byte PWMAl_val = 100;
22byte PWMBr_val = 100;
23
24void setup() {
25 // put your setup code here, to run once:
26 Serial.begin(9600);
27 swSerial.begin(9600);
28
29 pinMode(IN3Br, OUTPUT);
30 pinMode(IN4Br, OUTPUT);
31 pinMode(PWMBr, OUTPUT);
32
33 pinMode(IN1Al, OUTPUT);
34 pinMode(IN2Al, OUTPUT);
35 pinMode(PWMAl, OUTPUT);
36
37 digitalWrite(IN3Br, LOW);
38 digitalWrite(IN4Br, LOW);
39 digitalWrite(PWMBr, LOW);
40
41 digitalWrite(IN1Al, LOW);
42 digitalWrite(IN2Al, LOW);
43 digitalWrite(PWMAl, LOW);
44
45 swSerial.println("Setup Complete");
46}
47
48void loop() {
49 // put your main code here, to run repeatedly:
50 checkSerial();
51}
52
53void checkSerial() {
54 //Read data from Serial
55 while(Serial.available()>0){
56 cmd+=(char)Serial.read();
57 }
58
59 while(swSerial.available()>0){
60 cmd+=(char)swSerial.read();
61 }
62
63 //Select function with cmd
64 if(cmd!=""){
65 cmd.trim(); // Remove added LF in transmit
66 // We expect Command from bluetooth
67 if (cmd.equals("S")) {
68 swSerial.println("Braking");
69 brakeVehicle();
70 } else if(cmd.equals("R")) {
71 swSerial.println("Right turn");
72 turnVehicleRght();
73 }else if (cmd.equals("L")){
74 swSerial.println("Left turn");
75 turnVehicleLeft();
76 }else if(cmd.equals("F")){
77 swSerial.println("Moving forward");
78 moveVehicleForward();
79 }else if(cmd.equals("B")){
80 swSerial.println("Moving backward");
81 moveVehicleBackward();
82 }
83 cmd=""; //reset cmd
84 }
85}
86
87void brakeVehicle () {
88 digitalWrite(PWMBr, LOW);
89 digitalWrite(PWMAl, LOW);
90}
91
92void turnVehicleRght() {
93 analogWrite(PWMBr, TURNS_SPEED);
94 analogWrite(PWMAl, NORMAL_SPEED);
95}
96
97void turnVehicleLeft() {
98 analogWrite(PWMAl, TURNS_SPEED);
99 analogWrite(PWMBr, NORMAL_SPEED);
100}
101
102void moveVehicleForward() {
103 digitalWrite(IN3Br, HIGH);
104 digitalWrite(IN4Br, LOW);
105 analogWrite(PWMBr, NORMAL_SPEED);
106
107 digitalWrite(IN1Al, HIGH);
108 digitalWrite(IN2Al, LOW);
109 analogWrite(PWMAl, NORMAL_SPEED);
110}
111
112void moveVehicleBackward() {
113 digitalWrite(IN3Br, LOW);
114 digitalWrite(IN4Br, HIGH);
115 analogWrite(PWMBr, NORMAL_SPEED);
116
117 digitalWrite(IN1Al, LOW);
118 digitalWrite(IN2Al, HIGH);
119 analogWrite(PWMAl, NORMAL_SPEED);
120}
Call To Action
If you found this tutorial helpful, please consider supporting me by sharing this to your friends. You may leave your comments and suggestions in the comment box.
Thank you and have a good day.
Posts in this series
- How to Get Started with ATTiny85 in Arduino IDE
- Tutorial: How to use MFRC522 RFID module using Arduino
- SOS Flasher Using Millis Function with Enable Switch
- Tutorial: How to use DS3231 RTC in Arduino
- Tutorial: How to use 0.96 OLED - a small and cute display
- Tutorial: Getting Started with the NRF24L01 | How to use | Arduino
- Tutorial: How to use SIM800L GSM Module for Controlling Anything | Arduino
- Tutorial: How to use Keypad | Text Entry Mode | Arduino
- Tutorial: How to use 4x4 Keypad | Arduino
- Project Idea: Arduino Voltmeter
- Project Idea: Door Lock Security | Arduino
- Multitasking with Arduino | Relay Timer Controller | using millis
- Tutorial Understanding Blink Without Delay | How to millis
- Arduino Simple LCD Menu
- How to use SIM800L GSM Module using Arduino | Make or Answer Voice Calls
- Tutorial: How to Use Arduino Uno as HID | Part 2: Arduino Mouse Emulation
- Tutorial: How to Use Arduino Uno as HID | Part 1: Arduino Keyboard Emulation
- Tutorial: How to use SIM800L DTMF to Control Anything | Arduino
- Tutorial: Arduino EEPROM
- How to use SIM800L GSM Module | Arduino | Send and Receive SMS
- 16x2 LCD Menu for Arduino
- Tutorial: Arduino GPIO | How to use Arduino Pins
- MIT App Inventor for Arduino
- How to Use LCD Keypad Shield for Arduino
- How to Use Arduino Interrupts
- Project: Automatic Alcohol Dispenser
- TUTORIAL: How to use HC-SR04 Ultrasonic Sensor with Arduino
- Source Code: Astronomia Meme and Funeral Dance | melodies the Arduino way
- How to Get Started with L293D Motor Driver Shield with Arduino
- How to Get Started with L298N Motor Driver module using Arduino
- Part 2: Wav Music Player with Lyrics Using Arduino and SD Card
- Interfacing Infrared to Arduino Uno
- Part 1: Wav Music Player Using Arduino Uno and SD Card
- How to Interface Stepper Motor to Arduino Uno
- How To Play MP3 Files on Arduino from SD Card
- What is Arduino Software Serial
- How to Interface SD card to Arduino (without SD card shield)?
- Playing Melodies Using Arduino
- 8 Degrees Of Freedom (DOF) Robot Using Arduino Uno
- How to Interface PS2 Controller to Arduino Uno
- Part 3: DF Player Mini Tinkering with Arduino Nano and LCD
- How to Interface HC-06 to Arduino
- How to make a Remote Control RC car using Arduino and HC-06 bluetooth module
- Part 2: DF Player Mini Tinkering with Arduino Nano
- Part 1: DF Player Mini - a mini cheap mp3 player
No comments yet!