0% found this document useful (0 votes)
18 views50 pages

Download

The document outlines a Robotics Skill Development Program focused on Arduino projects, including an overview of the Arduino IDE and the Arduino Uno board. It details several projects such as LED blinking, interfacing with DC gear motors using the L298N motor driver, and controlling motors via Bluetooth. Each project includes components required, circuit diagrams, and example code for implementation.

Uploaded by

myscarsinsilence
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views50 pages

Download

The document outlines a Robotics Skill Development Program focused on Arduino projects, including an overview of the Arduino IDE and the Arduino Uno board. It details several projects such as LED blinking, interfacing with DC gear motors using the L298N motor driver, and controlling motors via Bluetooth. Each project includes components required, circuit diagrams, and example code for implementation.

Uploaded by

myscarsinsilence
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

ROBOTICS SKILL

DEVELOPMENT PROGRAM

KAVINESH J SHIKHAR K TARUN PRASAD


CCCIR CCCIR CCCIR
Index

Sl. No Title Page No.


1 Overview of Arduino IDE 2

2 Arduino Uno 3

3 Project 1 6

4 Project 2 8

5 Project 3 12

6 Project 4 15

1
Arduino UNO

The Arduino Uno is one of the most popular and beginner-friendly Arduino boards, perfect for a variety
of projects and prototyping.

2
Key Features:
● Microcontroller (ATmega328P): The heart of the Arduino Uno, this microcontroller manages
all the board’s operations, including processing inputs and outputs.
● Operating Voltage (3.3V-5V): The voltage level at which the board operates. It is compatible
with most sensors and components designed for 3.3V and 5V.
● Input Voltage: The range of input voltage supplied via the power jack. The onboard voltage
regulator converts it to the stable 5V needed by the microcontroller.
● Digital I/O Pins (14): These pins can be used for digital input (reading signals) or output
(controlling components like LEDs). Six of these pins (marked with ‘~’) support Pulse Width
Modulation (PWM), which allows for analog-like control over components like motors and
LEDs.
● Analog Input Pins (6): The analog pins read varying voltage levels, making them useful for
sensors that provide analog signals (e.g., temperature sensors, potentiometers).
● Clock Speed (16 MHz): The speed at which the microcontroller processes instructions, ensuring
smooth operation and timing control in various projects.
● Flash Memory (32 KB): Storage for your code (sketches). 0.5 KB is reserved for the bootloader,
which helps upload new programs from your computer.

3
Introduction to Arduino IDE

The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board.
This software can be used with any Arduino board.

Installation

Step 1. Click on the following link to download the Arduino IDE


Arduino_software

Step 2. Click on the downloaded software

4
Step 3. Follow the instructions in the installation guide

● Click on agree to proceed with the installation

● Click on next to continue

● Choose the default installation location

5
● Complete the installation

6
Step 4. To launch the Arduino IDE application

● Click on windows search icon and type Arduino IDE


● Click on Arduino IDE to launch the Integrated Development Environment

7
Overview of Arduino IDE

The Arduino Integrated Development Environment (IDE) is a powerful tool that enables users to
write, edit, compile, and upload code to Arduino boards. It simplifies the programming process, making it
accessible to beginners and efficient for experienced developers.

● Arduino uses a simplified version of C/C++. Users write code using functions, libraries, and
structures that are easy to learn and use.
● The IDE includes a variety of built-in functions that simplify common tasks, such as controlling
pins, reading sensors, and communicating with other devices.
● The IDE comes with a wide range of example sketches (pre-written code) that demonstrate how
to use various functions and libraries.
● Users can easily include additional libraries to expand functionality, such as controlling specific
sensors, motors, or displays.
● The IDE checks the code for errors and compiles it into a format that the Arduino board can
understand.
● With a single click, users can upload their code to the connected Arduino board via USB.

Arduino IDE documentation: https://docs.arduino.cc/software/ide-v2/tutorials/getting-started-ide-v2/


Download Arduino IDE: https://www.arduino.cc/en/software
Installation guide:
https://docs.arduino.cc/software/ide-v2/tutorials/getting-started/ide-v2-downloading-and-installing

8
Configuration

Step 5. Identify the board in IDE

● Click on Tools in Arduino IDE


● Click on Board and select Arduino Uno board

9
Blink Arduino program

1. Open Arduino IDE as shown in Step 1


2. Connect the Arduino uno board to PC
3. Click on File ->
Select Examples ->
Select 0.1Basics->
Click Blink

10
The following example program will be displayed

Code Explanation:

void setup():
This function runs once when the Arduino board starts or resets.

pinMode(LED_BUILTIN, OUTPUT);:

● This sets pin LED_BUILTIN as an output pin.


● The Arduino needs to know whether you want to use a pin as an input (e.g., to read a
button) or an output (e.g., to control an LED).

11
void loop():

● This function runs repeatedly in a loop as long as the Arduino is powered on.

digitalWrite(led, HIGH);:

● Sends a HIGH voltage signal to pin LED_BUILTIN, turning the LED on.

delay(1000);:

● Pauses the program for 1000 milliseconds (1 second).


● The LED remains on during this pause.

digitalWrite(led, LOW);:

● Sends a LOW voltage signal to pin LED_BUILTIN, turning the LED off.

delay(1000);:

● Pauses the program for another 1 second while the LED is off.

12
Code verification

● Compile the program to verify the code

13
This message is displayed for successful compilation of given code.

14
● Search for Device manager in windows search icon in the bottom left corner

● Connect Arduino uno board to PC

15
● Expand Ports in device manager
Identify the USB-SERIAL CH340 connected to which specific COM port

● Select the identified COM port in Arduino IDE under tools

● Program the arduino uno board by uploading the verified code

16
Result

Observe the internal LED start to blink for delay of 1 second (1000 millisecond)

17
Project 1: Simple LED Blink
The LED blink project is one of the most fundamental exercises for beginners using the Arduino
Uno. This project demonstrates the basic principles of digital output and introduces you to programming
the Arduino.

Objective:

To make an LED connected to a digital pin on the Arduino Uno blink on and off at a regular interval,
typically once every second.

Components Required:

● Arduino Uno board


● LED (any color)
● 220-ohm resistor
● Breadboard (optional)
● Jumper wires

18
Circuit Diagram:

19
Connect the anode (long leg) of the LED to one end of the 220-ohm resistor.
Connect the short leg (cathode) to GND (ground) pin on the Arduino uno board
Connect the other end of the resistor to the GPIO 3 digital pin on the Arduino Uno board

Code:

// LED Blink Example


// This code controls an LED connected to GPIO pin 3, turning it on and off in a loop with 1-second
intervals.

void setup() {
pinMode(3, OUTPUT); // Configure GPIO pin 3 as an output to control the LED
}

void loop() {
digitalWrite(3, HIGH); // Set GPIO pin 3 to HIGH, turning the LED on
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(3, LOW); // Set GPIO pin 3 to LOW, turning the LED off
delay(1000); // Wait for 1 second before repeating
}

On writing code, check for the correct baud rate (9600 / 115200 based on requirement) and select Arduino
Uno board under board selection and make sure your board is plugged to your system.

Now compile the code by clicking the “tick” option on top left of your screen.

On Successful completion, upload the code to the board by choosing the port that the device is connected
to by clicking the right arrow button next to the compile button.

Follow the same to all the project to compile and upload the code.

Once uploaded to the Arduino, the LED connected to pin 3 will blink on for 1 second and then off for 1
second repeatedly. This simple project serves as a foundation for understanding how to control outputs
with Arduino, and it can be expanded to include more complex behavior or additional components.

Task 1: Write a code to blink the LED is a different frequency

20
Project 2: Interfacing Arduino with DC Gear Motor Using L298N

The L298N motor driver is a popular dual H-bridge motor controller that allows you to control
the speed and direction of DC motors or gear motors using an Arduino. In this project, we'll connect a
gear motor to the Arduino via the L298N module.

Components Needed:

● Arduino Uno
● L298N motor driver module
● Gear motor (DC motor with gearbox)
● Power source (e.g., 12V battery or power adapter)
● Jumper wires

Connection:

21
Motor Connection

Circuit Connection:

Follow instructions to connect the Arduino to the L298N and the DC motor:

22
Power Connections:

L298N 12V (+12V): Connect to the positive terminal of your external power supply.

L298N GND: Connect to the ground (GND) of the external power supply and also to the
Arduino GND to have a common reference.

Motor Connections:
DC Motor Terminals: Connect to OUT1 and OUT2 on the L298N to BO DC motor.

Control Connections:

IN1: Connect to Arduino Digital Pin 2.


IN2: Connect to Arduino Digital Pin 3.

5V Pin on L298N: If you plan to use the L298N’s 5V to power the Arduino, ensure the jumper is
in place. Otherwise, leave the jumper off and power the Arduino separately via USB or another
source.

Code:

int IN3 = 6;
int IN4 = 5;

void setup() {
// put your setup code here, to run once:
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

}
void loop() {

digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);

delay(3000);

digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);

23
delay(3000);
}

Code explanation :

setup() Function
● motor1pin1 and motor1pin2 are declared as int variables and assigned to pins 2 and 3 of
the Arduino, respectively. These pins will control the motor's behavior.

setup() Function
● pinMode(motor1pin1, OUTPUT) and pinMode(motor1pin2, OUTPUT) configure
the pins as outputs, enabling the Arduino to send signals to the motor driver (e.g., an H-bridge
like L298N).

loop() Function
● motor1pin1 is set to HIGH (5V).
● motor1pin2 is set to LOW (0V).
● This drives the motor in one direction, assuming the motor driver interprets the signal as "forward
rotation."
● Delay keeps the motor running in the forward direction for 3 seconds (3000 milliseconds).
● motor1pin1 is set to LOW (0V).
● motor1pin2 is set to HIGH (5V).
● This reverses the polarity across the motor, causing it to rotate in the opposite direction ("reverse
rotation").
● Delay function keeps the motor running in reverse for 3 seconds.

Safety Tips

Check Voltage Ratings: Ensure that the voltage of the external power supply matches the requirements of
both the L298N and the motor.
Avoid Short Circuits: Double-check all connections before powering the circuit to prevent short circuits,
which can damage components.
Heat Dissipation: The L298N can get warm when driving motors. Consider adding a heatsink or ensuring
adequate ventilation.
Use Current-Limiting Resistors: If adding LEDs or other components, use appropriate resistors to prevent
excess current draw.

24
Project 3: Interfacing Arduino with 2 Gear Motor Using L298N

Description : Over here an additional motor is interfaced and the rest remains as the previous
projects

Circuit diagram:

Now connect the L298N module’s Input pins( IN1, IN2, IN3, IN4) to the six Arduino digital output pins
(2, 3 , 4, 5).

Finally, wire one motor to terminal A (OUT1 and OUT2) and the other to terminal B (OUT3 and OUT4).
You can swap out your motor’s connections. There is technically no right or wrong way.

25
Code

int IN3 = 4;
int IN4 = 5;

void setup() {
// put your setup code here, to run once:
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

}
void loop() {

digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);

delay(3000);

digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);

delay(3000);
}

26
Project 4: Control Gear Motors Using Bluetooth Module

Integrating the HC-05 Bluetooth module with your Arduino and L298N motor driver setup allows
you to control your DC gear motor wirelessly using a smartphone or any Bluetooth-enabled device. This
addition enhances the interactivity of your project and provides a foundation for more advanced
remote-controlled applications.

Click for Instruction for Robot

Components Required
In addition to the components listed in the previous project, you'll need:
1. HC-05 Bluetooth Module
2. Smartphone or Bluetooth-enabled Device

Understanding the HC-05 Bluetooth Module


The HC-05 is a popular Bluetooth module that enables serial communication between your Arduino and
other Bluetooth-enabled devices. It operates using the Serial Port Protocol (SPP) and can be configured as
either a master or a slave device.
Key Pins of HC-05:
● VCC: Power supply (3.3V to 6V, typically 5V)
● GND: Ground
● TXD: Transmit Data
● RXD: Receive Data
● KEY: Used for entering AT command mode (optional for basic operation)

Circuit Diagram

27
Circuit remains same as that of previous project except for extra bluetooth connection that's shown above.

1. Power Connections:
○ L298N 12V (+12V): Connect to the positive terminal of your external power supply.
○ L298N GND: Connect to the ground (GND) of the external power supply and to the Arduino

28
GND.
○ HC-05 VCC: Connect to Arduino 5V.
○ HC-05 GND: Connect to Arduino GND.

2. Motor Connections:
○ DC Motor Terminals: Connect to OUT1 and OUT2 on the L298N.

3. Control Connections:
○ ENA: Connect to Arduino Digital Pin 9 (PWM pin) to control speed.
○ IN1 : Connect to Arduino Digital Pin 2.
○ IN2 : Connect to Arduino Digital Pin 3.
○ IN3 : Connect to Arduino Digital Pin 4.
○ IN4 : Connect to Arduino Digital Pin 5.

4. HC-05 Bluetooth Module Connections:


○ TXD (HC-05): Connect to Arduino RX (Pin 10) directly or through a voltage divider (e.g.,
1kΩ resistor and 2kΩ resistor) to reduce 5V to 3.3V for safe communication.
○ RXD (HC-05): Connect to Arduino TX (Pin 11) directly or through a voltage divider if
necessary.
○ KEY (HC-05): Typically left unconnected for basic operation.

Code

#include <SoftwareSerial.h> // Include the SoftwareSerial library to communicate with Bluetooth

#define IN1 2 // Motor driver input pin for controlling direction

#define IN2 3 // Motor driver input pin for controlling direction

#define IN3 4 // Motor driver input pin for controlling direction

#define IN4 5 // Motor driver input pin for controlling direction

// Define Bluetooth RX and TX pins

SoftwareSerial bt(11, 10); // RX (pin 11) and TX (pin 10) for Bluetooth communication

char data; // Variable to store incoming Bluetooth data

void setup() {

Serial.begin(9600); // Initialize serial communication at 9600 baud for debugging

pinMode(IN1, OUTPUT); // Set motor control pins as outputs

pinMode(IN2, OUTPUT);

29
pinMode(IN3, OUTPUT);

pinMode(IN4, OUTPUT);

// Set initial state of motor control pins to LOW (motors off)

digitalWrite(IN1, LOW);

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW);

digitalWrite(IN4, LOW);

bt.begin(9600); // Start Bluetooth communication at 9600 baud

void loop() {

while (bt.available()) { // Check if data is available from Bluetooth

data = bt.read(); // Read incoming Bluetooth data

Serial.println(data); // Print received data to Serial monitor for debugging

// Perform actions based on received data

switch (data) {

case 'F': // If 'F' is received, move forward

forward();

break;

case 'B': // If 'B' is received, move backward

reverse();

break;

case 'L': // If 'L' is received, turn left

left();

break;

30
case 'R': // If 'R' is received, turn right

right();

break;

case 'S': // If 'S' is received, stop the robot

stoprobot();

break;

delay(100); // Short delay to prevent overwhelming the Bluetooth receiver

// Function to move forward

void forward() {

digitalWrite(IN1, HIGH); // Set motor A forward

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW); // Set motor B forward

digitalWrite(IN4, HIGH);

delay(20); // Short delay for command execution

// Function to move backward

void reverse() {

digitalWrite(IN1, LOW); // Set motor A backward

digitalWrite(IN2, HIGH);

digitalWrite(IN3, HIGH); // Set motor B backward

digitalWrite(IN4, LOW);

31
delay(20); // Short delay for command execution

// Function to turn left

void left() {

digitalWrite(IN1, HIGH); // Set motor A forward

digitalWrite(IN2, LOW);

digitalWrite(IN3, HIGH); // Set motor B backward

digitalWrite(IN4, LOW);

delay(20); // Short delay for command execution

// Function to turn right

void right() {

digitalWrite(IN1, LOW); // Set motor A backward

digitalWrite(IN2, HIGH);

digitalWrite(IN3, LOW); // Set motor B forward

digitalWrite(IN4, HIGH);

delay(20); // Short delay for command execution

// Function to stop the robot

void stoprobot() {

digitalWrite(IN1, LOW); // Turn off motor A

digitalWrite(IN2, LOW);

digitalWrite(IN3, LOW); // Turn off motor B

32
digitalWrite(IN4, LOW);

delay(20); // Short delay for command execution

Smartphone Setup and App Configuration

To send commands to the Arduino via the HC-05 module, you'll need a Bluetooth controller app.
Below are the steps to set up your smartphone:

1. Pairing the HC-05 Module:


● Default Pairing Code: 1234 or 0000
● Steps:
1. Turn on Bluetooth on your smartphone.
2. Search for new devices and select the HC-05 module (commonly named "HC-05").
3. When prompted, enter the default pairing code.
4. Once paired, note the COM port or connection status.

2. Installing a Bluetooth Controller App:


Several free apps are available for both Android and iOS devices. Here are some recommendations:
● Android:
○ Arduino Bluetooth Controller: User-friendly with customizable buttons and joysticks.
○ Bluetooth RC Controller: Simple interface for sending predefined commands.
● iOS:
○ Bluetooth Terminal: Allows sending custom text commands.
○ BLE Controller: Suitable for sending and receiving serial data.

3. Configuring the App:


● Open the App: Launch the Bluetooth controller app on your smartphone.
● Connect to HC-05: Select the paired HC-05 module from the list of available devices.
● Map Controls to Commands:
○ Assign buttons or controls in the app to send specific characters (e.g., 'F', 'B', 'S', '+', '-').
○ For example:
■ Forward Button: Sends 'F'
■ Backward Button: Sends 'B'
■ Stop Button: Sends 'S'
■ Increase Speed Button: Sends '+'
■ Decrease Speed Button: Sends '-'

33
Explanation of the Code

1. Pin Definitions:
○ ENA (Pin 9): Controls motor speed via PWM.
○ IN1 (Pin 8) & IN2 (Pin 7): Control motor direction.
2. Setup Function:
○ Initializes motor control pins as outputs.
○ Starts serial communication at 9600 baud (default for HC-05).
○ Stops the motor initially.
○ Sends a ready message to the Serial Monitor.
3. Loop Function:
○ Checks if data is available from the serial buffer (Bluetooth).
○ Reads the incoming character and executes corresponding motor control functions based on
the command.
4. Motor Control Functions:
○ moveForward(): Sets direction pins to rotate the motor forward and applies the current speed.
○ moveBackward(): Sets direction pins to rotate the motor backward and applies the current
speed.
○ stopMotor(): Stops the motor by setting both direction pins LOW and PWM to 0.
○ increaseSpeed(): Increases motor speed by increments of 10, up to a maximum of 255.
○ decreaseSpeed(): Decreases motor speed by increments of 10, down to a minimum of 0.

Task 3: Develop a code to control 2 motors simultaneously / to move the robot (forward, reverse, stop
operation respectively).

Task 4: Develop a code to move the robot in desired direction (that is to add left and right turn along with
forward, reverse, stop operation).

34
Project 4b: Line Follower Robot

5 channel IR sensor: Based on the TCRT5000 infrared reflective sensor, the TCRT5000L 5 Channel
Tracking Sensor Tracking Module Infrared Sensor is frequently used to produce tracking smart cars.

Components Required
In addition to the components listed in the previous project, you'll need:
3. 5 channel IR array

Understanding the ir Module


● Excellent for creating quick line-following and grid-navigating robots.
● Consists of simple-to-use digital outputs that can be connected directly to microcontrollers.
● For simple attachment, the array contains mounting holes with a 3mm diameter

Key Pins
● VCC: VCC (It is the power input port, which could access 3.3V ~ 5V voltage)
● GND: GND (It is the negative input of the power supply)
● OUT1 ~ 5 Pin: OUT (It is the signal output port, MCU link I / O port)

Circuit Diagram

35
Code

#define m1 4 //Right Motor MA1

#define m2 5 //Right Motor MA2

#define m3 2 //Left Motor MB1

#define m4 3 //Left Motor MB2

#define e1 9 //Right Motor Enable Pin EA

#define e2 10 //Left Motor Enable Pin EB

//**********5 Channel IR Sensor Connection**********//

#define ir1 A0

#define ir2 A1

#define ir3 A2

#define ir4 A3

#define ir5 A4

//*************************************************//

void setup() {

36
pinMode(m1, OUTPUT);

pinMode(m2, OUTPUT);

pinMode(m3, OUTPUT);

pinMode(m4, OUTPUT);

pinMode(e1, OUTPUT);

pinMode(e2, OUTPUT);

pinMode(ir1, INPUT);

pinMode(ir2, INPUT);

pinMode(ir3, INPUT);

pinMode(ir4, INPUT);

pinMode(ir5, INPUT);

void loop() {

//Reading Sensor Values

int s1 = digitalRead(ir1); //Left Most Sensor

int s2 = digitalRead(ir2); //Left Sensor

int s3 = digitalRead(ir3); //Middle Sensor

int s4 = digitalRead(ir4); //Right Sensor

int s5 = digitalRead(ir5); //Right Most Sensor

//if only middle sensor detects black line

if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 1) && (s5 == 1))

37
//going forward with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, HIGH);

digitalWrite(m2, LOW);

digitalWrite(m3, HIGH);

digitalWrite(m4, LOW);

//if only left sensor detects black line

if((s1 == 1) && (s2 == 0) && (s3 == 1) && (s4 == 1) && (s5 == 1))

//going right with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, HIGH);

digitalWrite(m2, LOW);

digitalWrite(m3, LOW);

digitalWrite(m4, LOW);

//if only left most sensor detects black line

if((s1 == 0) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 1))

38
//going right with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, HIGH);

digitalWrite(m2, LOW);

digitalWrite(m3, LOW);

digitalWrite(m4, HIGH);

//if only right sensor detects black line

if((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 0) && (s5 == 1))

//going left with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, LOW);

digitalWrite(m2, LOW);

digitalWrite(m3, HIGH);

digitalWrite(m4, LOW);

//if only right most sensor detects black line

if((s1 == 1) && (s2 == 1) && (s3 == 1) && (s4 == 1) && (s5 == 0))

//going left with full speed

39
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, LOW);

digitalWrite(m2, HIGH);

digitalWrite(m3, HIGH);

digitalWrite(m4, LOW);

//if middle and right sensor detects black line

if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 1))

//going left with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, LOW);

digitalWrite(m2, LOW);

digitalWrite(m3, HIGH);

digitalWrite(m4, LOW);

//if middle and left sensor detects black line

if((s1 == 1) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))

//going right with full speed

40
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, HIGH);

digitalWrite(m2, LOW);

digitalWrite(m3, LOW);

digitalWrite(m4, LOW);

//if middle, left and left most sensor detects black line

if((s1 == 0) && (s2 == 0) && (s3 == 0) && (s4 == 1) && (s5 == 1))

//going right with full speed

analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, HIGH);

digitalWrite(m2, LOW);

digitalWrite(m3, LOW);

digitalWrite(m4, LOW);

//if middle, right and right most sensor detects black line

if((s1 == 1) && (s2 == 1) && (s3 == 0) && (s4 == 0) && (s5 == 0))

//going left with full speed

41
analogWrite(e1, 255); //you can adjust the speed of the motors from 0-255

analogWrite(e2, 255); //you can adjust the speed of the motors from 0-255

digitalWrite(m1, LOW);

digitalWrite(m2, LOW);

digitalWrite(m3, HIGH);

digitalWrite(m4, LOW);

//if all sensors are on a black line

if((s1 == 0) && (s2 == 0) && (s3 == 0) && (s4 == 0) && (s5 == 0))

//stop

digitalWrite(m1, LOW);

digitalWrite(m2, LOW);

digitalWrite(m3, LOW);

digitalWrite(m4, LOW);

42
Code Explanation

Setup: The setup() function initializes motor control pins as outputs and sensor pins as inputs.

Loop Functionality: The loop() function reads values from the IR sensors and adjusts the motor
speeds and directions based on the sensor readings. Here’s how the robot’s movements are controlled:

● Moving Forward: When only the middle sensor detects the black line, both motors are set to
move forward.
● Turning Right: When the left sensors detect the black line, it signals that the robot is veering left,
so the motors are adjusted to turn the robot right.
● Turning Left: When the right sensors detect the black line, the robot corrects by turning left.
● Stopping: When all sensors detect the black line, the robot stops, assuming it has reached the end
of the path or needs to stop

Motor Control Logic: Each condition sets the motors to a specific configuration using digitalWrite
and analogWrite functions to control the direction and speed of the motors.

APPENDIX A

L298N Motor Driver Module:

L298N Motor Driver Module is a high power motor driver


module for driving DC and Stepper Motors. This module consists
of an L298 motor driver IC and a 78M05 5V regulator. L298N
Module can control up to 4 DC motors, or 2 DC motors with
directional and speed control.

L298N Module Pinout Configuration

43
Pin Name Description

IN1 & IN2 Motor A input pins. Used to control the spinning direction of Motor A

IN3 & IN4 Motor B input pins. Used to control the spinning direction of Motor B

ENA Enables PWM signal for Motor A

ENB Enables PWM signal for Motor B

OUT1 & OUT2 Output pins of Motor A

OUT3 & OUT4 Output pins of Motor B

12V 12V input from DC power Source

5V Supplies power for the switching logic circuitry inside L298N IC

Features & Specifications

● Driver Model: L298N 2A


● Driver Chip: Double H Bridge L298N
● Motor Supply Voltage (Maximum): 46V
● Motor Supply Current (Maximum): 2A
● Logic Voltage: 5V
● Driver Voltage: 5-35V
● Driver Current:2A
● Logical Current:0-36mA
● Maximum Power (W): 25W
● Current Sense for each motor
● Heatsink for better performance
● Power-On LED indicator

44
The L298N Motor Driver module consists of an L298 Motor Driver IC, 78M05 Voltage Regulator,
resistors, capacitor, Power LED, 5V jumper in an integrated circuit. 78M05 Voltage regulator will be
enabled only when the jumper is placed. When the power supply is less than or equal to 12V, then the
internal circuitry will be powered by the voltage regulator and the 5V pin can be used as an output pin to
power the microcontroller. The jumper should not be placed when the power supply is greater than 12V
and separate 5V should be given through 5V terminal to power the internal circuitry.

ENA & ENB pins are speed control pins for Motor A and Motor B while IN1& IN2 and IN3 & IN4 are
direction control pins for Motor A and Motor B.

Internal circuit diagram of L298N Motor Driver module is given below:

HC 05 Bluetooth Module:

HC-05 is a Bluetooth module which is designed for


wireless communication. This module can be used in a
master or slave configuration.
It is used for many applications like wireless headset,
game controllers, wireless mouse, wireless keyboard,
and many more consumer applications.
It has a range up to <100m which depends upon
transmitter and receiver, atmosphere, geographic &
urban conditions.
It is IEEE 802.15.1 standardized protocol, through

45
which one can build wireless Personal Area Network (PAN). It uses frequency-hopping spread spectrum
(FHSS) radio technology to send data over air.
It uses serial communication to communicate with devices. It communicates with a microcontroller using
a serial port (USART).

Pin Description

1. Key/EN: It is used to bring Bluetooth modules in AT commands mode. If the Key/EN pin is set to
high, then this module will work in command mode. Otherwise by default it is in data mode. The default
baud rate of HC-05 in command mode is 38400 bps and 9600 in data mode.
HC-05 module has two modes,
a. Data mode: Exchange of data between devices.
b. Command mode: It uses AT commands which are used to change setting of HC-05. To send
these commands to the module serial (USART) port is used.
2. VCC: Connect 5 V or 3.3 V to this Pin.
3. GND: Ground Pin of module.
4. TXD: Transmit Serial data (wirelessly received data by Bluetooth module transmitted out serially on
TXD pin)
5. RXD: Receive data serially (received data will be transmitted wirelessly by Bluetooth module).
6. State: It tells whether module is connected or not.

Module Specification:
● Bluetooth version: 2.0 + EDR (Enhanced Data Rate)
● Frequency: 2.4 GHz ISM band
● Modulation: GFSK (Gaussian Frequency Shift Keying)
● Transmit power: Class 2 (up to 4 dBm)
● Sensitivity: -80 dBm typical
● Range: approximately 10 meters (or 33 feet) in open air
● Profiles supported: SPP (Serial Port Profile), HID (Human Interface Device) and others
● Operating voltage: 3.3V to 5V DC
● Operating current: less than 50mA
● Standby current: less than 2.5mA

46
● Sleep current: less than 1mA
● Interface: UART (Universal Asynchronous Receiver/Transmitter)
● Baud rates: 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200, 230400, and 460800
● Operating temperature: -20°C to 75°C (-4°F to 167°F)

Working Principle:
To communicate with a smartphone with the HC-05 Bluetooth module, the smartphone requires a
Bluetooth terminal application for transmitting and receiving data. You can find Bluetooth terminal
applications for android and windows in respective application stores.

Bluetooth Module Serial Interface

So, when we want to communicate through a smartphone with HC-05 Bluetooth module, connect this
HC-05 module to the PC via serial to USB converter.
Before establishing communication between two Bluetooth devices, 1st we need to pair the HC-05
module to a smartphone for communication.
Pair HC-05 and smartphone:
1. Search for a new Bluetooth device from your phone. You will find Bluetooth devices with the
“HC-05” name.
2. Click on connect/pair device option; default pin for HC-05 is 1234 or 0000.
● After pairing two Bluetooth devices, open terminal software (e.g. Teraterm, Realterm etc.) in PC,
and select the port where we have connected the USB to the serial module. Also select default
baud rate of 9600 bps.
● In smartphone, open Bluetooth terminal application and connect to paired device HC-05.
● It is simple to communicate, we just have to type in the Bluetooth terminal application of our
smartphone. Characters will get sent wirelessly to Bluetooth module HC-05. HC-05 will

47
automatically transmit it serially to the PC, which will appear on the terminal. Same way we can
send data from PC to smartphone.

Command Mode
● When we want to change settings of the HC-05 Bluetooth module like change password for
connection, baud rate, Bluetooth device’s name etc.
● To do this, HC-05 has AT commands.
● To use the HC-05 Bluetooth module in AT command mode, connect the “Key” pin to High
(VCC).
● Default Baud rate of HC-05 in command mode is 38400 bps.
● Following are some AT commands generally used to change the setting of the Bluetooth module.
● To send these commands, we have to connect the HC-05 Bluetooth module to the PC via serial to
USB converter and transmit these commands through the serial terminal of the PC.

Command Description Response

AT Checking communication OK

Set Password
AT+PSWD=XXXX OK
e.g. AT+PSWD=4567

Set Bluetooth Device Name


AT+NAME=XXXX OK
e.g. AT+NAME=MyHC-05

`AT+UART=Baud rate, stop bit, Change Baud rate


OK
parity bit e.g. AT+UART=9600,1,0

Respond version no. of Bluetooth +Version: XX OK


AT+VERSION?
module

Parameters: device type,


Send detail of setting done by
AT+ORGL module mode, serial
manufacturer
parameter, passkey, etc.

48
REFERENCE:
https://www.arduino.cc/

https://www.instructables.com/

https://www.electronicwings.com/

https://components101.com/

https://lastminuteengineers.com/

49

You might also like