This project is made to achieve certain level of automation. It uses IR Sensors to detect the proximity of an obstacle and takes a left turn every time it encounters the same.
It can simulate a self driving car / self moving robot.
The simple working principle of an IR Sensor is to emit light (infrared) and sense it back when it reflects from an object. Internally, it is made up of photodiodes that are arranged in a forward bias configuration.
A pin Vout is taken just before the diode to provide a high or low signal to the microcontroller.
As the light intensity increases, the resistance increases, which in turn increases the drop across the diode.
This in conclusion makes voltage a function of light intensity.
1) obs_avoiding_prg.c
#include<reg51.h>
#include<stdio.h>
//OBSTACLE AVOIDING CONTROLLED CAR ON THE SIMPLEST LEVEL
/*
4 SPST Push Buttons
1 IR Proximity sensor
2-4 DC motors
1 L293D DC Motor IC
8051 MICRO CONTROLLER
use interrupt to override switch signal when obstacle is detected
*/
//IR PROXIMITY SENSOR PIN
sbit irrecpin=P3^7;
//MOTOR PINS
sbit motor1pin1=P2^0;
sbit motor1pin2=P2^1;
sbit motor2pin1=P2^2;
sbit motor2pin2=P2^3;
//SWITCHES
sbit bsw=P2^5;
sbit lsw=P2^6;
sbit rsw=P2^7;
void direction(int a, int b, int c, int d)
{
motor1pin1=a;
motor1pin2=b;
motor2pin1=c;
motor2pin2=d;
}
void init_interrupt() interrupt 0
{
int i=0;
for(;i<1000;i++);// Delay for getting a proper signal
direction(0,0,1,0);// Always turn left
}
void main()
{
TCON=0X02;// Low edge trigger interrupt
IE=0X81;// EA and External Interrupt 0 Enable
while(1)
{
if(bsw==0) direction(0,1,0,1);
else
if(lsw==0) direction(0,0,1,0);
else
if(rsw==0) direction(1,0,0,0);
else
direction(1,0,1,0);
}
}
#include<stdio.h>
//OBSTACLE AVOIDING CONTROLLED CAR ON THE SIMPLEST LEVEL
/*
4 SPST Push Buttons
1 IR Proximity sensor
2-4 DC motors
1 L293D DC Motor IC
8051 MICRO CONTROLLER
use interrupt to override switch signal when obstacle is detected
*/
//IR PROXIMITY SENSOR PIN
sbit irrecpin=P3^7;
//MOTOR PINS
sbit motor1pin1=P2^0;
sbit motor1pin2=P2^1;
sbit motor2pin1=P2^2;
sbit motor2pin2=P2^3;
//SWITCHES
sbit bsw=P2^5;
sbit lsw=P2^6;
sbit rsw=P2^7;
void direction(int a, int b, int c, int d)
{
motor1pin1=a;
motor1pin2=b;
motor2pin1=c;
motor2pin2=d;
}
void init_interrupt() interrupt 0
{
int i=0;
for(;i<1000;i++);// Delay for getting a proper signal
direction(0,0,1,0);// Always turn left
}
void main()
{
TCON=0X02;// Low edge trigger interrupt
IE=0X81;// EA and External Interrupt 0 Enable
while(1)
{
if(bsw==0) direction(0,1,0,1);
else
if(lsw==0) direction(0,0,1,0);
else
if(rsw==0) direction(1,0,0,0);
else
direction(1,0,1,0);
}
}
No comments:
Post a Comment