Automatic self parking smart car

 Block Diagram




Circuit Diagram







Main.h

#ifndef MAIN_H
#define MAIN_H
#include "includes.h"
#define PARKING_DEPTH 0.16 /* in Meters */
#define ITERATIONS 250
#define PARKING_DISTANCE 40 /* in Centimeters */
struct App {
volatile char AutoPark :1;
volatile char Moni :1;
volatile char Door :1;
volatile char Alco :1;
volatile char DispDoor :1;
volatile char DispAlco :1;
volatile char Back :1;
volatile char Front :1;
volatile char Obstacle :1;
volatile char FrontObstacle :1;
volatile char Parked :1;
};
//DEFINE FUNCTION PROTOTYPE
static void Init (void);
static void inittest (void);
static void DispTitle (void);
static void CheckAlco (void);
static void ChkDoor (void);
static void EXTINTinit (void);
static void Tmr2Init (void);
static int8u AutoPark (void);
static void ParkVehicle (void);
static void Unpark (void);
#endif
App.h

#ifndef _APP_H
#define _APP_H
/************* LCD CONFIGURATION ****************/
#define LCD_DDR DDRC
#define LCD_DATA_PORT PORTC
#define LCD_ENABLE_PIN PC3
#define LCD_REGISTER_SELECT_PIN PC2
#define DISPLAY_INIT 1
#define LCD_NSCRL 1
#define FLOAT_T0_STRING 1
#define DECIMAL_PRECISION 100
/******** LCD CONFIGURATION ENDS ****************/
/******** BUZZER: CONFIGURATION ****************/
#define BUZ_DDR DDRC
#define BUZ_PORT PORTC
#define BUZ_PIN PC1
#define OFF_TIME 100
/******** BUZZER CONFIGURATION ENDS ************/
/********* LED: CONFIGURATION ******************/
#define LED_DDR DDRC
#define LED_PORT PORTC
#define LED_PIN PC0
#define OFF_TIME 100
/******** LED CONFIGURATION ENDS *************/
/******** MOTOR CONFIGURATION *************/
#define MOT_PORT PORTA
#define MOT_DDR DDRA
#define M1_AN PA3
#define M1_CA PA4
#define M2_AN PA5
#define M2_CA PA6
/******** MOTOR CONFIGURATION ENDS *********/
/***** SERVO MOTOR CONFIGURATION *********/
#define SERVO_DDR DDRD
#define SERVO_PORT PORTD
#define SERVO1 PD5
/***** SERVO MOTOR CONFIGURATION END *****/
/******* ALCOHOL SENSOR CONFIG *********/
#define ALSENS_DDR DDRD
#define ALSENS_PORT PORTD
#define ALSENS_PPIN PIND
#define ALSENS_PIN PD2
/************************************/
/******* DOOR SENSOR CONFIG *********/
#define DOOR_SENS_PORT PORTD
#define DOOR_SENS_DDR DDRD
#define DOOR_SENS_PPIN PIND
#define DOOR_SENS_PIN PD7
/************************************/
/******* ULTRASONIC SENSOR PIN DEFINITION *******/
#define ULTSEN_DDR DDRA
#define ULTSEN_PORT PORTA
#define ULTSEN_PIN PINA
#define TRIG_PIN PA1
#define ECHO_PIN PA0
/*****************************************/
/******* IR SENSOR PIN DEFINITION ******/
#define IR_SENS_DDR DDRD
#define IR_SENS_PORT PORTD
#define IR_SENS_PPIN PIND
#define IR_SENS1_PIN PD4
#define IR_SENS2_PIN PD6
#define IR_SENSORS_2
/**************************************/
/*********** EXTERNAL INTERRUPT PINS *************/
#define INTDDR DDRD
#define INTPORT PORTD
#define INTPIN PIND
#define INT1_PIN PD3
/**********************************************/
#endif

Code

#include"main.h"
static struct App Flags;
int main(void) {
Init();
while (TRUE) {
if (Flags.Moni) {
CheckAlco();
ChkDoor();
MeasDist(0xcc);
Flags.Moni = FALSE;
}
if (Flags.AutoPark) {
beep(1,150);
if (Flags.Parked)
Unpark();
else
AutoPark();
Flags.AutoPark = FALSE;
}
sleep_cpu();
}
return 0;
}
static void Init(void) {
buzinit();
ledinit();
beep(2,100);
lcdinit();
IRSensInit();
AlcoSensInit();
DoorSensInit();
MotInit();
servoinit();
ultinit();
Tmr2Init();
EXTINTinit();
inittest();
DispTitle();
sei();
sleep_enable();
sleep_cpu();
}
static void DispTitle(void) {
lcdclr();
lcdws("Auto Parking Veh");
lcdr2();
lcdws("Distance:");
}
static int8u AutoPark(void){
int8u ParkDist = 0;
int16u Count = 0;
Flags.Parked = FALSE;
lcdclrr(1);
lcdws("Find'g Par Space");
Front();
lcdclrr(0);
while (++Count < ITERATIONS) {
if (MeasDist(0x80) > PARKING_DEPTH) {
if(++ParkDist > PARKING_DISTANCE) {
ParkVehicle();
Flags.Parked = TRUE;
return 1;
}
dlyms(100);
} else
ParkDist = 0;
lcdwint(0x88, ParkDist);
lcdwint(0x8c,Count);
}
lcdclrr(1);
lcdws("No Parking Dist");
MotStop();
beep(3,150);
dlyms(1000);
DispTitle();
}
static void ParkVehicle(void) {
int8u i;
lcdclr();
lcdws(" Distance Found");
beep(2,150);
Front();
dlyms(4000);
MotStop();
lcdr2();
lcdws(" Parking.");
Flags.Back = TRUE;
Strt2Left();
Back();
i = 0;
while (i < 100) {
if (!Flags.Obstacle) {
Back();
i++;
} else
MotStop();
dlyms(55);
}
Left2Strt();
Strt2Right();
i = 0;
while (i < 100) {
if (!Flags.Obstacle) {
Back();
i++;
} else
MotStop();
dlyms(55);
}
MotStop();
Right2Strt();
Mot1Aclk();
dlyms(750);
MotStop();
lcdclr();
lcdws("*****Parked*****");
Flags.Back = FALSE;
beep(3,150);
dlyms(2000);
DispTitle();
}
static void Unpark(void) {
int8u i;
lcdclr();
lcdws(" Unparking");
Back();
dlyms(750);
MotStop();
Strt2Right();
Flags.Front = TRUE;
i = 0;
while (i < 100) {
if (!Flags.FrontObstacle) {
Front();
i++;
} else
MotStop();
dlyms(47);
}
Right2Strt();
Strt2Left();
i = 0;
while (i < 100) {
if (!Flags.FrontObstacle) {
Front();
i++;
} else
MotStop();
dlyms(40);
}
Left2Strt();
dlyms(2000);
MotStop();
lcdclr();
lcdws("****UNPARKED****");
Flags.Parked = FALSE;
Flags.Front = FALSE;
beep(3,150);
dlyms(2000);
DispTitle();
}
static void inittest(void) {
lcdclr();
lcdws("Chk Alcol:");
if (ReadAlco()) {
lcdws(" NOT OK");
while (ReadAlco()) {
beep(1,100);
dlyms(2000);
}
} else {
lcdws(" OK");
dlyms(1000);
}
lcdclr();
lcdws("Chk Doors:");
if (DoorRead()) {
lcdws(" NOT OK");
while (DoorRead()) {
beep(1,100);
dlyms(2000);
}
} else {
lcdws(" OK");
dlyms(1000);
}
}
static void Tmr2Init(void) {
TCNT2 = 0;
TIMSK |= _BV(TOIE2); /* ENABLE OVERFLOW INTERRUPT */
TCCR2 |= _BV(CS22) | _BV(CS21) | _BV(CS20); /* PRESCALAR BY 1024 */
}
/* overflows at every 32msec */
ISR(TIMER2_OVF_vect) {
static int8u i, j, k, l;
TCNT2 = 0;
if (++i >= 156) i = 0;
switch(i) {
case 0: case 6: ledon(); break;
case 3: case 9: ledoff(); break;
}
if (!Flags.Moni && ++j >= 31) {
Flags.Moni = TRUE;
j = 0;
}
if (Flags.Alco || Flags.Door) {
if (++k >= 94)
k = 0;
switch (k) {
case 0: case 6: buzon(); break;
case 3: case 9: buzoff(); break;
}
}
if (Flags.Back) {
if (BackIRRead())
Flags.Obstacle = TRUE;
else
Flags.Obstacle = FALSE;
if (++l >= 31)
l = 0;
switch (l) {
case 0: case 6: buzon(); break;
case 3: case 9: buzoff(); break;
}
}
if (Flags.Front) {
if (FrntIRRead())
Flags.FrontObstacle = TRUE;
else
Flags.FrontObstacle = FALSE;
}
}
static void EXTINTinit(void) {
INTDDR &= ~_BV(INT1_PIN);
INTPORT |= _BV(INT1_PIN);
GICR |= _BV(INT1); //ENABLE EXTERNAL INTERRUPT
MCUCR |= _BV(ISC11); //FALLING EDGE INTERRUPT
}
ISR(INT1_vect) {
Flags.AutoPark = TRUE;
GICR |= _BV(INT1);
}
static void CheckAlco(void) {
if (ReadAlco()) {
if (!Flags.DispAlco) {
Flags.DispAlco = TRUE;
lcdclrr(1);
lcdws("Alcohol Consumed");
Flags.Alco = TRUE;
}
}else {
if (Flags.DispAlco) {
Flags.Alco = FALSE;
Flags.DispAlco = FALSE;
buzoff();
DispTitle();
}
}
}
static void ChkDoor(void) {
if (DoorRead()) {
if (!Flags.DispDoor) {
Flags.DispDoor = TRUE;
lcdclrr(1);
lcdws("Door Opened");
Flags.Door = TRUE;
}
}else {
if (Flags.DispDoor) {
Flags.Door = FALSE;
Flags.DispDoor = FALSE;
buzoff();
DispTitle();
}
}
}

Comments

Popular posts from this blog

How to make talking Voltmeter at home

How to make IR sensor, IR sensor circuit diagram

How to make voltmeter using Arduino