2-Way Traffic Signal Controller

Description

It’s a 2-Way Traffic Signal Controller using 8051 microcontroller. It controls 6 lights (2 red, 2 yellow and 2 green) for 2-Way Traffic. It is an interesting and another basic learning project for student and hobbies.

Diagram

Detail

In this project 8051 microcontroller controls 6 traffic lights of 2-Way traffic. A fixed time is assigned to each green signal of each way. This is also simple project that uses 6 LEDs of 3 colors, 8051 microcontroller and an optional 5V power supply regulator part. It’s algorithm is as follows

1- Initially microcontroller will switche on both red LED lights of both ways and switches off all other LED lights of both ways.

2- Then wait for time defined by RESET_DELAY.

3- Now start servicing way 0 by switching yellow LED light of that way. Give delay of defined by YELLOW_DELAY.

4- Now switch off red and yellow LED lights of way 0 and switch on green of that way. Wait for green way 0 as defined by GREEN0_DELAY.

5- Switch off green and switch on yellow LED light for way 0. Give delay of defined by YELLOW_DELAY.

6- Switch off yellow and switch on red LED lights for way 0. Give delay of defined by RED_DELAY.

7- Now servicing of way 0 is complete and it is the time to service 2nd way that is way 1. Similarly we repeat steps from 2 to 6 for way 1 also.

8- After servicing of way 1 we once again start from way 0 as discussed earlier.

For basic operation & components used in an 8051 based microcontroller based systems see
8051 Basic LED Flasher.

Code

// Start of code.

///////////////////////////////////////////////////////////
// Company         : Micro Digital                       //
// Address         : Office # C7 Raza Plaza              //
//                   DAV College Road                    //
//                   Rawalpindi,                         //
//                   Pakistan.                           //
// Programmed By   : Rashid Mehmood                      //
// Project Name    : 2-Way Traffic Light Controller      //
// Crystal         : 24.000000 MHz                       //
// Microcontroller : AT89C2051-C51-C52-C55-S2051-S51-S52 //
///////////////////////////////////////////////////////////

// Header file for AT89x051 microcontrollers regiter definitions.
#include <AT89x051.h>

sbit R0 = P1^0;
sbit Y0 = P1^1;
sbit G0 = P1^2;
sbit R1 = P1^3;
sbit Y1 = P1^4;
sbit G1 = P1^5;

void delay_ms(unsigned int del)
{
	unsigned int i,j;
	for(i = 0; i < del; i ++)
		for(j = 0; j < 1275; j ++);
}

#define RESET_DELAY 	1000	// (aprox 1 second)
#define RED_DELAY 	1000	// (aprox 1 second)
#define YELLOW_DELAY	1000	// (aprox 1 second)
#define GREEN0_DELAY	2000	// (aprox 2 second)
#define GREEN1_DELAY	3000	// (aprox 3 second)

void main()
{
	// Initialize all lights////////
	// Switch on all red signals.
	R0 = R1 = 0;
	// Switch off all other signals.
	Y0 = Y1 = G0 = G1 = 1;
	delay_ms(RESET_DELAY);
	////////////////////////////////

	while(1)
	{

		// First service way 0.////////////////////

		// Switch on yellow of way 0.
		Y0 = 0;
		delay_ms(YELLOW_DELAY);


		// Switch off red and yellow of way 0 and 
		// switch on green of way 0.
		R0 = 1;
		Y0 = 1;
		G0 = 0;
		delay_ms(GREEN0_DELAY);
			
		// Switch off green of way 0 and 
		// switch on yellow of way 0;
		G0 = 1;
		Y0 = 0;
		delay_ms(YELLOW_DELAY);

		// Switch off yellow of way 0 and 
		// switch on red of way 0;
		Y0 = 1;
		R0 = 0;
		delay_ms(RED_DELAY);
		/////////////////////////////////////////

		
		// Now service way 1.////////////////////

		// Switch on yellow of way 1.
		Y1 = 0;
		delay_ms(YELLOW_DELAY);


		// Switch off red and yellow of way 1 and 
		// switch on green of way 1.
		R1 = 1;
		Y1 = 1;
		G1 = 0;
		delay_ms(GREEN0_DELAY);
			
		// Switch off green of way 1 and 
		// switch on yellow of way 1;
		G1 = 1;
		Y1 = 0;
		delay_ms(YELLOW_DELAY);

		// Switch off yellow of way 1 and 
		// switch on red of way 1;
		Y1 = 1;
		R1 = 0;
		delay_ms(RED_DELAY);
		/////////////////////////////////////////
	}
}

// End of code.

This code can also be executed on AT89C2051 microcontroller a small brother of AT89C51.

Related Projects

8051 Basic LED Flasher

Electronic Dice using 8051

8051 To Seven Segment Display Interfacing

More Projects