Components:
Tiva C Launchpad
1 Photoresistor
1k Resistor
Circuit Diagram:
Code: Note:
you can change the threshold value based on your photoresistor.
In case if you want to control some other device of choice,you can just change the following lines of code in the program
It uses interrupt method instead of polling method
Fast response and efficient
Filters noise, thus gives most accurate distance of the obstacle
Algorithm:
When we start the robot, it moves in a straight direction. This robot continuously scans over a range from 0 to 180 degrees.
90 degree -straight position
0 degree - right
180 degree - left
45 degree-right diagonal
135 degree- left diagonal
In case the robot encounters any obstacle in the straight path (90 degree), it stops and reverses itself for 10 cm. It then scans to the right(0 degree) then left(180 degree) and chooses the best path.
However, if it encounters an obstacle in the right diagonal(45 degree), it immediately checks for the left diagonal clearance and takes a turn in that direction. The same method can be applied for the left diagonal. Further, if it encounters a complete blockage over 180 degree then the robot stops.
Components used:
2- continuous servos
1 standard micro servo (To scan)
1- 5 V voltage regulator (LM7805)
1- 9 V battery
2- 10uF capacitor
1- HCSR04 ultrasonic sensor
1- USB power bank(optional)
Connections:
PC5 - Trigger pin of HCSR04
PC6 - Echo pin of HCSR04
PF1 - PWM5 - Left servo
PF2 - PWM6 - Right servo
PF3 - PWM7 - Standard servo
Power Supply to the board:
Note: You must connect the ground pin of LM7805 with the ground pin of launchpad. It is recommended to use separate power supply for servos and microcontroller as servos draw more amps during switching times which can not be supplied by the launchpad.
Working Video:
Program Logic:
Variables used..
int moveRightFrwd = 10;
int moveRightBcwd = 170;
int moveLeftFrwd = 170;
int moveLeftBcwd = 10;
int stopRight = 90;
int stopLeft = 90;
int Radarstop = 90;
int thresholdLimit = 18;
int diagThresholdLimit = 13;
int leftDistance, rightDistance,diagRightDistance,diagLeftDistance;
long distance;
int straightBlock=0;
int timeout;
Here I am providing the initialization routine that I have used.
void timer1InterruptRoutineForRobot()
{
//you can write the control program here
}
You must include the timer1InterruptRoutineForRobot() routine in startup_ccs.c file, corresponding to the timer1 interrupt vector. The timer should fire whenever the robot encounters an obstacle.
You can achieve this by checking the condition leftDistance <18|| rightDistance<18 (i.e thresholdLimit) diagRightDistance<13 || diagLeftDistance<13 (i.e diagThresholdLimit) in the timer routine.