Tuesday, January 19, 2021

Automatic street lamp/light control using 8051 and sensor. IDE Keil c51 and Proteus simulator

  

Free online courses with Free Certificate

Keil c51:

DevC++ compiler(or IDE)

Download link: Click here

step-1: right click on "Keil uvision" and click on "run as administrator"


step-2: now go to project >> new project >> "project_name.uvproj"



step-3: select "at89c51" as shown below



step-3: now file >> new file



step-4: click on save as then save with "file_name.c" i.e. with ".c" extension



step-5: now copy code given below and paste and save it, as shown below




step-6: to the left side of window right click on "Source group 1" and then click on "add existing file to source group 1"



step-7: now click on project  >>  build target to compile this code i.e. to check if any error in code



step-8: to generate "hex file" of this code right click on "target 1" tab to the left side of your window and then click on "options for target 'target 1'... " as shown below



step-9: now change frequency to "11.0592MHz" and tick to "use on-chip ROM" as shown below



step-10: now in same window options click on output >> tick to "create hex file" as shown below



step-11: click again on "build target" to create "hex file" as shown below





Embedded C code :


Code without comments (for simplicity)

#include<reg51.h>

//3 IR sensors on streets

sbit sensor1=P1^0;

sbit sensor2=P1^1;

sbit sensor3=P1^2;


//connections sensor for loads

sbit load1=P2^0;

sbit load2=P2^1;

sbit load3=P2^2;


void main()

{

load1=load2=load2=0;

sensor1=sensor2=sensor3=0; //optional logic based input we give

while(1)

{

if(sensor1==1)

{

load1=1; //street light 1 in ON

load2=load3=0;//street light 2&3 OFF

}

if(sensor2==1)

{

load2=1;//street light 2 in ON

load1=load3=0;//street light 1&3 OFF

}

if(sensor3==1)

{

load3=1;//street light 3 in ON

load1=load2=0;//street light 1&3 OFF

}

}

}

Free online courses with Free Certificate

Free online courses with Free Certificate

Free online courses with Free Certificate


Proteus:

Download linkClick here !


step: right click on "Proteus 8 professional"(whichever version available) and "run as administrator"

step: now go to project >> new project >> "New Project.pdsprj"


step: click on "P" and open window for "pick devices" as shown below


step: now type "at89c51" and select microcontroller then press ok


step: now add other components as shown below:

  1. Alternator as AC source :


2. BC547 Transistor as Switch to control Relay:


3. Button as Sensing element :


4. Lamp as Street Light:



5. Relay as Controlling element to Lamp:


6. Add "Power" and "Ground" from "terminal" tab as shown below:


step: now final circuit as shown below




step: now double click on microcontroller symbol then "edit component" window will open. then click on "folder symbol" to select ".hex" file and change frequency to 11.0592MHz as shown below

Note- make sure you know path of ".hex" file generated through Keil c51 as shown below

e.g. - ..\..\..\Keil_v5\C51\Examples\my project\Objects\7segment 8051.hex


step: click on "play button" and check output as shown below






Note - you can change delay in code >> save .c file >> rebuilt then play simulation in proteus

Check actual simulation in GIF format as shown below





If you found any difficulty or any suggestions please comment below or contact me on "pangfreelearner@gmail.com".

And also visit my YouTube channel for "Free online courses with Free certificate" on below link.

Free online courses with Free Certificate

Join Facebook group for Free online courses with Free certificate

Join Facebook group


Thank you.

PANG.


No comments:

Post a Comment