A Practical activity Report submitted for
Engineering Design Project-II (UTA-024)
By
Jasminder Singh 102108124
Shivam Singh 102108184
Rachanbir Singh 102108188
Kudrat Kaur Sandhu 102108189
Achyut Sharma 102108190
Vansh Gautam 102288013
Group: 2ME7
Submitted to
Mr. Himanshu Sharma
COMPUTER SCIENCE ENGINEERING DEPARTMENT
THAPAR INSTIUTE OF ENGINEERING AND TECHNOLOGY,
(A DEEMED TO BE UNIVERSITY), PATIALA, PUNJAB,
INDIA
JULY-DECEMBER 2022
INDEX
Sr. No Experiment
5. Write a program to demonstrate control of DC Motor using
forward, backward, left, right turn motion and clock-
wise/anti clock- wise rotation.
6. Write a program to read values of IR Sensor using analog
and digital read and convert buggy into normal line
follower robocar
7. To demonstrate the use of ultrasonic sensor by
integrating line follower robo car with obstacle
avoidance capability.
8. Write a program to read the pulse width of
gantry transmitter and trigger stop buggy
function by detecting individual gantry.
9. Write configuration program to demonstrate
Xbee module communication between two
PC’s using XCTU.
10. Write a program to control buggy in full supervisory mode
using serial communication and XCTU/C#.
11. Write a Program to demonstrate full bronze
challenge.
Experiment 5
Objective: To demonstrate control of DC Motor using forward, backward, left, right turn motion
and clock-wise/anti clock- wise rotation.
Hardware Used: Arduino Microcontroller, USB cable, Nvis 3302ARD RoboCar
Software Used: Arduino IDE
Theory: Nvis 3302ARD is capable of sensing environment using various sensor modules and acts
accordingly. Nvis RoboCar is a ready assembled unit consisting of strong chassis wheels with
different Sensor modules mounted on it. The machine is driven by DC motors which are powered
by rechargeable batteries. This Nvis 3302ARD is Atmega328P Microcontroller RoboCar. We can
design user defined functions in the Arduino IDE to make the buggy move in our own specified
directions like left, right, forward, backward, clockwise and anti clockwise by setting the pins 5, 6, 7
,8 on Nvis 3302ARD RoboCar either HIGH/LOW.
Code:
void forward()
{ digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
} void backward()
{
digitalWrite(5,LOW);
digitalWrite(6,HIGH);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
} void right()
{ digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH); }
FIG 0 BUGGY WITH MOTOR DIRECTIONS
void left() {
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
} void anticlockwise() {
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,HIGH);
digitalWrite(8,LOW);
} void clockwise() {
digitalWrite(5, LOW);
digitalWrite(6, HIGH);
digitalWrite(7,LOW);
digitalWrite(8, HIGH); }
void setup() {
Serial.begin(9600);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
} void loop() {
forward();
delay(1000);
backward();
delay(1000);
left();
delay(1000); right();
delay(1000); clockwise();
delay(1000);
anticlockwise();
delay(1000);
}
Result Analysis: We see that the buggy can easily move in forward, then backward, then left,
then right, then clockwise and then finally anticlockwise direction after a gap of 1 seconds.
Experiment 6
Objective: To read values of IR Sensor using analog and digital read and convert buggy into
normal line follower robo car.
Hardware Used: LED, Arduino microcontroller, Connecting wires, Breadboard, USB
connector, Resistor, buggy, IR sensor.
Software Used: Arduino IDE.
Theory: An IR sensor is a device that emits in order to sense some aspects of the surroundings
which detects IR radiation falling on it. The emitter is simply an IR LED (Light Emitting Diode) and
the detector is simply an IR photodiode which is sensitive to IR light of the same wavelength is
emitted by the IR LED. When IR light falls on the photodiode, the resistances and output voltages,
change in proportion to the magnitude of the IR light received. In our buggy, the IR sensor helps it
to move only on the black lines of our path defined. We use the user defined functions from the
previous experiment to control the movement of the buggy on the path in the Arduino IDE which in
turn gives the instructions to the IR sensor.
Code:
void setup() {
// put your setup code here, to run once:
pinMode(A0,INPUT); pinMode(A1,INPUT);
pinMode(5,OUTPUT); pinMode(6,OUTPUT);
pinMode(7,OUTPUT); pinMode(8,OUTPUT);
} void forward()
{ digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
} void right()
{ digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
} void left()
{
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
}
void loop() {
// put your main code here, to run repeatedly: int l,r;
l = digitalRead(A0); r =
digitalRead(A1); if(l==0 &&
r==0) forward(); else if(l==0
&& r==1) right(); else
if(l==1 && r==0)
left();
else if(l==1 && r==1)
forward();
}
Result Analysis: We can clearly see that our buggy moves on the
black path. We learned how to use the IR sensor on the buggy for sensing
the black and white color of signal. We also learned how to control the
movement on the buggy on the predefined path
Experiment: 7
Objective:
To demonstrate the use of ultrasonic sensor by integrating line follower robo car with
obstacle avoidance capability.
Hardware Used:
Arduino UNO, Ultrasonic sensor
Software Used:
Arduino IDE
Theory:
An Ultrasonic Sensor is a device that can measure the distance to an object by using sound
waves. It measures distance by sending out a sound wave at a specific frequency andlistening
for that sound wave to bounce back. By recording the elapsed time between the sound wave
being generated and the sound wave bouncing back, it is possible to calculate thedistance
between the sonar sensor and the object.
The HC-SR04 ultrasonic sensor uses sonar to determine distance to an object like bats do. It
offers excellent non-contact range detection with high accuracy and stable readings in an easy-
to- use package. It comes complete with ultrasonic transmitter and receiver module. Ultrasound
has several characteristics which make it so useful. Firstly, it is inaudible to humans and
therefore undetectable by the user. Secondly, ultrasound waves can be produced with high
directivity. Thirdly, they are a compression vibration of matter (usually air).Finally, they have
a lower propagation speed than light or radio waves.
Code:
#include<NewPing.h>
int echo=12;
int trig =13;
int m=0;
NewPing sonar(trig,echo,maxdist); int
h1,h2;
void setup() {
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(4,INPUT);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(echo,INPUT);
pinMode(trig,OUTPUT);
Serial.begin(9600);
void loop()
{
h1=digitalRead(A0);
h2=digitalRead(A1);
m=sonar.ping_cm();
if(m>0 && m<20)
stopBuggy();
delay(2000);
else{
if(h1==1 && h2==1)
{
forward();
}
else if(h1==0 && h2==0)
{
forward();
else if(h1==0 && h2==1)
{
left();
}
else if(h1==1 && h2==0)
{
right();
}
void stopBuggy()
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW}
void forward()
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
void right()
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
void left()
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
Result Analysis:
The ultrasonic sensor is connected to the buggy and we moved the buggy. By uploading the
code in the buggy, we tested this sensor by placing obstacles in front of the robot car and it
worked correctly.
Signature
Experiment: 8
Objective:
Write a program to read the pulse width of gantry transmitter and trigger stop_buggy
function by detecting individual gantry.
Hardware Used:
Arduino Board, Connecting Wires, Robot Car, Receiver Circuit, Ultrasonic Sensor.
Software Used:
Arduino Software (IDE)
Theory:
The gantries are equipped with three pulses of different bandwidth from the transmitter circuit.
The range of pulses can be changed by programming the 5 reprogrammable pins of ATtiny85
microcontroller used in the construction of transmitter circuit. The receiver circuitis connected
to buggy and programmed to do operations like stop buggy when it passes through the suitable
gantry and receives the corresponding pulse. In this way buggy stops after it passes the gantry
receiving the pulse from the transmitter connected to the gantry and if the pulse received is in
the range according to the code then the required function is performed by Buggy.
Code:
int t1=A0;
int t2=A2;
int pin5=5;
int pin6=6;
int pin7=8;
int pin8=7;
int pin=4;
int flag=0;
unsigned long d=0;
static ntgantryCounter=0;
static long StartTime=0;
static long CurrentTime =
0;
unsigned long ElapsedTime = 0;
static long StartTimeG=millis();;
static long CurrentTimeG = 0;
unsigned long ElapsedTimeG =
0; long previousMillisU =
millis(); long intervalU = 500;
#include <NewPing.h>
#define TRIGGER_PIN 13
#define ECHO_PIN 12
#define MAX_DISTANCE
200
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
void setup() {
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin7,OUTPUT);
pinMode(pin8,OUTPUT);
pinMode(t1,INPUT);
pinMode(t2,INPUT);
Serial.begin(9600);
Serial.print("+++"); delay(1500);
Serial.println("ATID 3333, CH C,
CN");
void loop()
{
if(flag==0)
if (Serial.available() > 0)
char s = Serial.read();
switch (s) {
case 'G':
flag=1;
unsigned long currentMillisU = millis();
if(currentMillisU -
previousMillisU>intervalU)
previousMillisU =
currentMillisU; detectObstacle();
if (flag==1)
gantry();
if (flag==3)
CurrentTimeG=millis();
ElapsedTimeG = CurrentTimeG-
StartTimeG; if(ElapsedTimeG<1500)
flag=3;
leftBlind();
if(ElapsedTimeG>1500 &&ElapsedTimeG<3500)
flag=3;
normalLineFollow();
if(ElapsedTimeG>3500)
stopBuggy();
Serial.print("Buggy:1
Parked");
Serial.println(ElapsedTimeG);
delay(2000)
; flag=-1;
void gantry()
int r1=digitalRead(t1);
int r2=digitalRead(t2);
if(r1==LOW&&r2==LO
W)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
if(r1==LOW&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);
if(r1==HIGH&&r2==LOW)
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
if(r1==HIGH&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
Void stopBuggy()
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);
void detectObstacle()
delay(50);
unsigned int distanceCm;
distanceCm = sonar.ping_cm();
pinMode(ECHO_PIN,OUTPUT);
digitalWrite(ECHO_PIN,LOW);
pinMode(ECHO_PIN,INPUT);
Serial.print("Ping: ");
Serial.println(distanceCm);
Serial.println("cm");
if((distanceCm<15) && (distanceCm>0))
stopBuggy();
delay(1000);
Result Analysis:
From this experiment, we get to understand the working of the gantry circuit along receiver
circuit. The pulse sends to the computer via receiver circuit which detects the pulse in the form
of a Square Wave Function. The time of the high pulse is obtained using pulseIn function along
with Serial.begin(9600).
Signature
Experiment: 9
Objective:
Write a program to control buggy in full supervisory mode using serial communication and
XCTU/C#.a
Hardwre Used:
Arduino Board, Connecting Wires, Robot Car, Zigbee module.
Software Used:
Arduino Software (IDE), XCTU.
Theory:
Zigbee is an IEEE 802.15.4-based specification for a suite of high-level communication protocols
used to create personal area networks with small, low-power digital radios, such as for home
automation, medical device data collection, and other low-power low-bandwidth needs, designed
for small scale projects which need wireless connection. Hence, Zigbee is a low-power, low data
rate, and close proximity (i.e., personal area) wireless ad hoc network.
The Xbee is the brand name a wireless transceiver device introduced by the Digi international
which works on the ZigBee protocol and can form PAN networks. The Xbee module even though
uses complex packet data based Zigbee protocol for communicating with each other; But also they
can communicate with other devices using simplest serial communication protocol and hence they
are widely used in microcontroller base boards.
Code:
void setup() {
Serial.begin(9600);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(4,INPUT);
}
void forward(){
digitalWrite(5,HIGH);
digitalWrite(8,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
void Stopp(){
digitalWrite(5,LOW);
digitalWrite(8,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
}
void loop() {
if(Serial.available()>0){
char c=digitalRead(4);
if(c=='y'){
forward();
}
else if(c=='n'){
Stopp();
}
}
}
Signature
Experiment: 10
Objective:
Write configuration program to demonstrate Xbee module communication between two PC’s
using XCTU.
Hardware Used:
Arduino Board, Connecting Wires, Robot Car, Zigbee module.
Software Used:
Arduino Software (IDE), XCTU.
Theory:
Zigbee is an IEEE 802.15.4-based specification for a suite of high-level communication
protocols used to create personal area networks with small, low-power digital radios, such as
for home automation, medical device data collection, and other low-power low-bandwidth
needs, designed for small scale projects which need wireless connection. Hence, Zigbee is a
low-power, low data rate, and close proximity (i.e., personal area) wireless ad hoc network.
The Xbee is the brand name a wireless transceiver device introduced by the Digi international
which works on the ZigBee protocol and can form PAN networks. They have an approximate
range of 10 to 100 meters and are used in industries, scientific fields, medical fields etc. The
Xbee module even though uses complex packet data based Zigbee protocol for communicating
with each other; But also they can communicate with other devices using simplest serial
communication protocol and hence they are widely used in microcontroller base boards.
Code:
void setup()
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
Serial.begin(9600);
void forward()
digitalWrite(5,HIGH);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,HIGH);
void loop()
if(Serial.available()>0)
Char s
=Serail.read();
if(S== ‘G’)
forward();
}
else
digitalWrite(5,LOW);
digitalWrite(6,LOW);
digitalWrite(7,LOW);
digitalWrite(8,LOW);
Result Analysis:
From this experiment, we get to understand the working of the Xbee.We have connected the
Xbee to buggy and done its configuration on XCTU software. The coordinator will be attached
to the computer which will control the buggy and the router will be attached to the buggy.Then
after doing the configurations, we have controlled the movement of buggy from the computer
using Xbee communication.
Signature
Experiment: 11
Objective:
Write a Program to demonstrate full bronze challenge.
Hardware Used: Arduino Board, Connecting Wires, Robot Car, Receiver Circuit,
Ultrasonic Sensor, Zigbee Module.
Software Used: Arduino software (IDE), XCTU.
Theory:
Bronze Challenge: Single buggy capable of following main track twice in an clockwise
direction under full supervisory control. Buggy must be capable of detecting an obstacle whilst
following the track, coming to a halt if it does. The buggy must safely park in the parking bay.
It prints the state of the track and buggy at each gantry stop. No external end- user manual
control input is permitted once the initial start is signalled.
Code:
int t1=A0;
int t2=A2;
int pin5=5;
int pin6=6;
int pin7=8;
int pin8=7;
int irPin=4;
int flag=0;
int inside = 0;
unsigned long d=0;
static int gantryCounter=0;
static long StartTime=0;
static long CurrentTime = 0;
unsigned long ElapsedTime = 0;
static long StartTimeG=millis();;
static long CurrentTimeG = 0;
unsigned long ElapsedTimeG = 0;
long previousMillisU = millis();
long intervalU = 500;
#include <NewPing.h>
#define TRIGGER_PIN 13
#define ECHO_PIN 12
#define MAX_DISTANCE 200
NewPing sonar(TRIGGER_PIN, ECHO_PIN,
MAX_DISTANCE); void setup() {
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin7,OUTPUT);
pinMode(pin8,OUTPUT);
pinMode(t1,INPUT);
pinMode(t2,INPUT);
Serial.begin(9600);
Serial.print("+++"); // Enter Xbee AT command mode, NB no carriage return here
delay(1500); // Guard time
Serial.println("ATID 3333, CH C, CN");
}
void loop()
{
if(flag==0)
if (Serial.available() > 0)
char s = Serial.read();
switch (s) {
case 'K':
flag=1;
unsigned long currentMillisU = millis();
if(currentMillisU - previousMillisU > intervalU)
previousMillisU = currentMillisU;
detectObstacle();
if (flag==1)
gantry();
}
if (flag==3)
int r1=digitalRead(t1);
int r2=digitalRead(t2);
if (r1 == LOW && r2 == LOW)
if (inside == 0)
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
inside = 1;
delay(200);
else
stopBuggy();
delay(100000);
else
normalLineFollow();
}}}
void gantry()
int r1=digitalRead(t1);
int r2=digitalRead(t2);
if(r1==LOW&&r2==LOW)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW)
if(r1==LOW&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);
if(r1==HIGH&&r2==LOW)
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
}
if(r1==HIGH&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
if (digitalRead(irPin)==HIGH)
StartTime = millis();
d = pulseIn(irPin,HIGH);
if (d>500 and d<1500) //(d > 500 and d < 1500)
Serial.println(d);
Serial.println("Gantry: 1");
stopBuggy();
delay(1000);
if(r1==HIGH&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
delay(300);
gantryCounter=gantryCounter+1;
}
else if (d>1500 and d< 2700) //(d> 1500 and d < 2500)
Serial.println(d);
Serial.println("Gantry: 2");
stopBuggy(); delay(1000);
if(r1==HIGH&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
delay(300);
gantryCounter=gantryCounter+1;
else if (d>2500 and d<3500) //(d > 2500 and d < 3500)
Serial.println(d);
stopBuggy();
Serial.println("Gantry: 3");
delay(1000);
if(r1==HIGH&&r2==HIGH
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
delay(300);
gantryCounter=gantryCounter+1;
else {
//Serial.println(d);
Serial.println("Gantry: Unknown");
Serial.print("The gantry Counter is: ");
Serial.println(gantryCounter); if
(gantryCounter>=2)
flag=3;
else
gantry();
}
void stopBuggy()
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);
void normalLineFollow()
int r1=digitalRead(t1);
int r2=digitalRead(t2);
if(r1==LOW&&r2==LOW)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
if(r1==HIGH&&r2==LOW)
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
} if(r1==LOW&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);
if(r1==HIGH&&r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
void leftBlind()
int r2=digitalRead(t2);
if(r2==LOW)
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
}
if(r2==HIGH)
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);
void detectObstacle()
delay(50);
unsigned int distanceCm;
distanceCm = sonar.ping_cm();
pinMode(ECHO_PIN,OUTPUT);
digitalWrite(ECHO_PIN,LOW);
pinMode(ECHO_PIN,INPUT);
Serial.print("Ping: ");
Serial.println(distanceCm);
Serial.println("cm");
if((distanceCm<15) && (distanceCm>0))
stopBuggy();
delay(1000);
}
Result Analysis:
We have successfully completed the Bronze challenge by using various sensors like IR
sensors, ultrasonic sensors, receiver circuit and ZigBee module.
Signature