0% found this document useful (0 votes)
92 views28 pages

CourseContent - IoT and ML Training Bolt

The program reads the pulse width from a gantry transmitter circuit and uses it to control a robotic buggy. It detects individual gantries using an Arduino board connected to sensors. Based on the pulse width, it triggers functions like stopping the buggy, normal line following, or left-blind line following. The goal is to demonstrate obstacle avoidance and parking the buggy at different points along the track defined by the gantry locations.

Uploaded by

Rizul
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)
92 views28 pages

CourseContent - IoT and ML Training Bolt

The program reads the pulse width from a gantry transmitter circuit and uses it to control a robotic buggy. It detects individual gantries using an Arduino board connected to sensors. Based on the pulse width, it triggers functions like stopping the buggy, normal line following, or left-blind line following. The goal is to demonstrate obstacle avoidance and parking the buggy at different points along the track defined by the gantry locations.

Uploaded by

Rizul
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/ 28

A

Practical Activity Report


Submitted for

ENGINEERING DESIGN-III (UTA011)

By

Dinmani Malhan 101608048


Divyanshu Bhatia 101608049
Divyaraj Singh 101608050
Gagan Bansal 101608052

Submitted to

Dr. Raman Singh

COMPUTER SCIENCE AND ENGINEERING DEPARTMENT


THAPAR UNIVERSITY, PATIALA-147004, PUNJAB
INDIA
July-December 2017

Page | 1
TABLE OF CONTENT

Sr.no. Exercise Page no.

1. To demonstrate the use of ultrasonic sensor by integrating line follower 3


robo car with obstacle avoidance capability.

2. Write a program to read the pulse width of gantry transmitter and 7


trigger stop_buggy function by detecting individual gantry.

3. Write a C# Sharp program that takes three letters as input and display 11
them in reverse order on console.

4. Write a program to control buggy into full supervisory mode using 13


serial communication.

5. WAP to demonstrate full bronze challenge. 17

6 Write a program to demonstrate silver/gold challenge. 24

Page | 2
EXERCISE 1
Aim: To demonstrate the use of ultrasonic sensor by integrating line follower robo car with
obstacle avoidance capability.

Hardware used- Ultrasonic sensor, robotic buggy.

Software used- Arduino IDE.

Theory: UltrasonicTransducers are transducers that convert ultrasound waves to electrical


signals or vice versa. Those that both transmit and receive may also be called ultrasound
transceivers; many ultrasound sensors besides being sensors are indeed transceivers because
they can both sense and transmit. These devices work on a principle similar to that of transducers
used in radar and sonar systems, which evaluate attributes of a target by interpreting the echoes
from radio or sound waves, respectively. Active ultrasonic sensors generate high-frequency
sound waves and evaluate the echo which is received back by the sensor, measuring the time
interval between sending the signal and receiving the echo to determine the distance to an object.
Passive ultrasonic sensors are basically microphones that detect ultrasonic noise that is present
under certain conditions, convert it to an electrical signal, and report it to a computer.

ULTRASONIC SENSOR HC-SR04

Working : The Ultrasonic Sensor sends out a high-frequency sound pulse and then times how
long it takes for the echo of the sound to reflect back. The sensor has 2 openings on its front. One
opening transmits ultrasonic waves, (like a tiny speaker), the other receives them, (like a tiny
microphone). The speed of sound is approximately 341 meters (1100 feet) per second in air. The
ultrasonic sensor uses this information along with the time difference between sending and
receiving the sound pulse to determine the distance to an object. It uses the following
mathematical equation:

Distance = Time x Speed of Sound divided by 2


Time = the time between when an ultrasonic wave is transmitted and when it is received. You
divide this number by 2 because the sound wave has to travel to the object and back.

Page | 3
Program :

int lmotor=5;

int lmotorb=6;

intrmotor=7;

intrmotorf=8;

const int trigpin=13;

cons tint echopin=12;

void setup(){

pinMode(trigpin,OUTPUT);

pinMode(lmotorf,OUTPUT);

pinMode(lmotorb,OUTPUT);

pinMode(rmotorb,OUTPUT);

pinMode(rmotorf,OUTPUT);

pinMode(echopin,INPUT);

Serial.begin(9600);

void loop(){

digitalWrite(trigpin,LOW);

delayMicroseconds(2);

digitalWrite(trigpin,HIGH);

Page | 4
delayMicroseconds(10);

digitalWrite(trigpin,LOW);

long duration,cm;

duration= pulseIn(echopin,HIGH);

cm=microsecondsTOCentimeters(duration);

Serial.print(cm);

delay(500);

if(cm<=10){

stop();

else{

forward();

Long microsecondsTOCentimeters(long microseconds)

return microseconds/29/2;

void stop(){

digitalWrite(lmotorf,LOW);

digitalWrite(lmotorb,LOW);

Page | 5
digitalWrite(rmotorb,LOW);

digitalWrite(rmotorf,LOW);

delay(500);

void forward(){

digitalWrite(lmotorf,HIGH);

digitalWrite(lmotorb,LOW);

digitalWrite(rmotorb,LOW);

digitalWrite(rmotorf,HIGH);

delay(500);

Result : The Experiment to make obstacle avoiding Robo Car was done.

Signature of Faculty member

Page | 6
EXERCISE-2
Aim: Write a program to read the pulse width of gantry transmitter and trigger stop_buggy
function by detecting individual gantry.
Hardware Used: Arduino/Genuino board, connecting wires, Robocar, Receiver Circuit,
Ultrasonic sensor.
Software Used: Arduino software (IDE)
Program:
int t1=A0;
int t2=A2;
int pin5=5;
int pin6=6;
int pin7=8;

int pin8=7;
int irPin=4;
int flag=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)
{

Page | 7
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)
{
//gantryParking();
CurrentTimeG=millis();
ElapsedTimeG = CurrentTimeG-StartTimeG;

if(ElapsedTimeG<1500)
{
flag=3;
leftBlind();
}
if(ElapsedTimeG>1500 && ElapsedTimeG<3500)
{
flag=3;
normalLineFollow();
}
if(ElapsedTimeG>35
00)
{
stopBuggy();
Serial.print("Buggy:1 Parked");
Serial.println(ElapsedTimeG);
delay(2000);
flag=-1;
}

}
}

void gantry()
{
int r1=digitalRead(t1);

Page | 8
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);

}
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);

Page | 9
} 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);

Result:
From this experiment we get to understand the working of the gantry circuit along receiver
circuit.
Which send the pulse to the computer via receiver circuit which detects the pulse via MBD311D
diode and feeds it to the computer , in the form of a Square Wave Function from which the time
of the high pulse is obtained using pulseIn function along with Serial.begin(9600) (which gives
communication rate). And from this time along with its condition statements we operate the
Working of the Buggy.

Signature of Faculty member

Page | 10
EXERCISE – 3
Aim: Write a C# Sharp program that takes three letters as input and display them in reverse
order on console.

Program:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.IO.Ports;

namespace basicsendreceive
{
class Program
{
static void Main(string[] args)
{
SerialPort port = new SerialPort();
port.PortName = "COM14"; // Tells the
computer what COM port the XBee is attached to
port.BaudRate = 9600; // Sets baud rate
port.Open();

// Set the PAN ID to 3333


port.Write("+++");
Thread.Sleep(1100); // Guard Time
port.WriteLine("ATID 3333, CH C, CN");
Thread.Sleep(1100); // Guard Time
port.DiscardInBuffer(); // Get rid of OKs from the AT commands

// attach event handler after the AT commands


port.DataReceived += new
SerialDataReceivedEventHandler(port_OnReceiveData);
Console.Write(" BUGGY CONTROL MODE\n");
Console.Write("F: NORMAL LINE FOLLOW\n");
Console.Write("G: GANTRY MODE\n");
Console.Write("P: PARKING IN GANTRY MODE\n");
Console.Write("S: STOP THE BUGGY\n");
Console.Write("> "); // Prompt User

while (true) // Loop forever


{
port.Write(Console.ReadLine()); // This blocks the loop as
it's waiting for input
}
}

// Event handler that fires whenever data is received on the COM port
//
static void port_OnReceiveData(object sender,
SerialDataReceivedEventArgs e)
{
SerialPort castedPort = (SerialPort) sender;

Page | 11
String inData = castedPort.ReadLine();
// string inData = castedPort.ReadExisting();

Console.WriteLine("> " + inData);


Console.Write("> "); // Prompt User

}
}
}

Result: In this exercise we make a program in C# language in Microsoft Visual studio to take 3
letters in input and display them in output.

Signature of Faculty member

Page | 12
EXERCISE 4

Aim: Write a program to control buggy into full supervisory mode using serial communication.

Hardware Used: NVIS3302ARD Robocar kit, Zigbee, usb converter


Software Used: Arduino IDE
Theory : Zigbee is the brand name of a family of form factor compatible radio modules from
Digi International. The first Zigbee radios were introduced under the MaxStream brand in 2005
and were based on the IEEE 802.15.4-2003 standard designed for point-to-point and star
communications at over-the-air baud rates of 250 kbit/s.

Two models were initially introduced — a lower cost 1 mw Zigbee and the higher power 100
mW Zigbee-PRO. Since the initial introduction, a number of new Zigbee radios have been
introduced and all Zigbees are now marketed and sold under the Digi brand.

ZIGBEE

The Zigbees can operate either in a transparent data mode or in a packet-based application
programming interface (API) mode. In the transparent mode, data coming into the Data IN (DIN)
pin is directly transmitted over-the-air to the intended receiving radios without any modification.
Incoming packets can either be directly addressed to one target (point-to-point) or broadcast to
multiple targets (star). This mode is primarily used in instances where an existing protocol
cannot tolerate changes to the data format. AT commands are used to control the radio’s settings.
In API mode the data are wrapped in a packet structure that allows for addressing, parameter
setting and packet delivery feedback, including remote sensing and control of digital I/O and
analog input pins.

This project is used as a means for wireless communication. The zigbee is a wireless technology
that has been used here to control the movements of the buggy from our serial monitor. In this
experiment, we calibrate the coordinator and the router to be used for zigbee communication.
Then these are used to control the movements of the buggy car wirelessly just by giving
commands on our computer. There are two modes of communication- AT and API. AT is used
for controlling a single buggy car while API mode can establish communication with various
robocars.
Procedure : 1. Compile and upload the sketch to the buggy.

Page | 13
2. Calibrate the coordinator of the zigbee using XCTU software.
3. Calibrate the router of the zigbee using XCTU software.
4. Place the coordinator and router in their respective positions.
5. Search for router in the XCTU software and connect it.
6. Search and connect the coordinator to this router.
7. Now, control the buggy movement using respective keys.

Precautions:
1. Calibrate the coordinator and router properly.
2. Properly set paths for communication.
3. Make sure the router and coordinator are connected in their respective places.

Program :
void setup()

Serial.begin(9600); //serial initlization here we are using 9600 baud rate.

pinMode(5, OUTPUT); // Right +ve


pinMode(6, OUTPUT); // Right –ve

pinMode (7, OUTPUT); // Left –ve

pinMode(8, OUTPUT); // Left +ve

//functions for forward, backward, Anti_Rotation, Clock_Rotation and stop


movements
void forward()

digitalWrite(5,HIGH); // Right +ve

digitalWrite(6,LOW); // Right -ve

digitalWrite(7,LOW); // Left -ve


digitalWrite(8,HIGH); // Left +ve
}
void Backward()

Page | 14
{

digitalWrite(5,LOW);

digitalWrite(6,HIGH);
digitalWrite(7,HIGH);

digitalWrite(8,LOW);
}
void Anti_Rotation()

{
digitalWrite(5,HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(6,LOW); // turn the LED on (HIGH is the voltage level)


digitalWrite(7,HIGH); // turn the LED on (HIGH is the voltage level)

digitalWrite(8,LOW); // turn the LED on (HIGH is the voltage level)


}

void Clock_Rotation()

digitalWrite(5,LOW); // turn the LED on (HIGH is the voltage level)

digitalWrite(6,HIGH); // turn the LED on (HIGH is the voltage level)


digitalWrite(7,LOW); // turn the LED on (HIGH is the voltage level)

digitalWrite(8,HIGH); // turn the LED on (HIGH is the voltage level)


}

void stops()

{
digitalWrite(5,LOW); // turn the LED on (HIGH is the voltage level)

digitalWrite(6,LOW); // turn the LED on (HIGH is the voltage level)

digitalWrite(7,LOW); // turn the LED on (HIGH is the voltage level)


digitalWrite(8,LOW); // turn the LED on (HIGH is the voltage level)
}

// the loop function runs over and over again forever


void loop()

char s=' ';


if(Serial.available()>0) //here we check serial data on serial port and then
read it.

Page | 15
{

s=Serial.read();

if(s=='F')
forward();

else if(s=='B')
{ Backward();

}
else if(s=='R')

{
Clock_Rotation();

}
else if(s=='L')

Anti_Rotation();

s=' ';
}

RESULT : The movement of the buggy was controlled wirelessly using computer.

Signature of Faculty member

Page | 16
EXERCISE – 5
Aim: To demonstrate full bronze challenge.
Software used: Arduino IDE.
Program:
// initialize digital pin motor as an output
int pin5=5;
int pin6=6;
int pin8=7;
int pin7=8;

int t1=A0;
int t2=A2;
int irPin=4;
int pathLoop=2;
int numGantry=3;
static int flag=0;
static int gantryCounter=0;
unsigned long d=0;
static long StartTime=0;
static long CurrentTime = 0;
unsigned long ElapsedTime = 0;
const int trigPin = 13;
const int echoPin = 12;
long duration;
long distanceCm;
//long distanceInch;
void setup() {
pinMode(pin5,OUTPUT);
pinMode(pin6,OUTPUT);
pinMode(pin7,OUTPUT);
pinMode(pin8,OUTPUT);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(t1,INPUT);
pinMode(t2,INPUT);
pinMode(irPin,INPUT);
//pathLoop = Serial.read();
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");

// the loop function runs over and over again forever

void loop()
{

if (flag==1)
{

Page | 17
normalLineFollow();

digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distanceCm = (duration*0.034)/2;
Serial.print("The disctance in CM is: ");
Serial.println(distanceCm);
if(distanceCm<15 && distanceCm>0 ) //here we set the object range 15cm.
{

stopBuggy();
delay(1000);
}

}
if (flag==2)
{
gantryMode();
pinMode(trigPin, OUTPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);
distanceCm = (duration*0.034)/2;
Serial.print("The distance in CM is: ");
Serial.println(distanceCm);
//distanceInch = duration*0.0133/2;

if(distanceCm<9) //here we set the object range 15cm.


{

stopBuggy();
delay(1000);

}
}

if (flag==3)
{
gantryParking();
CurrentTime=millis();
ElapsedTime = CurrentTime-StartTime;
if(ElapsedTime>6500)
{
stopBuggy();
flag=0;
}
}

Page | 18
int r1=digitalRead(t1);
int r2=digitalRead(t2);
if (Serial.available() > 0) //here we check serial data on serial port and
than read it.
{

// char s='G';

char s = Serial.read();
switch (s) {
case 'F':
{
normalLineFollow();
flag=1;
break;

}
case 'G':
{
gantryMode();
flag=2;
break;

case 'S':
{
flag=0;
stopBuggy();
break;
}

}
}

}
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,HIGH);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);

} if(r1==LOW&&r2==HIGH)
{

Page | 19
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,HIGH);
}
if(r1==HIGH&&r2==HIGH)
{
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);

}
/*digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;

//distanceInch = duration*0.0133/2;

if(distanceCm<15) //here we set the object range 15cm.


{

stopBuggy();
delay(1000);
flag=1;
}
else
{
normalLineFollow();
flag=1;

} */
}
void gantryMode()
{
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,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);

Page | 20
} if(r1==LOW&&r2==HIGH)
{
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)
{
gantryCounter=gantryCounter+1;
d = pulseIn(irPin,HIGH);
if(d > 500 and d < 1500)
{
// Serial.println(d);
Serial.println("Gantry: 1");

}
else if (d> 1500 and d < 2500)
{
// Serial.println(d);
Serial.println("Gantry: 2");

}
else if (d > 2500 and d < 3500)
{
// Serial.println(d);
Serial.println("Gantry: 3");

}
else {
// Serial.println(d);
Serial.println("Gantry: Unknown");

}
stopBuggy();
delay(2000);

if (gantryCounter==(numGantry*pathLoop))
{
StartTime = millis();
gantryParking();
flag=3;
}
else
{
flag=2;
}

Page | 21
}
/*digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;

if(distanceCm<15) //here we set the object range 15cm.


{

stopBuggy();
delay(1000);
flag=2;
}
else
{
gantryMode();
flag=2;

}*/
}

void gantryParking()
{
int r1=analogRead(t1);
int r2=analogRead(t2);
if(r1<50&&r2<50)
{
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);

}
if(r1>50&&r2<50)
{
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW);

} if(r1<50&&r2>50)
{
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);
digitalWrite(pin8,LOW);

}
if(r1>50&&r2>50)
{
digitalWrite(pin5,HIGH);
digitalWrite(pin6,LOW);
digitalWrite(pin7,HIGH);

Page | 22
digitalWrite(pin8,LOW);

}
flag=3;
/*digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distanceCm= duration*0.034/2;
distanceInch = duration*0.0133/2;

if(distanceCm<15) //here we set the object range 15cm.


{

stopBuggy();
delay(1000);
flag=0;
}*/
}

void stopBuggy()
{
digitalWrite(pin5,LOW);
digitalWrite(pin6,LOW);
digitalWrite(pin7,LOW);
digitalWrite(pin8,LOW); }

Signature of Faculty member

Page | 23
EXCRCISE-6
Aim: Write a program to demonstrate silver/gold challenge, if completed.
Hardware Used: Arduino/Genuino board, connecting wires, Robocar, Receiver Circuit,
Ultrasonic sensor, Zigbee Module.
Software Used: Arduino Software (IDE)
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;
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 'G':

Page | 24
{
flag=1;
}
}
}
}
unsigned long currentMillisU = millis();

if(currentMillisU - previousMillisU > intervalU)


{

previousMillisU = currentMillisU;
detectObstacle();
}

if (flag==1)
{
gantry();

if (flag==2)
{
//gantryParking();
CurrentTimeG=millis();
ElapsedTimeG = CurrentTimeG-StartTimeG;

if(ElapsedTimeG<2000)
{
flag=3;
leftBlind();
}
if(ElapsedTimeG>2000 && ElapsedTimeG<7500)
{
flag=3;
normalLineFollow();
}
if(ElapsedTimeG>7500)
{
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==LOW)
{
digitalWrite(pin5,HIGH);

Page | 25
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)
{
//Serial.println(d);
Serial.println("Gantry: 1");
stopBuggy();
delay(1000);
}
else if (d> 1500 and d < 2500)
{
// Serial.println(d);
Serial.println("Gantry: 2");
stopBuggy();
gantryCounter=gantryCounter+1;
Serial.print("The gantry Counter is: ");
Serial.println(gantryCounter);
stopBuggy();
delay(1000);
}
else if (d > 2500 and d < 3500)
{
// Serial.println(d);

Serial.println("Gantry: 3");

delay(1000);

Page | 26
}
else {
//Serial.println(d);
Serial.println("Gantry: Unknown");

if (gantryCounter>=2)
{
StartTimeG = millis();
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);

Page | 27
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:

Using this code we completed the silver/gold challenge.

Signature of Faculty member

Page | 28

You might also like