Interfacing of Keypad with 8051 Microcontroller in Proteus
Hello friends, in today's post we are gonna have a look at Interfacing of Keypad with 8051 Microcontroller in Proteus ISIS. In the previous project, we have seen the Interfacing of LCD with 8051 Microcontroller and I have told there that LCD is a great debugging tool as we can print our data on it and can display different values and that's what is gonna done in today's post. Today, I will get the values from keypad and then question is how to know that we are getting the correct values. So in order to do so, we will display these values over LCD. So, that's how we are gonna use LCD as a debugging tool. As the debugging is concerned, there's another great tool for debugging which is called Serial port, we can also display these values over to Serial port. So, you should also read Serial communication with 8051 Microcontroller in Proteus ISIS, and try to display these keypad characters over to Serial port as a homework.
Anyways, let's come back to keypad, if you wanna read the keypad details then you should read Interfacing of keypad with Arduino in Proteus ISIS as I have mentioned all the basic details about keypad in that tutorial and I am not gonna repeat it. But as a simple recall, keypad works on matrix system like it has 4 columns and 4 rows so we will have total 8 pins through which we are gonna control these 16 buttons. So, let's get started with it.
Interfacing of Keypad with 8051 Microcontroller in Proteus ISIS
- Keypad is quite an easy and basic tool in embedded projects which is used in almost every kind of engineering project.
- Today, we will first design the Proteus Simulation and after that we will design the programming code for 8051 Microcontroller.
- The 8051 Microcontroller I have used is AT89C51 while the compiler I used for this microcontroller is keil uvision 3 and the simulation is designed in Proteus ISIS.
- So, let's get started with Proteus simulation:
Proteus Simulation
- Get the below components from Proteus components library and place it in your workspace.
- Now design a circuit in Proteus software as shown in below figure:
- Now as you can see in the above figure, I have used 4x4 keypad which has 4 rows and 4 columns and that's why there are total 16 buttons on it.
- So, I have connected 8 pins of keypad with Port 1 of 8051 microcontroller.
- LCD data pins are connected with Port 2 while the RS and E pins are connected to Port 3.
- So, now let's move to the programming code for Interfacing of keypad with 8051 Microcontroller.
Programming Code
- For programming purposes I have used Keil uvision 3 Compiler.
- Most of the code is quite similar to that for Interfacing of LCD with 8051 Microcontroller, so if you wanna read about that then read this post.
- The new code added in this post is about keypad which is as follows:
char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A
if (C1 == 0) { delay(10000); while (C1==0); return '7'; }
if (C2 == 0) { delay(10000); while (C2==0); return '8'; }
if (C3 == 0) { delay(10000); while (C3==0); return '9'; }
if (C4 == 0) { delay(10000); while (C4==0); return '/'; }
RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B
if (C1 == 0) { delay(10000); while (C1==0); return '4'; }
if (C2 == 0) { delay(10000); while (C2==0); return '5'; }
if (C3 == 0) { delay(10000); while (C3==0); return '6'; }
if (C4 == 0) { delay(10000); while (C4==0); return 'x'; }
RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C
if (C1 == 0) { delay(10000); while (C1==0); return '1'; }
if (C2 == 0) { delay(10000); while (C2==0); return '2'; }
if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
if (C4 == 0) { delay(10000); while (C4==0); return '-'; }
RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D
if (C1 == 0) { delay(10000); while (C1==0); return 'C'; }
if (C2 == 0) { delay(10000); while (C2==0); return '0'; }
if (C3 == 0) { delay(10000); while (C3==0); return '='; }
if (C4 == 0) { delay(10000); while (C4==0); return '+'; }
return 'n'; // Means no key has been pressed
}
- In the above function, which is READ_SWITCHES(), what we are doing is we are first checking the rows and after that for each row we are checking the columns.
- For example, if you have pressed the button "1" then it will detect that first ROW and the first COLUMN has gone LOW and it will print out 1 as shown in above code.
- That's how its reading all the 16 buttons, first detecting the Rows and then for each row detecting all the columns and then printing out the respective character.
- Quite simple, isn't it?
- So now, here's the complete code for the Interfacing of Keypad with 8051 Microcontroller:
#include<reg51.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void Return(void);
char READ_SWITCHES(void);
char get_key(void);
//*******************
//Pin description
/*
P2 is data bus
P3.7 is RS
P3.6 is E
P1.0 to P1.3 are keypad row outputs
P1.4 to P1.7 are keypad column inputs
*/
//********************
// Define Pins
//********************
sbit RowA = P1^0; //RowA
sbit RowB = P1^1; //RowB
sbit RowC = P1^2; //RowC
sbit RowD = P1^3; //RowD
sbit C1 = P1^4; //Column1
sbit C2 = P1^5; //Column2
sbit C3 = P1^6; //Column3
sbit C4 = P1^7; //Column4
sbit E = P3^6; //E pin for LCD
sbit RS = P3^7; //RS pin for LCD
// ***********************************************************
// Main program
//
int main(void)
{
char key; // key char for keeping record of pressed key
cct_init(); // Make input and output pins as required
lcdinit(); // Initilize LCD
writecmd(0x95);
writedata('w'); //write
writedata('w'); //write
writedata('w'); //write
writedata('.'); //write
writedata('T'); //write
writedata('h'); //write
writedata('e'); //write
writedata('E'); //write
writedata('n'); //write
writedata('g'); //write
writedata('i'); //write
writedata('n'); //write
writedata('e'); //write
writedata('e'); //write
writedata('r'); //write
writedata('i'); //write
writedata('n'); //write
writedata('g'); //write
writecmd(0xd8);
writedata('P'); //write
writedata('r'); //write
writedata('o'); //write
writedata('j'); //write
writedata('e'); //write
writedata('c'); //write
writedata('t'); //write
writedata('s'); //write
writedata('.'); //write
writedata('c'); //write
writedata('o'); //write
writedata('m'); //write
writecmd(0x80);
while(1)
{
key = get_key(); // Get pressed key
//writecmd(0x01); // Clear screen
writedata(key); // Echo the key pressed to LCD
}
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0xf0; //used for generating outputs and taking inputs from Keypad
P2 = 0x00; //used as data port for LCD
P3 = 0x00; //used for RS and E
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void writedata(char t)
{
RS = 1; // This is data
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writecmd(int z)
{
RS = 0; // This is command
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
/////////////////////////////////////////////////////
writecmd(0x38); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
void Return(void) //Return to 0 location on LCD
{
writecmd(0x02);
delay(1500);
}
char READ_SWITCHES(void)
{
RowA = 0; RowB = 1; RowC = 1; RowD = 1; //Test Row A
if (C1 == 0) { delay(10000); while (C1==0); return '7'; }
if (C2 == 0) { delay(10000); while (C2==0); return '8'; }
if (C3 == 0) { delay(10000); while (C3==0); return '9'; }
if (C4 == 0) { delay(10000); while (C4==0); return '/'; }
RowA = 1; RowB = 0; RowC = 1; RowD = 1; //Test Row B
if (C1 == 0) { delay(10000); while (C1==0); return '4'; }
if (C2 == 0) { delay(10000); while (C2==0); return '5'; }
if (C3 == 0) { delay(10000); while (C3==0); return '6'; }
if (C4 == 0) { delay(10000); while (C4==0); return 'x'; }
RowA = 1; RowB = 1; RowC = 0; RowD = 1; //Test Row C
if (C1 == 0) { delay(10000); while (C1==0); return '1'; }
if (C2 == 0) { delay(10000); while (C2==0); return '2'; }
if (C3 == 0) { delay(10000); while (C3==0); return '3'; }
if (C4 == 0) { delay(10000); while (C4==0); return '-'; }
RowA = 1; RowB = 1; RowC = 1; RowD = 0; //Test Row D
if (C1 == 0) { delay(10000); while (C1==0); return 'C'; }
if (C2 == 0) { delay(10000); while (C2==0); return '0'; }
if (C3 == 0) { delay(10000); while (C3==0); return '='; }
if (C4 == 0) { delay(10000); while (C4==0); return '+'; }
return 'n'; // Means no key has been pressed
}
char get_key(void) //get key from user
{
char key = 'n'; //assume no key pressed
while(key=='n') //wait untill a key is pressed
key = READ_SWITCHES(); //scan the keys again and again
return key; //when key pressed then return its value
}
- So, now upload this code to your keil and get the hex file.
- Upload this hex file to your Proteus software and run the simulation.
- Now if everything goes fine then you will get first screen as shown in below figure:
- Obviously our website link at the bottom, now when you press the buttons on Keypad then it will start displaying on the first row of LCD.
- Now I have pressed all the 12 buttons of keypad and they are shown on LCD as shown in below figure:
- Now you can see the keypad buttons are displayed on the LCD.
- Now you can download the Proteus Simulation along with hex file and code by clicking the below button.
Download Proteus Simulation with Code
That's all about Interfacing of Keypad with 8051 Microcontroller. Its not that difficult but if you have problems then ask in comments and I will try to resolve them. So, will meet in the next tutorial, till then take care. !!! :)
Interfacing of LCD with 8051 Microcontroller in Proteus ISIS
Hello friends, hope you all are fine and having fun with your lives. Today's post is about Interfacing of LCD with 8051 Microcontroller. In my previous post, we have seen How to do Serial Communication with 8051 Microcontroller, which was quite a basic tutorial and doesn't need much hardware attached to it. Now today we are gonna have a look at Interfacing of LCD with 8051 Microcontroller. LCD is always the basic step towards learning embedded as it serves as a great debugging tool for engineering projects.
LCD is also used almost in every Engineering Project for displaying different values. For example, if you have used the ATM machine, which you must have, then you have seen an LCD there displaying the options to select. Obviously that's quite a big LCD but still LCD. Similarly, all mobile phones are also equipped with LCDs. The LCD we are gonna use in this project is quite small and basic. It is normally known as the 16x2 LCD as it has rows and 2 columns for writing purposes. So, we are gonna interface that LCD with 8051 Microcontroller. The proteus Simulation along with hex file and the programming code in keil uvision 3 is given at the end of this post for download. If you are working with Arduino, then you should have a look at Interfacing of LCD with Arduino. The next level from LCD is Graphical LCD also known as GLCD, so if you wanna know more about that then you should read Interfacing of Arduino with GLCD. So, let's get started with it.
Interfacing of LCD with 8051 Microcontroller in Proteus ISIS
- First of all, we are gonna need to design the Proteus Simulation as we always did.
- After designing the simulation, we are gonna write our embedded code for 8051 Microcontroller.
- I will be designing the code in Keil uvision3 compiler and the 8051 Microcontroller I am gonna use is AT89C51.
- So, let's first get started with Proteus Simulation for interfacing of LCD with 8051 Microcontroller.
Proteus Simulation
- First of all, get the below components from the Proteus components Library and place them in your workspace.
- Now design a circuit in Proteus using these above components as shown in below figure:
- If you have read the previous tutorial, you have noticed a small change, which is the RESET button.
- Its a good thing to have a RESET button in your project. When you press this button, your 8051 Microcontroller will get reset and will start again.
- Moreover, we have added a 20x4 LCD. The data pins of this LCD are attached with Port 2, while the RS and enable pins are connected to 0 and 1 pins of Port 1.
- So, now let's design the programming code for interfacing of LCD with 8051 Microcontroller.
Programming Code
- For programming code I have used Keil uvision 3 software. I am gonna first explain the code in bits so let's get started with it.
- Before starting the LCD programming, let me clear few basic concepts.
- In LCD, there are two types of data, we need to sent.
- The first type is the command like we need to tell the LCD either to start from first column or second column so we need to place the LCD cursor at some point from where we need to start writing. So, this type of data is called commands to LCD.
- The second type of data is the actual data we need to print on the LCD.
- So first of all we send commands to the LCD like the cursor should go to second line and then we send the actual data which will start printing at that point.
- The first function, I have used is named as lcdinit() , this function will initialize the LCD and will give the initializing commands to it.
void lcdinit(void)
{
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
writecmd(0x38); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
- Now in this function I have used another function which is writcmd, which is as follows:
void writecmd(int z)
{
RS = 0; // => RS = 0
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
- In order to send the commands to LCD with 8051 Microcontroller, we have to make the RS pin LOW and then we send the data and make the Enable pin HIGH to LOW which I have done in the above writecmd() function.
- Next function, we have used is writedata() function, which is as follows:
void writedata(char t)
{
RS = 1; // => RS = 1
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
- So, if you check above two functions then its quite clear that when we send command to the LCD then we have to make RS pin 0 but when we need to send data to be printed on LCD then we need to make RS pin 1. That's the only thing worth understanding in interfacing of LCD with 8051 Microcontroller.
- Now below is the complete code for interfacing of LCD with 8051 Microcontroller and I think now you can get it quite easily.
#include<reg51.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void writecmd(int);
void writedata(char);
void ReturnHome(void);
//*******************
//Pin description
/*
P2 is data bus
P1.0 is RS
P1.1 is E
*/
//********************
// Defines Pins
sbit RS = P1^0;
sbit E = P1^1;
// ***********************************************************
// Main program
//
void main(void)
{
cct_init(); //Make all ports zero
lcdinit(); //Initilize LCD
writecmd(0x81);
writedata('w'); //write
writedata('w'); //write
writedata('w'); //write
writedata('.'); //write
writedata('T'); //write
writedata('h'); //write
writedata('e'); //write
writedata('E'); //write
writedata('n'); //write
writedata('g'); //write
writedata('i'); //write
writedata('n'); //write
writedata('e'); //write
writedata('e'); //write
writedata('r'); //write
writedata('i'); //write
writedata('n'); //write
writedata('g'); //write
writecmd(0xc4);
writedata('P'); //write
writedata('r'); //write
writedata('o'); //write
writedata('j'); //write
writedata('e'); //write
writedata('c'); //write
writedata('t'); //write
writedata('s'); //write
writedata('.'); //write
writedata('c'); //write
writedata('o'); //write
writedata('m'); //write
ReturnHome(); //Return to 0 position
while(1)
{
}
}
void cct_init(void)
{
P0 = 0x00; //not used
P1 = 0x00; //not used
P2 = 0x00; //used as data port
P3 = 0x00; //used for generating E and RS
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void writedata(char t)
{
RS = 1; // => RS = 1
P2 = t; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void writecmd(int z)
{
RS = 0; // => RS = 0
P2 = z; //Data transfer
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
delay(15000);
writecmd(0x30);
delay(4500);
writecmd(0x30);
delay(300);
writecmd(0x30);
delay(650);
writecmd(0x38); //function set
writecmd(0x0c); //display on,cursor off,blink off
writecmd(0x01); //clear display
writecmd(0x06); //entry mode, set increment
}
void ReturnHome(void) //Return to 0 location
{
writecmd(0x02);
delay(1500);
}
- So, place this code in your keil software and get the hex file.
- Upload this hex file in your Proteus software and Run it.
- If everything goes fine then you will get something as shown in below figure:
- Now, you can see we have printed our website address on the LCD with 8051 Microcontroller.
- You can print anything you wanna print on this LCD instead of our address.
- You can download the Proteus Simulation along with hex file and the programming code in keil uvision 3 by clicking on below button.
Download Proteus Simulation & Code
That's all for today, in the next post I am gonna share how to display custom characters on LCD with 8051 Microcontroller, because till now you can just display the simple characters like alphabets and numbers on it but can't display the custom characters like arrowhead etc. You should have a look at
LCD Interfacing with Microcontrollers, where I have combined all tutorials related to LCD. So stay tuned and have fun.
Serial Communication with 8051 Microcontroller in Proteus
Hello friends, hope you are having fun. In today's post, we will have a look at Serial Communication with 8051 Microcontroller in Proteus ISIS. In the previous post, we have seen a detailed post on LED Blinking Project using 8051 Microcontroller in Proteus ISIS, which was quite a simple tutorial. And I hope if you are new to 8051 Microcontroller then from that post you must have got some idea about C Programming of 8051 Microcontroller.
Now, today we are gonna go a little further and will have a look at Serial Communication with 8051 Microcontroller and we will also design the simulation of this project in Proteus ISIS software. 8051 Microcontroller also supports Serial port similar to Arduino and PIC Microcontroller. And the communication protocol is exactly the same as its a Serial Port. But obviously the syntax is bit different as we are not working in Arduino software or MPLAB. So let's get started with it.
Serial Communication with 8051 Microcontroller in Proteus
- Let's first have a little recall of Serial communication. In serial communication we have two pins which are named as TX and RX.
- TX pin is used for transmitting data while the RX pin is used for receiving data.
- So, our microcontroller has these two pins as it supports Serial Communication and these pins are located at Pin no 10 and 11 in AT89C52 Microcontroller, which I am gonna use today.
- First of all, we will design a Simulation of this project in which there will be 8 LEDs attached to Port 1 and by sending characters through Serial port, we will either turn these LEDs ON or OFF.
- After designing the Simulation, we will then design the programming code for 8051 Microcontroller and will test our result.
- So, let's get started with Proteus Simulation of Serial Communication with 8051 Microcontroller.
Proteus Simulation
- Open your Proteus software and get these components from your Proteus Component Library:
- Now, design a circuit for Serial Communication with 8051 Microcontroller in Proteus software as shown in below figure:
- Now in the above figure, I have used crystal Oscillator of 16MHz as I did in the previous post LED Blinking Project using 8051 Microcontroller and again the reset is pull Down.
- Next I have attached Virtual Terminal with TX and RX of 8051 Microcontroller, if you don't know about Virtual Terminal much then I suggest to read How to use Virtual Terminal in Proteus ISIS.
- Finally, I have attached the 8 LEDs on Port 1 so that we could check whether we are getting correct data or not.
- Now let's design the programming code.
Programming Code
- Now open your Keil micro vision 4 software and paste the below code into it.
#include <reg52.h>
#define Baud_rate 0xFD // BAUD RATE 9600
void SerialInitialize(void);
void SendByteSerially(unsigned char);
void cct_init(void);
sbit Appliance1 = P1^0;
sbit Appliance2 = P1^1;
sbit Appliance3 = P1^2;
sbit Appliance4 = P1^3;
sbit Appliance5 = P1^4;
sbit Appliance6 = P1^5;
sbit Appliance7 = P1^6;
sbit Appliance8 = P1^7;
void main()
{
cct_init();
SerialInitialize();
EA = 1;
ES = 1;
while(1) {;}
}
void cct_init(void) //initialize cct
{
P0 = 0x00; //not used
P1 = 0x00; //Used for Appliances
P2 = 0x00; //not used
P3 = 0x03; //used for serial
}
void SerialInitialize(void) // INITIALIZE SERIAL PORT
{
TMOD = 0x20; // Timer 1 IN MODE 2 -AUTO RELOAD TO GENERATE BAUD RATE
SCON = 0x50; // SERIAL MODE 1, 8-DATA BIT 1-START BIT, 1-STOP BIT, REN ENABLED
TH1 = Baud_rate; // LOAD BAUDRATE TO TIMER REGISTER
TR1 = 1; // START TIMER
}
void SendByteSerially(unsigned char serialdata)
{
SBUF = serialdata; // LOAD DATA TO SERIAL BUFFER REGISTER
while(TI == 0); // WAIT UNTIL TRANSMISSION TO COMPLETE
TI = 0; // CLEAR TRANSMISSION INTERRUPT FLAG
}
void serial_ISR (void) interrupt 4
{
//receive character
char chr;
if(RI==1)
{
chr = SBUF;
RI = 0;
}
P0 = ~P0; //Show the data has been updated
switch(chr)
{
case '1': Appliance1 = 1; SendByteSerially('k'); break;
case '2': Appliance2 = 1; SendByteSerially('k'); break;
case '3': Appliance3 = 1; SendByteSerially('k'); break;
case '4': Appliance4 = 1; SendByteSerially('k'); break;
case '5': Appliance5 = 1; SendByteSerially('k'); break;
case '6': Appliance6 = 1; SendByteSerially('k'); break;
case '7': Appliance7 = 1; SendByteSerially('k'); break;
case '8': Appliance8 = 1; SendByteSerially('k'); break;
case 'a': Appliance1 = 0; SendByteSerially('k'); break;
case 'b': Appliance2 = 0; SendByteSerially('k'); break;
case 'c': Appliance3 = 0; SendByteSerially('k'); break;
case 'd': Appliance4 = 0; SendByteSerially('k'); break;
case 'e': Appliance5 = 0; SendByteSerially('k'); break;
case 'f': Appliance6 = 0; SendByteSerially('k'); break;
case 'g': Appliance7 = 0; SendByteSerially('k'); break;
case 'h': Appliance8 = 0; SendByteSerially('k'); break;
default: ; break; //do nothing
}
RI = 0;
}
- You can see in the above code that baud rate we have used is 9600and we have used a switch case method for turning ON or OFF Leds.
- So, now what it will do is when you send 1 on Serial Monitor, it will turn ON the first LED and when you send "a" on Serial Terminal then it will turn OFF the first LED. The same will go on for 8 LEDs.
- Character 1,2,3,4,5,6,7,8 will turn ON the LEDs from 1 to 8 respectively.
- While the character a,b,c,d,e,f,g,h will turn OFF the LEDs from 1 to 8 respectively.
- For each command it will reply us back a single character which is "k". So in this way we are doing the two way communication i.e. sending as well as receiving the serial data.
- So, now after adding the code, get your hex file and then upload it to your Proteus Simulation and click the RUN button on your Proteus software.
- When you start your Proteus Simulation, all the LEDs will be OFF and the virtual terminal will be open as shown in below figure:
- So, now click in the Virtual Terminal and press 1 and the first LED will get ON and you will get k in response as shown in below figure:
- You can see in the above figure, I have pressed 1 and the first LED goes ON as well as we get a response "k" in the virtual Terminal.
- So, that's how we can turn ON or OFF LEDs so in the below figure, I have turned ON all the 8 LEDs.
- Now you can see in the above figure,all leds are on and the virtual terminal is showing k for 8 times as I have given 8 instructions.
- You can download the Proteus Simulation along with hex file and the programming code by clicking the below button.
Download Proteus Simulation and Code
So, that's how we can do Serial communication with 8051 Microcontroller. I don't think its much difficult but still if you have problems then ask in comments and I will resolve them. That's all for today and will meet in the next tutorial soon.
LED Blinking Project Using 8051 Microcontroller
Hello friends, hope you all are fine and having fun with your lives. In today's tutorial, we will see LED Blinking Project Using 8051 Microcontroller. I haven't yet posted any project or tutorial on 8051 Microcontroller. I have posted quite a lot of tutorials on Arduino and PIC Microcontroller, so today I thought of posting tutorials on 8051 Microcontroller. Its my first tutorial on it and I am gonna post quite a lot of tutorials on 8051 Microcontroller in coming week.
So, as its our first tutorial on 8051 Microcontroller that's why its quite a simple one and as we did in Arduino we will first of all have a look at LED Blinking Project Using 8051 Microcontroller. In this project, we will design a basic circuit for 8051 Microcontroller which involves crystal oscillator etc. The basic circuit of 8051 Microcontroller is quite the same as we did for PIC Microcontroller. After that, we will attach a small LED on any of its I/O pins and then will make it blink. I have also given the Proteus Simulation along with Programming code designed in keil uvision 4 for download at the end of this post. So, let's get started with it. :)
LED Blinking Project Using 8051 Microcontroller in Proteus ISIS
- I am gonna first design the simulation of LED Blinking Project using 8051 Microcontroller in Proteus ISIS, as you all know Proteus is my favorite simulation software.
- After designing the simulation, we will design the programming code for 8051 Microcontroller.
- In order to design the code we are gonna use Keil micro vision compiler and the version I have rite now is 4. So its keil micro vision 4 compiler for 8051 Microcontrollers.
- So let's first design the Proteus Simulation for LED Blinking PRoject Using 8051 Microcontroller.
Proteus Simulation for LED Blinking Project
- So, get these components from Proteus components library and place it in your workspace, these components are shown in below figure:
- So, now I hope you have got all these components, now design a circuit in your Proteus software as shown in below figure:
- Now you can see in the above image, I have used crystal oscillator of 16MHz which is used to provide frequency to 8051 Microcontroller.
- After that we have placed a 10k resistance in path of our Reset pin.
- LED is connected to first pin of Port 1 which is P1.0.
- So, now let's design the programming code for 8051 Microcontroller as we are done with the Proteus Simulation.
Keil Programming Code for LED Blinking Project
- Now as I have mentioned earlier, the compiler I have used for designing the programming code for LED Blinking Project is Keil micro vision 4.
- So I hope you have this installed on your computer and if not then must install it as otherwise you wont be able to compile this code, but I have also placed the hex file so that you can run the simulation easily.
- You can download them easily by clicking the Download buttons present at the end of this post.
- So now create a new project in your keil compiler and paste the below code in your c file.
#include<reg51.h>
sbit LED = P1^0;
void cct_init(void);
void delay(int a);
int main(void)
{
cct_init();
while(1)
{
LED = 0;
delay(30000);
LED = 1;
delay(30000);
}
}
void cct_init(void)
{
P1 = 0x00;
}
void delay(int a)
{
int i;
for(i=0;i<a;i++);
}
- Now let me explain this code a bit, first of all, I declare the pin1.0 as LED so that its easy to use it in our code in future.
- After that I declared two functions. One of them is the delay function which is just adding the delay, while the second function is for initialization of Port 1 as output port.
- While in the Main function, we have used the LED blinking code in which LED is ON and then OFF continuously and so that make it blink.
- Now after adding the code in your Keil software, compile it and get the hex file.
- Upload this hex file into your 8051 Microcontroller which I have used is AT89C52 and hit the RUN button.
- If everything's goes fine then you will get results as shown in below figure:
- Now click the below button to get the simulation and the programming code and let me know did it work for you. :)
Download Proteus Simulation & Keil Code
That's all for today, will come soon with new tutorial on 8051 Microcontroller so stay tuned and have fun. Cheers !!! :)
Scrolling Text on LED Matrix 8x8 using Arduino
Buy This Simulation
Hello friends, Hope you all are fine and having fun with your lives. In today's post, I am going to show How to display a Scrolling Text on LED Matrix 8x8 using Arduino in Proteus ISIS. We all know about LED Matrix but if you don't know then google it. :P LED Matrix is used to display long messages, the best thing about LED Matrix is you can combine then in serial way and can make it of any size you want. Like in this post I have combined 8 LED matrices and then displayed my message on them. I have given all the details here but as you can see we have done a great effort in designing this simulation so I haven't posted it free but have placed a very small amount of $20 on it and you can buy it quite easily from our shop by clicking the above button.
I have used Proteus software for the simulation purposes and have use Arduino board as a microcontroller. We know that Proteus doesn't support Arduino but we have a library for it. So, first of all, read Arduino library for Proteus so that you can easily add the Arduino board in your Proteus software and then must also read How to get Hex file from Arduino which we will be uploading in our Proteus software. Its quite easy and you will get it don't in the first attempt. Anyways let's get started with Scrolling Text on LED Matrix 8x8 using Arduino in Proteus ISIS.
Hardware Design of LED Matrix 8x8 using Arduino in Proteus ISIS
- First of all let's have a look on the hardware design of LED Matrix 8x8 using Arduino in Proteus ISIS, which is shown in below figure:
- So, if you have a closer look on it by clicking it then you can see I have used 8 LED matrices and have used MAX7219.
- MAX7219 is a shift register which is of real importance here, it takes data serially in and parallel out.
- It is also known by the name serial in parallel out shift register. We send data to it using single pin which is the data pin and this data is edge triggered by the clock pulse.
- So when our clock pulse goes from low to high the data is sent to the shift register.
- We have connected these shift registers in a row as you can see in above figure, the first register is connected to second register via Dout pin.
- So suppose I have connected two shift register then in this case now I am sending data to two shift register and my output will be of total 16 bits.
- So, in this way we can add as many shift registers as we want and here I have added total 8 shift registers so my output is total of 64 bits and I am controlling these 64 bits via single pin of Arduino which is data pin of course.
- Clock Pin and Load Pin are also used here which are used to send the data and then load it in sequence so in short using just 3 pins of Arduino I can control any number of shift register.
- Now, each shift register is controlling each LED Matrix 8x8 and the reason I am using 8 shift registers is because I am using 8 LED Matrix 8x8.
- It's a bit tricky but quite simple. So, now we have complete overview of this shift register and how it works, now let's move on to our simulation.
Scrolling Text on LED Matrix 8x8 using Arduino in Proteus ISIS
- First of all, download the Arduino library for LED Matrix 8x8 by clicking on the below button.
- Now design a complete circuit as shown in below figure in your Proteus ISIS software:
- Next thing you are gonna need is the code for Arduino board which is posted below, so copy it and paste it in your Arduino software:
#include <MD_MAX72xx.h>
#define MAX_DEVICES 8
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
MD_MAX72XX mx = MD_MAX72XX(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define SCROLL_DELAY 200
#define CHAR_SPACING 1
#define BUF_SIZE 75
char curMessage[BUF_SIZE];
char newMessage[BUF_SIZE];
uint8_t scrollDataSource(uint8_t dev, MD_MAX72XX::transformType_t t)
{
static char *p = curMessage;
static uint8_t state = 0;
static uint8_t curLen, showLen;
static uint8_t cBuf[8];
uint8_t colData;
switch(state)
{
case 0:
showLen = mx.getChar(*p++, sizeof(cBuf)/sizeof(cBuf[0]), cBuf);
curLen = 0;
state++;
if (*p == '\0')
{
p = curMessage;
}
case 1:
colData = cBuf[curLen++];
if (curLen == showLen)
{
showLen = CHAR_SPACING;
curLen = 0;
state = 2;
}
break;
case 2:
colData = 0;
curLen++;
if (curLen == showLen)
state = 0;
break;
default:
state = 0;
}
return(colData);
}
void scrollText(void)
{
static uint32_t prevTime = 0;
if (millis()-prevTime >= SCROLL_DELAY)
{
mx.transform(MD_MAX72XX::TSR);
prevTime = millis();
}
}
void setup()
{
mx.begin();
mx.setShiftDataInCallback(scrollDataSource);
mx.control(MD_MAX72XX::INTENSITY, 10);
strcpy(curMessage, "www.TheEngineeringProjects.com");
newMessage[0] = '\0';
}
void loop()
{
scrollText();
}
- Now after uploading the code in Arduino software, get the Hex file for Arduino and upload it in your Arduino board in Proteus ISIS.
- Now when you upload it to your Arduino board and run your simulation you will get something as shown in below figure:
- Now let's have a look at How it scrolls, I really have to work hard to make the below figure but it looks cool isn't it. :)
- So, that's how our website link is gonna scroll from right to left and you can scroll any kind of text.
- You can buy the complete simulation along with Arduino code and hex file by clicking on below button.
Buy this Proteus Simulation
That's all for today. I hope you guys get some knowledge out of it. Let's meet in the next tutorial, till then take care!!! :)
Interfacing of Keypad with Arduino
Hello friends, hope you all are fine and having fun with your lives. In today's post we will have a look at How to interface keypad with Arduino in Proteus ISIS. Keypad is used almost in every engineering project. If you even look around you will find keypad in many electronic appliances. For example, a simple ATM machine has a keypad on it using which enter our pin code and give commands to the ATM machine. Similarly, calculator also has keypad on it. So, in short there are numerous applications of keypad. You should also read the Real Life examples of Embedded Systems and you will find Keypad in them as well.
Keypad is used where you need to used numerical buttons or you need to use lots of buttons for sending commands so like in some application I need to use 10 buttons so instead of using separate 10 buttons I would prefer to use keypad instead as it will save a lot of time both in hardware as well as programming. So today we will have a detailed look on How keypad works and How we can Interface keypad with Arduino in Proteus ISIS. Proteus also gives keypad component in its database using which we can easily simulate it in Proteus and can save our time. So first simulate it and then design the hardware. After today's post I will also share an Automatic Lock system project using keypad. Anyways let's get started with Interfacing of Arduino with keypad:
How keypad works ??
- Keypad uses matrix system in order to work.
- For example, I am using a keypad which has 12 buttons on it as shown in below figure:
- Now you can see its a 12 button keypad so it has total 3 columns and 4 rows and similarly there are 7 pins to control these 12 buttons.
- So, the simple formula is total number of pins = Number of Rows + Number of Columns.
- Now if we look at the internal circuitry of this 12 button keypad then it will look something as shown in below figure:
- Columns and rows are connected with each other now suppose I press button "1" on the keypad then first row and the first column will get short and I will get to know that button "1" is pressed.
- Same is the case with other buttons, for example I press button "8" then second column and the third row will get short so this code will remain unique for each button.
- In simple words, on each button press different column and row will get short we need to detect which one gets short in order to get the pressed button.
Quite simple, isn't it ?? You should also have a look at these
Arduino Projects for Beginners. So that's how a keypad works, now let's have a look at How to Interface this keypad with Arduino in Proteus ISIS.
Interfacing of Keypad with Arduino in Proteus ISIS
- So, now we are gonna interface this keypad with Arduino in Proteus ISIS which is as always my favorite simulator.
- In Proteus design a circuit as shown in below figure:
- So, we have an Arduino UNO board along with keypad and LCD.
- So I have done the programming in such way that whenever you press any button on the keypad, it will get displayed on the LCD.
Note:
- Now, copy the below code and paste it in your Arduino software and get the hex file from it.
#include <LiquidCrystal.h>
#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {13, 12, 11}; //connect to the column pinouts of the keypad
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(20, 4);
lcd.setCursor(1,2);
lcd.print("www.TheEngineering");
lcd.setCursor(4,3);
lcd.print("Projects.com");
lcd.setCursor(0,0);
}
void loop() {
char key = keypad.getKey();
if (key) {
lcd.print(key);
}
}
- Now upload the hex file in your Arduino UNO in Proteus ISIS and hit the RUN button.
- If everything goes fine then you will get something as shown in below figure:
- Now, when you press any button on the keypad it will also appear on the LCD as shown in below figure:
That's all for today. In the coming post I am gonna share a small project in which we will design a automatic locking system using this keypad. So stay tuned and have fun. :)
Control Servo Motor with Arduino in Proteus
Hello friends, hope you all are fine and having fun with your lives. Today's post is about the Controlling of Servo Motor with Arduino in Proteus ISIS. Servo Motor is a common motor used in engineering projects for precise circular motion. We can move the servo motor at any desired angle, which is not possible in the case of other motors i.e. Stepper or DC.
For example, suppose I want to move an antenna at a precise angle of 47.5 degrees then if I use DC Motor, I have to use an encoder. So, in such cases instead of using a DC motor, I will prefer Servo Motor.
I have already posted Angle Control of Servo Motor using 555 Timer in which I have controlled servo motor using 555 timer and another tutorial about Controlling of Servo Motor using PIC Microcontroller in which I have controlled it with PIC16F877a. And today we are going to Control Servo Motor with Arduino and will design the simulation in Proteus ISIS.
First of all, we will have a look at simple control of servo motor with Arduino in Proteus ISIS and then we will check the control of the servo motor with Arduino using buttons in which we will move the servo motor to precise angles using buttons. So, let's get started with it. :)
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | Servo Motor | Amazon | Buy Now |
2 | Arduino Uno | Amazon | Buy Now |
Simple Control of Servo Motor with Arduino in Proteus
- First of all, open your Proteus ISIS software and design the below simple circuit.
- You should also have a look at these Proteus Libraries of Components.
- Servo Motor has three pins:
- First Pin is Vcc.
- Second Pin is Control Pin.
- Third Pin is GND.
- The center pin is the controlling pin and goes to any digital pin of Arduino. I have connected the control pin to pin # 4 of Arduino.
Arduino Code for Servo Motor Control
- The next thing we need to do is to design the code for Arduino. So, open your Arduino software and copy paste the below code in it.
#include <Servo.h>
Servo myservo;
int pos = 0;
void setup()
{
myservo.attach(4);
}
void loop()
{
for(pos = 0; pos <= 180; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 180; pos>=0; pos-=1)
{
myservo.write(pos);
delay(15);
}
}
- Now compile this code and get your hex file.
- It's the same code as given in the Servo folder of Examples in Arduino software.
- Upload your hex file to your Proteus Arduino board.
Note:
Proteus Simulation Results
- Now, run your simulation and you will see that your Servo motor will start moving from 90 degrees to -90 degrees and then back to 90 degrees and will keep on going like this, as shown in the below figures:
- Now when you start it, first of all, it will show Position A in the above figure then will move anticlockwise and pass the position B and finally will stop at Position C and then it will move clockwise and comes back to Position A after passing Position B.
- In this way, it will keep on moving between Position A and C.
- Till now we have seen a simple control of Servo Motor with Arduino in Proteus ISIS, now let's have a look at a bit complex control of servo motor with Arduino.
Control Servo Motor with Arduino using Push Buttons
- In the previous section, we have seen a simple Control of Servo Motor with Arduino in which we simply moved Servo motor from 90 degrees to -90 degrees and vice versa.
- Now I am going to control Servo motor using five push buttons and each push button will move the Servo motor to a precise angle.
- So, first of all, design a small design as shown in the below figure:
- I have added five buttons with Arduino and now with these five buttons, I will move the Servo motor to 90, 45, 0, -45 and -90 degrees. So, each button has its precise angle and it will move the motor to that angle only.
Arduino Code
- So, now the next thing is the code, copy paste the below code in your Arduino software and get the hex file:
#include <Servo.h>
Servo myservo;
int degree90 = 8;
int degree45 = 9;
int degree0 = 10;
int degree_45 = 11;
int degree_90 = 12;
void setup()
{
myservo.attach(4);
pinMode(degree90, INPUT_PULLUP);
pinMode(degree45, INPUT_PULLUP);
pinMode(degree0, INPUT_PULLUP);
pinMode(degree_45, INPUT_PULLUP);
pinMode(degree_90, INPUT_PULLUP);
}
void loop()
{
if(digitalRead(degree90) == LOW)
{
myservo.write(180);
}
if(digitalRead(degree45) == LOW)
{
myservo.write(117);
}
if(digitalRead(degree0) == LOW)
{
myservo.write(93);
}
if(digitalRead(degree_45) == LOW)
{
myservo.write(68);
}
if(digitalRead(degree_90) == LOW)
{
myservo.write(3);
}
}
- Upload this hex file to your Arduino board in Proteus and run the simulation.
Proteus Simulation Results
- Now press these buttons from top to bottom and you will get the below results:
- The above figure is quite self-explanatory but still, I explain a little.
- In the first figure, I pressed the first button and the motor moved to -90 degrees.
- In the second figure, I pressed the second button and the motor moved to -45 degrees.
- In the third figure, I pressed the third button and the motor moved to 0 degrees.
- In the fourth figure, I pressed the fourth button and the motor moved to 45 degrees.
- In the fifth figure, I pressed the fifth button and the motor moved to 90 degrees.
- In the sixth figure, all buttons are unpressed and the motor remained at the last position.
It was quite simple and hope I explained it properly. If you still have any questions then ask in the comments and I will try to resolve them. That's all for today, will see you guys in the next tutorial. Take care !!! :)
Arduino UNO PCB Design for Proteus ARES
Hello friends, hope you all are fine and having fun with your lives. Today's post, as the name suggests, is about Arduino UNO PCB Design in Proteus ARES. I have already posted Arduino Library for Proteus on my blog using which one can quite easily run Arduino simulation in Proteus.but what if you wanna do the Arduino UNO PCB design in Proteus, then you are lucky that you are reading this post. :)
In one of my projects, I have to design the PCB for Arduino in Proteus so I thought to also post it here so that others can download it as well. Normally PCB design is not required for Arduino and I usually get Atmega328 out of Arduino and use it separately but sometimes, depending on the requirements of your project, you may also need to place Arduino itself on the PCB so in such cases Arduino UNO PCB Design is required. Using this design you can place the Arduino on the PCB in upside down direction and then can take pins out and can use them as you want them to use. You should also have a look at How to do PCB Designing in Proteus ARES.
Let me give you a little introduction about Proteus ARES as I haven't posted much tutorials on it. When you install Proteus software in your computer then you get two exe files one is named as Proteus ISIS while the other one is named as Proteus ARES. If you need to test some electronic circuit i.e. need to design the simulation then you use Proteus ISIS and when you need to design the PCB design then its done in Proteus ARES. As here we are talking about the Arduino UNO PCB design so that's why we are using Proteus ARES. Here's the list of Top 10 PCB Design software. So, let's get started with it.
Arduino UNO PCB Design for Proteus ARES
- First of all, download this Arduino UNO PCB design, which I have designed in Proteus ARES.
Download Proteus ARES Design
- Once downloaded, then open the file and unrar it on your desktop.
- Now double click the file to open it, make sure you already installed the Proteus software.
- When you open it, it will look something as shown in below figure:
- Now select the whole PCB design, right click it and select Make package as shown in below figure:
- When you click on Make Package, a new pop up window will open up, as shown in below figure:
- Now in the New Package Name, you can give any name to it, as I have given Arduino Shield to it and can select any Package Category.
- After selecting these options, hit the OK button and this Arduino UNO PCB design will save in your Proteus ARES library as the name you gave it. Like mine is saved as Arduino shield.
- Now whenever you wanna use it, you simply need to search for it and it will come up.
- You can also attach it to your Arduino package in Proteus ISIS so that you simple design the circuit in Proteus ISIS and then design the PCB in Proteus ARES.
That's all for today, hope you got some knowledge out of it. It was quite easy but having any problems, ask in comments and I will help you out. Will see you guys in next tutorial. Till then take care :)
Intelligent Energy Saving System
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a complete project with you guys. Its an Intelligent Energy Saving System which I designed around two years ago. So, today I thought to share it so that others could also get benefit. In this project, I have used Arduino UNO board for programming purposes. Its not much complicated project but is the basic for many complex projects.
Energy, is a small word, but is the problem of whole world. Particularly when we are talking about electrical energy. IF you consume more electrical energy then you will get quite huge bill at the end of the month. :P So, there's always work done on reducing the consumption of electrical energy and also we compare energy costs from different providers. As a human, suppose you turn ON your room fan, then normally you forget to turn it OFF and thus your bill keeps on increasing. So in order to avoid this, automation is the only tool which comes in handy. Like there must be such system which automatically detects whether someone is still in the room or not and if there's no one then lights got OFF automatically. In this way, you can quite easily reduce your electricity cost. This same concept is presented in this project, let's have a complete look over it. :)
Overview of Intelligent Energy Saving System
- In this project, we have designed a complete room and used two inductive loads i.e. bulbs and one fan.
- Now the purpose of this project was to save the energy so we used two IR sensors for counting.
- Now, if there's no one present in the room then the loads will automatically turn OFF and when someone will enter in the room then the loads will automatically turn ON.
- Moreover, we have also added a counter functionality in it i.e. the project will also count the number of people present in the room.
- All these parameters will also display on the LCD attached with Arduino.
Components Used
I am mentioning here the components used in designing this project. I am not giving the exact values as you will get them in the circuit diagrams. Here's the list:
- Arduino UNO
- IR Sensors
- 16 x 2 LCD
- 100W Bulbs
- 12V Fan
- 2 Relay Board
- 7805 (IC Regulator)
- LED (Indication)
- Resistance
- Capacitors
Circuit Diagrams of Intelligent Energy Saving System
Suppose you are designing this project then the first thing you are gonna need is the circuit diagrams for the project so here I am gonna show you all the circuit diagrams step by step so let's start:
1: Interfacing of Arduino with LCD
- First thing we are gonna need is the interfacing of Arduino with LCD. LCD used in this project is 16 x 2.
- I have first designed the simulation in Proteus as its always better to design the simulation before going into real hardware.
- Now upload the below code into it, just to test that whether its working fine or not:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
lcd.print("www.TheEngineer");
lcd.setCursor(0,1);
lcd.print("ingProjects.com");
}
void loop() {}
- Now run it and if everything's gone fine then you will get something as shown in below figure:
Note:
2: Circuit diagram of 2 Relay Board
- Next thing we are gonna need is the two relay board. Using these relays we are gonna turn ON or OFF our loads.
- Here's the circuit diagram for 2 relay board.
- As you can see in the above figure, I have used two relay board, where both the relays are controlled bt simple logic operators.
- Now instead of these logic operators, you need to give Arduino Pins here.
- I have made the first relay ON while the second relay is OFF.
- In the above figure, relay outputs are open so you can place anything here as its gonna act as switch. So, in our case the loads will be placed after this relay.
3: Circuit Design of Buzzer
- Next circuit design which we need to understand is the buzzer circuit design.
- Its quite simple and similar to 2 relay board. I have also published a detailed post on How to Design a Buzzer in Proteus ISIS, which will be quite helpful.
- Here' I am gonna explain it lightly, so let's have a look at the circuit diagram of buzzer:
- You can quite easily understand the above figure, where I have shown both the ON and OFF states of buzzer.
4: Circuit Diagram of IR Sensor:
- In this project, I have used two IR sensors, both are placed on the door one after another. You can read more about the designing of IR Sensor on my post Circuit Diagram of IR Sensor using 555 Timer.
- I have named them Entering IR Sensor and Leaving IR Sensor.
- The logic behind these two sensors is that, when someone enters in the room then he will first pass the Entering IR Sensor and then will hit the Leaving IR Sensor and if someone is leaving the room then he will first pass the Leaving IR Sensor and then will cut the Entering.
- So, in this way I am counting the persons if someone entering in the room I simply increment and if someone's leaving then I decrement.
- Now, if number of people in the room becomes zero then I turn OFF all the lights and the fan, and if there even one person in the room then I turn ON the lights and fan.
- Here's the circuit diagram of IR Sensor:
- IR transmitter and Receiver are not available in Proteus so that's why I have used the button so when you press the button, its like someone cut the beam of IR sensor, and you will get below result:
5: Complete Circuit Diagram of Intelligent Energy Saving System
- Now that we have designed the individual circuit diagrams, next thing we are gonna do is the assembly of complete project.
- So, here's the complete circuit diagram of this project:
- As you can see in the above figure, I have used two IR Sensors. The first IR Sensor is for entering in the room while the IR sensor is for leaving the room.
- Next is the buzzer circuit which is also quite simple and I have explain in detail above.
- LCD will display the no of people in a room and will also display either the bulb is ON or OFF, and also about Fan status.
- I haven't shown the relay circuit in above figure as it will not fit in the space and I think you guys can place it easily.
Programming Code for Intelligent Energy Saving System
- The code designed for this project is developed in Arduino software.
- Code is as follows:
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 8
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
float celsius, fahrenheit;
int Sensor1 = A0;
int Sensor2 = A1;
int Bulb = A5;
int Fan = A4;
int Buzzer = A3;
int Counter = 0;
int Sen1Check = 0;
int Sen2Check = 0;
void setup(void)
{
Serial.begin(9600);
digitalWrite(Bulb, HIGH);
digitalWrite(Fan, HIGH);
digitalWrite(Buzzer, HIGH);
pinMode(Sensor1, INPUT);
pinMode(Sensor2, INPUT);
pinMode(Bulb, OUTPUT);
pinMode(Fan, OUTPUT);
pinMode(Buzzer, OUTPUT);
lcd.begin(20, 4);
lcd.setCursor(0, 1);
lcd.print("Temp = ");
lcd.setCursor(0, 0);
lcd.print("Counter = ");
lcd.setCursor(12, 0);
lcd.print("Persons");
}
void loop()
{
CheckEntry();
CheckLeaving();
lcd.setCursor(7, 1);
sensors.requestTemperatures();
lcd.println(sensors.getTempCByIndex(0));
lcd.setCursor(12, 1);
lcd.print(" degC");
lcd.setCursor(10, 0);
if(Counter >= 0){lcd.print(Counter);}
if(Counter < 0){Counter = 0;}
if(Counter > 0)
{
digitalWrite(Bulb, LOW);
digitalWrite(Fan, LOW);
digitalWrite(Buzzer, HIGH);
lcd.setCursor(0, 2);
lcd.print("Fan : ON ");
lcd.setCursor(0, 3);
lcd.print("Bulb : ON ");
}
if(Counter < 1)
{
digitalWrite(Bulb, HIGH);
digitalWrite(Fan, HIGH);
digitalWrite(Buzzer, HIGH);
lcd.setCursor(0, 2);
lcd.print("Fan : OFF");
lcd.setCursor(0, 3);
lcd.print("Bulb : OFF");
}
}
void CheckEntry()
{
if(((digitalRead(Sensor1) == LOW) || (Sen1Check == 1)) && (Sen2Check == 0))
{
while(digitalRead(Sensor1) == LOW);
Sen1Check = 1;
if(digitalRead(Sensor2) == LOW)
{
Counter++;
Sen1Check = 0;
while(digitalRead(Sensor2) == LOW);
}
}
}
void CheckLeaving()
{
if(((digitalRead(Sensor2) == LOW) || (Sen2Check == 1)) && (Sen1Check == 0))
{
while(digitalRead(Sensor2) == LOW);
Sen2Check = 1;
if(digitalRead(Sensor1) == LOW)
{
Counter = Counter - 1;
Sen2Check = 0;
while(digitalRead(Sensor1) == LOW);
}
}
}
- Coding isn't much difficult for this project, but still if you get into some trouble ask in comments and I will check it out.
- Here's the complete video for this Intelligent Energy Saving System, which will explain all about the project.
That's all for today. I hope I have helped you guys in some way. Till next tutorial, take care ALLAH HAFIZ :)
Design a Buzzer in Proteus ISIS
Hello friends, hope you all are having fun and enjoying life. Today's post is quite a simple one and is about designing of circuit diagram of buzzer in Proteus ISIS. Buzzer is quite a common electrical component which is used in almost every Embedded Systems project. For example, you have seen a simple UPS, it gives a beep each time the light goes off or it has depleted its battery. Buzzer is normally used for given some indication and normally this indication is kind of a warning.
Proteus has a builtin component for buzzer and its an animated component means it gives a sound (beep) when its turned ON. So, I am gonna use that one and will give you an actual beep on it. So, it won't be much difficult and quite a simple procedure. In this post, I am not gonna interface it with any Microcontroller i.e. Arduino or PIC Microcontroller but if you want then you can quite easily control it using any of them. You simply need to give pulse to it and you can control it. If I get time then I will post the control of buzzer with Arduino. So, let's start with it.
Design a Buzzer in Proteus ISIS
- First of all, get components from the Proteus library as shown in below figure:
- Now after selecting these components, design a circuit diagram in Proteus as shown in below figure:
- In the above circuit, I have used an optocoupler PC817 in order to control the buzzer.
- The optocoupler is controlled by a simple logic operator, now when you change the logic operator from 1 to 0 the buzzer will turn on.
Note:
- Optocoupler is working here on inverse logic i.e. when we send 1 then its OFF and when we send 0 then its ON.
- If you are designing it on hardware then you can use PC817 Optocoupler.
- So now if everything's fine then simply run the simulation and then click on the logic operator and you will get the below results:
- You can see in the above figure, there are two states.
- In the Buzzer ON state LED is OFF but the buzzer will be ON and you will hear a beep like sound, which obviously can't be heard here in the image. :)
- While in the OFF state LED is ON but the buzzer will be OFF and you wont hear anything.
That's quite a simple tutorial and quite easy to understand but still if you have any problem, then ask in comments. Till next tutorial, take care and have fun.