Arduino Bluetooth Communication using HC05
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share a new project in which we are gonna do Arduino Bluetooth communication. The Bluetooth module I have used for this project is HC-05, which is a serial Bluetooth module. We can quite easily perform the Bluetooth communication with this module using Arduino board. I have worked on many projects in which I have to send the data from sensors to my computer via Bluetooth. So, in such projects I normally use this Bluetooth module which is connected with the sensors and then Arduino gets the data from these sensors and then send this data to computer via Bluetooth module. In this project, I have used Arduino board but you can use PIC Microcontroller or 8051 Microcontroller as well. Because they both have the Serial pins on them.
Note:
Before reading any further, I think you must have a look at the below post from where you can download the Bluetooth Library for Proteus, using this library you can easily simulate HC-05 or , HC-06 in Proteus software:
I have also done Bluetooth communication with Android mobiles. In these projects I have sent the data from this Bluetooth module to Android mobiles but in such projects I have also designed Bluetooth app on which this data is received. Anyways, that's a topic of another tutorial. Today, I am gonna connect this Bluetooth module with Arduino board and then will send some data to my computer using Bluetooth. So, let's get started with Arduino Bluetooth communication using HC-05 module.
Arduino Bluetooth Communication using HC-05
- First of all, what you need to do is to buy the Arduino board. I have designed this project using Arduino UNO board but you can buy any of the Arduino Microcontroller board.
- Next thing you are gonna need is Bluetooth module which is HC-05. But this tutorial will also work for HC-06 or HC-07.
- Now if you have seen HC-05 then the pins are written on it so connect them with your Arduino board as shown below:
- This pin configuration is also shown in the below figure:
- Now that you have connected your Arduino board with the Bluetooth module HC-05 so you are ready to do the Arduino Bluetooth communication.
- Now upload the below code in your Arduino board:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
}
void loop()
{
if (mySerial.available())
Serial.write(mySerial.read());
if (Serial.available())
mySerial.write(Serial.read());
}
- Its a simple software serial code in which we are sending data from our Serial terminal to Bluetooth means whatever you write in your serial terminal will be sent over to Bluetooth and whatever you receive on your Bluetooth will be shown in serial terminal.
- Now, download this Serial monitor software, I have designed this software and its quite simple one. You can use any other serial monitor like Virtual Terminal in Proteus or Hyper Terminal in Windows XP.
- We are gonna use this software to get the data on our computer via Bluetooth and you computer must have the Bluetooth in your computer. :P
- So, download this software by clicking the below button and you can read more about it Microsoft Visual Basic 2010 - Com Port Tutorial.
Download Serial Terminal
- Now turn on your Arduino and search for the Bluetooth device in your Bluetooth settings and paired with it as shown in below figure.
- The default pin code for HC-05 is 1234.
- Now you can see I have paired the HC-05 device.
- Now, open this software and connect with the COM port of your Bluetooth device.
- The Bluetooth device generates two COM ports in my case it generated COM11 and COM12 but COM11 worked.
- So, I connected with COM11 and then whatever I entered in my software is shown on the serial monitor of my Arduino and whatever I entered in the Serial monitor of Arduino is shown in the serial terminal software.
- Its quite simple and you can do it quite easily.
So, that's all for today and I hope you are gonna make it work in the single attempt. If still having problems then ask in comments and I will resolve them. So, today we have done Arduino Bluetooth communication using HC-05 module.
Top 10 PCB Design Software
Hello friends, hope you all are fine and having fun with your lives. Today, I am going to share an informational tutorial about top 10 PCB design Software. These PCB design software are used for designing PCBs. In all engineering projects especially related to electronics, PCB designing is an important task and in order to design the PCB we have to use some software. There are many software available in market and today, I am gonna give a complete list of PCB Design software.
Few of these software and free to use and few have limited versions available but in order to get their advanced features you have to buy them. I have also mentioned their features below. If you have read my blog in detail then must have the idea that I use Proteus software for designing my PCB boards. So, if you ask me then I will recommend Proteus software as you can simulate your circuit design in it as well along with PCB designing. I have also used Eagle software for PCB designing and its also quite easy and rich with features. Anyways let's get started with top 10 PCB Design Software
PCB Design Software - Basics
There are few things, which you must remember before starting your PCB design. When you start your project, never jump directly to PCB designing. Instead, you must first design your circuit on wero board or bread board and then test it out. Once you confirmed that all features of your project are working perfectly, then you should move to designing part. If you started the PCB design at first then there's a chance that you miss something in your hardware and then your PCB boards will simply go to waste. So, first design your hardware temporarily adn then test its working and then design your PCB board. You can also simulate your circuit design on some software before designing its PCB. Anyways its up to you. When I design any project then I first design hardware on wero board and then once its perfect then I design its PCB board. Anyways, now let's have a look at top 10 PCB Designing software.
1 Altium
Altium is at first rank in my list of PCB Design software. You can get this software from their official site. Altium is used for designing PCB boards, you can design PCB of any layer in this software. Its very powerful and has a long list of tools for editing or designing your PCB board. Its a paid software and you can buy ti easily from their official site, whose link I have posted above. You can also create the component list, BOM file etc in this software. You can also design flexible PCB designs in it and can also check their 3D simulator to know about the final shape of your PCB baord.
2 Eagle
Eagle is another great PCB design software which comes after Altium software. Its also quite powerful and has great list of tools for designing your PCB board. Eagle is the most commonly used PCB Design software as its easy and quite flexible in its features. Eagle has quite a lot of support available online in forums as its quite an old software. It also provides the component list and the BOM file etc.
3 Proteus
This one is my favorite PCB Design software and if you have read my blog then you must have the idea how much i like this software. In Proteus you not only design your PCB boards but also can simulate your complete circuit design. When I design a PCB board then I first design its simulation in Proteus and then I move on to designing its PCB board. It also has quite flexible tools using which you can design your PCB board and then can also check its 3D design.
So, if you ask me then I will recommend you Proteus software for PCB designing. If you wanna start working in this software then you must read How to do PCB designing in Proteus ARES. I have also shared a the PCB design of Arduino UNO baord which you can also download from this link.
4 Fritzing
Fritzing is another tool used for designing PCB boards. I like its interface. It has quite attractive and user friendly interface and you can design your PCB layout in it quite easily. But drawback of fritzing is that its not professional software, it has quite small list of components available in it so I never thought of using this software for PCB Designing. But if you have simple designing then give ti a try, you are gonna like it.
5 TinyCAD
TinyCAD is also used for PCB Designing. and is quite famous. It also has a long list of tools for designing your PCB boards. Its quite similar to Eagle software and is easy to learn and operate.
6 ZenitPCB
When discussing PCB Design software, then how can we forget ZenitPCB. It also a great PCB Design software which is used for PCB designing in quite efficient way. Its easy to use and has a user friendly interface.
7 ExpressPCB
ExpressPCB is also a cool tool for design your PCB boards. Its good for new users as its easy to use and learn. You can learn this software just by watching its single video. Its too easy to get started with and have a cool and user friendly interface.
8 KiCAD
KiCAD is an open source software which you can easily download online and is also free to use. Using this software you can design PCB boards up to 16 layer quite easily. It is rich with PCB designing features and can handle complex designs quite easily.
9 DesignSpark PCB
DesignSpark PCB software is also another great tool in the list of free PCB Design software. Its also a flexible software with a lot of tools and options for PCB designing. You are gonna like this one if you need quick and easy PCB designing.
10 EasyEDA
EasyEDA is also used for design PCB boards. It also has a user friendly interface and is good for first time user as it has everything in front and one can design PCB boards quite easily in it. You can also design multi layer PCB boards in it. It has small database of components that's why you have to design your components on your own while using this PCB design software.
That's a long list of PCB Design software. These all software are quite easy to use and anyone can work on them just after a little training. So, you can select any of them for designing your PCB boards. If you ask me then I will recommend Proteus and Eagle software as I use the for designing my PCB boards.
Automatically Connect with Wifi SSID using Arduino YUN
Hello Friends, hope you all are fine and having fun. In today tutorial i am going to elaborate How to Automatically Connect with Wifi SSID using Arduino YUN. If you recall one of my previous tutorials named Getting started with Arduino YUN , in which i gave a brief introduction about Arduino YUN, its working and features. In that tutorial, I have explained How to connect Arduino YUN with Wifi manually. A little problem encounters while connecting Arduino manually to available wifi networks that if wifi connection drops then, then Arduino will also disconnect automatically and if wifi connection is energized again, it will still remain disconnected unless you reconnect it by yourself. This thing has very serious drawbacks in industrial projects, where data is continuously uploaded through multiple servers and if at any stage connection drops and Arduino stops working then, this thing leads to drastic outcomes.
So there is serious need to design an algorithm in which Arduino automatically connects to the available wifi connections and should enables the server to upload data through it. This whole process is a bit lengthy and much complicated. So, i will elaborate all this in the coming tutorials. In today's tutorial i am going to restrict myself only How to get Available wifi SSID using Arduino YUN. First of all lets recall the basics of Arduino YUN. Arduino YUN has 2 micro processors embedded on the same board. First is the Arduino microprocessor and the second is Atheros micro processor. Atheros supports Linux server (commonly used in Apple computers). With both these on-board micro processors, we can do anything we want to do. The beauty of Arduino board is that it has built in wifi, Ethernet port, USB host and SD card slot. We can also upload data into Arduino through wifi without physically connecting it with computer. That's why Arduino boards are the most widely used micro processors now a days, and are able to handle multitasking industrial projects. Above was a little introduction about Arduino YUN and now lets get started with our today's tutorial.
Automatically Connect with Wifi SSID using Arduino YUN
- First of all open the Arduino softeare. On toolbar click on the icon named "Tools" and a new window will open. Then go to the option "Board" and from the next opened window select the board "Arduino YUN".
NOTE:
- Remember you must download the Arduino software version 1.5.5 + instead of 1.0.3 because Arduino sketches will be only compiled in 1.5.5 version which is specifically designed for Arduino YUN.
- After selecting the board, you will load the given below code into Arduino Board.
#include <Process.h>
#include <FileIO.h>
String ESSID = "TEP";
String Pass = "Pakistan";
String Encrypt = "psk2";
void setup() {
Serial.begin(9600);
delay(5000);
FileSystem.begin();
delay(5000);
Bridge.begin();
delay(5000);
}
void loop() {
// put your main code here, to run repeatedly:
WifiAuthentication();
}
void WifiAuthentication()
{
uploadScript();
delay(1000);
runScript();
delay(20000);
}
void uploadScript()
{
File script = FileSystem.open("/tmp/setupwifi.sh", FILE_WRITE);
script.print("#!/bin/sh\n");
script.print("/sbin/uci set network.lan=interface\n");
script.print("/sbin/uci set network.lan.proto=dhcp\n");
script.print("/sbin/uci delete network.lan.ipaddr\n");
script.print("/sbin/uci delete network.lan.netmask\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].mode=sta\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].ssid=" + ESSID + "\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].encryption=" + Encrypt + "\n");
script.print("/sbin/uci set wireless.@wifi-iface[0].key=" + Pass + "\n");
script.print("/sbin/uci commit wireless; /sbin/wifi\n");
script.print("/etc/init.d/network restart\n");
script.close();
Process chmod;
chmod.begin("chmod");
chmod.addParameter("755");
chmod.addParameter("/tmp/setupwifi.sh");
chmod.run();
}
void runScript()
{
Process myscript;
myscript.begin("/tmp/setupwifi.sh");
myscript.run();
Serial.println("Connected");
}
- The above given code is a bit complicated and it consists of many steps. Now i am going to show all the steps through a block diagram and then i will try to explain every step one by one.
- Using this code, the Arduino YUN board will automatically connected to the available SSID which is in our case is TEP. So you can give any other SSID there and it will connect to that one.
- In the above block diagram, you can see that first of all Initialize Serial Port. When you will connect Arduino YUN with your computer through cable or as i described earlier that Arduino YUN also have built-in wifi so you can also connect Arduino YUN with computer through wifi.
- Then you will load the code to Initialize Serial Port, which is the first step and also shown in the above block diagram.
- In this project we have kept Baud rate of Arduino YUN 9600.
- The next step in the block diagram is to 'Initialize File System' . In this step we will load 'File System' into our code as viewed in the code image given above.
- Now in the next step we have to initialize the Arduino YUN Bridge. The block diagram representing the internal structure of Arduino YUN is shown in the image below:
- Â As i stated earlier in the beginning of the tutorial that Arduino YUN has 2 on-board micro processors and Arduino YUN is the intermediate source who performs communication between both micro processors.
- The Bridge library facilitates communication between the two processors, giving Arduino sketches the ability to run shell scripts, communicate with network interfaces, and receive information from the AR 9331 processor.
- The USB Host is connected to the ATmega 32u4, while the all external interferences(like Wifi, Ethernet, SD card) are connected to Linux micro processor.
- The beauty of this board is that Bridge libraries also enables the Arduino micr processor ATmega to communicate with the other interferences, which are also connected with Linux microprocessor.
- When bridge has been activated then, Arduino YUN enables its wifi and search for the nearby available wifi connections.
- When it will get some available wifi connections in its surrounding then, from its algorithm, Arduino YUN will get the SSID from that available wifi connections.
- The next thing which we have implemented in the code is to get SSID String. It is a built in function and also available in Arduino libraries that if it gets any available wifi connection near it, then it automatically gets strings from those connections.
- When Arduino has searched for all the available wifi connections near it and after getting the SSID of available wifi connections, it sends all these SSID to serial port of Arduino YUN board.
- After that Arduino YUN will automatically connect to that wifi connection whose SSID matches with the given SSID.
- Now the end step is very important and it distinguishes Arduino YUN from all other Arduino boards, which is, After sending data to serial port it again starts the loop and got o step #4 and it again starts to search for available wifi networks.
- This phenomenon can also be verified from the above shown block diagram.
- At any stage, if wifi connection drops then the loop will again start and will search for available wifi connections, get their SSID and it will send these SSID to serial port and it will rehabilitate the connection within no time and no problem will occur at any stage of data execution.
Alright friends, that was all from today's post. It is a very basic and very important post and we have seen How to Automatically Connect with Wifi SSID using Arduino YUN. I hope you have learned something new in today's post. If you have any problem in understanding any step of this tutorial then, you can ask in the comments and i will try my best to resolve the issue. Follow us to get the codes and simulations straight in your inbox. For more tutorial and projects, stay tuned and until next tutorial Take Care !!! :)
555 Timer Projects
Hello friends, hope you all are fine and having fun with your lives. Today I am gonna post 555 Timer projects list which are already posted on our blog. Actually, I have posted many 555 Timer Projects on my blog but we don't have a list of these tutorials and they are quite scattered. So, today I thought to arrange them in a proper list so that you can find all of them in one place. All these 555 timer projects are simulated in my favorite simulating software Proteus. I have also given their simulations for download in almost all tutorials. If you feel problem in any of them then ask in comments and I will resolve them.
All these 555 Timer Projects and tutorials are written and designed completely by our team so we hold the complete ownership for these projects. Other bloggers are welcome to share them on their blogs to spread knowledge but do mention our post link as we have done a lot of work and effort in designing these tutorials and projects. :)
I will keep on updating this list in future as I am gonna add more projects on 555 Timer, I will add their links below. So, enough with the talking, let's get started with 555 Timer projects.
555 Timer Projects
I have divided these projects and tutorials in different sections depending on their complexity. Follow all these tutorials step by step and you are gonna be expert in 555 Timer real soon. I will keep on updating this list in future, whenever I am gonna add new project on 555 Timer, I will post the link here.
Basics of 555 Timer
Below tutorials will give you the basics of 555 Timer IC. So these tutorials are kind of must because if you don't know the basics of any integrated chip then how can you use it in your ciruits. So must read them once and then move to next section:
555 Timer Projects - Basics
I hope you have read the basics of 555 Timer, so now here's time to get started with 555 Timer Projects. These projects are designed in Proteus simulating software and are working perfectly. Simulations are given for download in most of these tutorials. So, lets get started:
555 Timer Projects - Advanced
Now I think you are quite expert in 555 Timer and have done the basic projects so now its time to move to the next level and design advance level projects with 555 Timer. In these projects we are gonna interface difference electronic modules with 555 Timer.
How to Generate PWM in 8051 Microcontroller
Hello everyone, hope you all are fine and having fun with your lives. In today's post, I am going to share How to generate PWM in 8051 Microcontroller. PWM is an abbreviation of Pulse Width Modulation and is used in many engineering projects. It is used in those engineering projects where you want an analog output. For example, you want to control the speed of your DC motor then you need a PWM pulse. Using PWM signal you can move your motor at any speed from 0 to its max speed. Similarly suppose you wanna dim your LED light, again you are gonna use PWM pulse. So, in short, it has numerous uses. If you are working on Arduino then you should read How to use Arduino PWM Pins.
PWM, as the name suggests, is simply a pulse width modulation. We take a pulse and then we modulate its width and make it small or big. Another term important while studying PWM is named duty cycle. The duty cycle shows the duration for which the PWM pulse remains HIGH. Now if the pulse remains high for 50% and LOW for 50% then we say that PWM pulse has a duty cycle of 50%. Similarly, if the pulse is HIGH for 70% and Low for 30% then it has a duty cycle of 70%.
Most of the microcontrollers have special pins assigned for PWM as in Arduino UNO it has 6 PWM pins on it. Similarly, PIC Microcontrollers also have PWM pins but unfortunately, the 8051 Microcontroller doesn't have this luxury means there are no special PWM pins available in 8051 Microcontroller. But PWM is necessary so we are going to manually generate the PWM pulse using Timer0 interrupt. So, before reading this tutorial you must first read How to use Timer Interrupt in 8051 Microcontroller so that you understand the functioning of Timer Interrupt. Anyways, let's get started with the generation of PWM in the 8051 Microcontroller.
Where To Buy? |
---|
No. | Components | Distributor | Link To Buy |
1 | 8051 Microcontroller | Amazon | Buy Now |
How to Generate PWM in 8051 Microcontroller ???
- You can download both the simulation and the programming code for PWM in 8051 Microcontroller by clicking the below button:
Download PWM Code & Simulation
- First of all, design a simple circuit as shown in the below figure:
- Now what we are gonna do is we are gonna generate a PWM pulse using timer0 interrupt and then we are gonna send it to P2.0.
- I have attached an oscilloscope on which we can easily monitor this PWM pulse and can check whether it's correct or not.
Code in Keil uvision 3
- Now, copy the below code and paste it into your Keil uvision software. I have used Keil uvision 3 for this code compiling.
#include<reg51.h>
// PWM_Pin
sbit PWM_Pin = P2^0; // Pin P2.0 is named as PWM_Pin
// Function declarations
void cct_init(void);
void InitTimer0(void);
void InitPWM(void);
// Global variables
unsigned char PWM = 0; // It can have a value from 0 (0% duty cycle) to 255 (100% duty cycle)
unsigned int temp = 0; // Used inside Timer0 ISR
// PWM frequency selector
/* PWM_Freq_Num can have values in between 1 to 257 only
* When PWM_Freq_Num is equal to 1, then it means highest PWM frequency
* which is approximately 1000000/(1*255) = 3.9kHz
* When PWM_Freq_Num is equal to 257, then it means lowest PWM frequency
* which is approximately 1000000/(257*255) = 15Hz
*
* So, in general you can calculate PWM frequency by using the formula
* PWM Frequency = 1000000/(PWM_Freq_Num*255)
*/
#define PWM_Freq_Num 1 // Highest possible PWM Frequency
// Main Function
int main(void)
{
cct_init(); // Make all ports zero
InitPWM(); // Start PWM
PWM = 127; // Make 50% duty cycle of PWM
while(1) // Rest is done in Timer0 interrupt
{}
}
// Init CCT function
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
// Timer0 initialize
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x01; // Set timer0 in mode 1 = 16bit mode
TH0 = 0x00; // First time value
TL0 = 0x00; // Set arbitrarily zero
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
// PWM initialize
void InitPWM(void)
{
PWM = 0; // Initialize with 0% duty cycle
InitTimer0(); // Initialize timer0 to start generating interrupts
// PWM generation code is written inside the Timer0 ISR
}
// Timer0 ISR
void Timer0_ISR (void) interrupt 1
{
TR0 = 0; // Stop Timer 0
if(PWM_Pin) // if PWM_Pin is high
{
PWM_Pin = 0;
temp = (255-PWM)*PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
else // if PWM_Pin is low
{
PWM_Pin = 1;
temp = PWM*PWM_Freq_Num;
TH0 = 0xFF - (temp>>8)&0xFF;
TL0 = 0xFF - temp&0xFF;
}
TF0 = 0; // Clear the interrupt flag
TR0 = 1; // Start Timer 0
}
- I have added the comments in the above codes so it won't be much difficult to understand. If you have a problem then ask in the comments and I will resolve them.
- Now in this code, I have used a PWM variable and I have given 127 to it as a starting value.
- PWM pulse varies from 0 to 255 as it's an 8-bit value so 127 is the mid-value which means the duty cycle will be 50%.
- You can change its value as you want it to be.
Proteus Simulation Result
- So, now when you upload the hex file and run your simulation then you will get below results:
- Now you can check in the above figure that the duration of HIGH and LOW is the same means the pulse is HIGH for 50% and LOW for the remaining 50% cycle.
- Now let's change the PWM duty cycle to 85 which is 1/3 and it will generate a PWM pulse of 33% duty cycle. Here's the result:
- Now you can easily compare the above two figures and can get the difference. In the above figure now the duty cycle has decreased as the HIGH timing of the pulse is now reduced to 1/3 and pulse is LOW for 2/3 of the total time.
That's all, for today. That's how we can generate PWM in 8051 Microcontroller. Will meet you guys in the next tutorial. Till then take care !!! :)
Interrupt Based Digital Clock with 8051 Microcontroller
Hello friends, hope you all are fine and having fun with your lives. In today's post, I am going to share Interrupt based Digital clock with 8051 Microcontroller. In the previous post, I have explained in detail How to use Timer Interrupt in 8051 Microcontroller. We have seen in that post that we can use two timers in 8051 Microcontroller which are Timer0 and Timer1. Using these timers we can easily generate interrupts. So, before going into details of this post, you must read that timer post as I am gonna use these timer interrupts in today's post.
After reading this post, you will also get the skilled hand on timer interrupt and can understand them more easily. In today's post, I am gonna design a digital clock which will increment after every one second and we will calculate this one second increment using timer interrupt. This clock will be displayed on LCD so if you are not familiar with LCD then must read Interfacing of LCD with 8051 Microcontroller. You can also implement this digital clock with any other microcontroller like Arduino or PIC Microcontroller but today we are gonna implement it on 8051 Microcontroller. The complete simulation along with code is given at the end of this post but my suggestion is to design it on your own so that you get most of it. Use our code and simulation as a guide. So, let's get started with Interrupt based Digital clock with 8051 Microcontroller. :)
Interrupt Based Digital Clock with 8051 Microcontroller
- First of all, design a circuit as shown in below figure:
- Now use the below code and get your hex file. I have designed this code in Keil uvision 3 compiler for 8051 Microcontroller.
#include<reg51.h>
//Function declarations
void cct_init(void);
void delay(int);
void lcdinit(void);
void WriteCommandToLCD(int);
void WriteDataToLCD(char);
void ClearLCDScreen(void);
void InitTimer0(void);
void UpdateTimeCounters(void);
void DisplayTimeToLCD(unsigned int,unsigned int,unsigned int);
void WebsiteLogo();
void writecmd(int);
void writedata(char);
//*******************
//Pin description
/*
P2.4 to P2.7 is data bus
P1.0 is RS
P1.1 is E
*/
//********************
// Defines Pins
sbit RS = P1^0;
sbit E = P1^1;
// Define Clock variables
unsigned int usecCounter = 0;
unsigned int msCounter = 0;
unsigned int secCounter = 0;
unsigned int minCounter = 0;
unsigned int hrCounter = 0;
// ***********************************************************
// Main program
//
void main(void)
{
cct_init(); // Make all ports zero
lcdinit(); // Initilize LCD
InitTimer0(); // Start Timer0
// WebsiteLogo();
while(1)
{
if( msCounter == 0 ) // msCounter becomes zero after exact one sec
{
DisplayTimeToLCD(hrCounter, minCounter, secCounter); // Displays time in HH:MM:SS format
}
UpdateTimeCounters(); // Update sec, min, hours counters
}
}
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 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 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 InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x02; // Set timer0 in mode 2
TH0 = 0x05; // 250 usec reloading time
TL0 = 0x05; // First time value
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
void Timer0_ISR (void) interrupt 1 // It is called after every 250usec
{
usecCounter = usecCounter + 250; // Count 250 usec
if(usecCounter==1000) // 1000 usec means 1msec
{
msCounter++;
usecCounter = 0;
}
TF0 = 0; // Clear the interrupt flag
}
void WebsiteLogo()
{
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);
}
void UpdateTimeCounters(void)
{
if (msCounter==1000)
{
secCounter++;
msCounter=0;
}
if(secCounter==60)
{
minCounter++;
secCounter=0;
}
if(minCounter==60)
{
hrCounter++;
minCounter=0;
}
if(hrCounter==24)
{
hrCounter = 0;
}
}
void DisplayTimeToLCD( unsigned int h, unsigned int m, unsigned int s ) // Displays time in HH:MM:SS format
{
ClearLCDScreen(); // Move cursor to zero location and clear screen
// Display Hour
WriteDataToLCD( (h/10)+0x30 );
WriteDataToLCD( (h%10)+0x30 );
//Display ':'
WriteDataToLCD(':');
//Display Minutes
WriteDataToLCD( (m/10)+0x30 );
WriteDataToLCD( (m%10)+0x30 );
//Display ':'
WriteDataToLCD(':');
//Display Seconds
WriteDataToLCD( (s/10)+0x30 );
WriteDataToLCD( (s%10)+0x30 );
}
void delay(int a)
{
int i;
for(i=0;i<a;i++); //null statement
}
void WriteDataToLCD(char t)
{
RS = 1; // This is data
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (t&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((t<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void WriteCommandToLCD(int z)
{
RS = 0; // This is command
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (z&0xF0); // Write Upper nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= ((z<<4)&0xF0);// Write Lower nibble of data
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
}
void lcdinit(void)
{
///////////// Reset process from datasheet /////////
delay(15000);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(4500);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(300);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x30&0xF0); // Write 0x3
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
P2 &= 0x0F; // Make P2.4 to P2.7 zero
P2 |= (0x20&0xF0); // Write 0x2
E = 1; // => E = 1
delay(150);
E = 0; // => E = 0
delay(150);
delay(650);
/////////////////////////////////////////////////////
WriteCommandToLCD(0x28); //function set
WriteCommandToLCD(0x0c); //display on,cursor off,blink off
WriteCommandToLCD(0x01); //clear display
WriteCommandToLCD(0x06); //entry mode, set increment
}
void ClearLCDScreen(void)
{
WriteCommandToLCD(0x01); // Clear screen command
delay(1000);
}
- Now run your simulation and if everything goes fine then you will get results as shown in below figure:
- The above figure is taken after 10 seconds of start of simulation in Proteus ISIS.
- As the simulation keeps on running the clock will also keep on ticking.
- The code is self explanatory but let me explain the interrupt function.
- I have used Timer0 interrupt in this digital Clock.
- The timer interrupt function is incrementing the userCounter variable by 250 which is in micro seconds. So we need 1000us as it will become 1 second. That's why I have placed the check that when userCounter == 1000 then increment the second.
- I have added comments in the code so read it in detail and still if you stuck somewhere then ask in comments and I will resolve them.
- You can download the complete code along with Proteus Simulation by clicking the below button:
Download Proteus Simulation and Code for Digital Clock
That's all for today. Hope you have enjoyed today's project. Will meet you guys soon in the next post. Till then take care !!! :)
How to use Timer Interrupt in 8051 Microcontroller
Hello friends, hope you all are fine and having fun with your lives.In today's post, we are gonna see How to use timer interrupt in 8051 Microcontroller.8051 Microcontroller comes with timer as well. They normally have two timer in them named as Timer0 and Timer1. These timers are used for counting purposes like you want to start some countdown in your project then you can use these timers or you wanna create some clock then in that case as well you need timers. So, in short there are numerous uses of timers in a project. Timers are also used for delays like you wanna create some delay of 10 sec but you dont wanna use the delay function in your project so you can use timers. You start the timer and then when it comes to 10 seconds then you can do your work. So, these are different uses of a timer and clearly we can't neglect its importance, so today we are gonna see How to use these timer interrupt in 8051 Microcontroller.
Now coming towards interrupt, interrupt is interrupt :P Yeah really, we call it interrupt because its an interrupt. In programming codes there are many things which needs to run in background and appear when its time for them to appear. Here where interrupt comes handy. Interrupt is kind of a background code which keeps on running in the background while the main code keeps on running in front but when the interrupt condition is fullfilled then it interrupts the main program and executes the functions defined in it. For Timer interrupts, suppose I wanna blink my LED after every 2 seconds then what will I do is I will start a timer for 2 seconds and when this timer completes I will generate an interrupt. So, in this way after every two seconds the led will blink. So, let's start with timers interrupt in 8051 Microcontroller and see how we are gonna do this.
How to use Timer interrupt in 8051 Microcontroller ???
As I explained earlier, we are gonna use Timer interrupt in 8051 Microcontroller. so, now before gong into the details, let me first throw some light on how we are gonna implement this. Timers count from 0 to 255 in 8 bit mode as in 8 bit 255 is the maximum value and when timer hits the 255 number then we say that our timer is overflowed. Now when timer overflows, then it sends us a indication using which we generate our intterupt. In timers, there are few registers in which they store their value. If we are talking about Timer0 then timer0 stores its value in TL0 register. Now suppose I want my timer to start counting from 10 instead 0 then I will store 10 in my TL0 register and it will count from 10 instead 0 and when it reaches 255 it will overflow. Now when Timer0 will overflow then it will make TF0 bit HIGH. TF0 is another register value, if its 1 then it means that our timer is full and if its 0 then it means our timer is still counting. So, that's how we count from our timer and check the pin TF0. Now first of all, I am gonna use Timer0 and then we will have a quick look at Timer1.
Timer0 Interrupt
- First of all, design a simple circuit as shown in below figure:
- Now upload the below code in your Keil software and get the hex file.
#include<reg51.h>
// Out Pin
sbit Out = P2^0; // Pin P2.0 is named as Out
//Function declarations
void cct_init(void);
void InitTimer0(void);
int main(void)
{
cct_init(); // Make all ports zero
InitTimer0(); // Start Timer0
while(1) // Rest is done in Timer0 interrupt
{
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void InitTimer0(void)
{
TMOD &= 0xF0; // Clear 4bit field for timer0
TMOD |= 0x02; // Set timer0 in mode 2
TH0 = 0x05; // 250 usec reloading time
TL0 = 0x05; // First time value
ET0 = 1; // Enable Timer0 interrupts
EA = 1; // Global interrupt enable
TR0 = 1; // Start Timer 0
}
void Timer0_ISR (void) interrupt 1 // It is called after every 250usec
{
Out = ~Out; // Toggle Out pin
TF0 = 0; // Clear the interrupt flag
}
- In the above code, the main function is our InitTimer0 function.
- In this function what I have done is I simply set the timer 0 to mode 2. In mode 2, it will auto reload means once the timer0 overflows then it will comes back to its original value and will start again.
- TL0 has 0x05 in it which is the initial value of timer0 and it will count for 250 micro seconds.
- TH0 also has the 0x05. On reload timer uploads the vlaue from TH0 into TL0 so thats why we have given the same value to TH0.
- After that we make ET0 bit enabled which will enable the timer, if you dont set this pin HIGH then our timer will not work.
- EA bit will enable the global interrupt. if we dont enable this pin then timer will work but it wont generate the interrupt.
- Finally after setting all configurations, we started our timer.
- Now when the Timer0 overflows after every 250 micro seconds, it will generate the interrupt and it will come to Timer0_ISR function.
- In Timer0_ISR function, I simply toggled the OUt pin which is Pin2.0 and then I again set the interrupt bit to 0 which is TF0.
- That's how our timer is working and if we check the P2.0 pin on oscilloscope then it will look something as shown in below figure:
- You can see in the above figure that our pin is toggling with an interval of 250 usec.
- One important thing to note is there's no function written in while(1) loop and still its working because its running on background and performing the interrupt routine. You can add any function in your MAin code and it will keep on working and meanwhile at the background your interrupt will also keep on generating.
- You can download this Simulation and programming code by clicking on below button.
Download Timer0 Code and Simulation
- Now, lets have a quick look on Timer1 interrupt in 8051 Microcontroller.
Timer1 Interrupt
- Now let's have a quick look on Timer1 interrupt in 8051 Microcontroller. For that, design the same simulation in Proteus as we did for Timer 0.
- Now, upload the below code in your Keil software and get the hex file.
#include<reg51.h>
// Out Pin
sbit Out = P2^0; // Pin P2.0 is named as Out
//Function declarations
void cct_init(void);
void InitTimer1(void);
int main(void)
{
cct_init(); // Make all ports zero
InitTimer1(); // Start Timer1
while(1) // Rest is done in Timer1 interrupt
{
}
}
void cct_init(void)
{
P0 = 0x00;
P1 = 0x00;
P2 = 0x00;
P3 = 0x00;
}
void InitTimer1(void)
{
TMOD &= 0x0F; // Clear 4bit field for timer1
TMOD |= 0x20; // Set timer1 in mode 2
TH1 = 0x05; // 250 usec reloading time
TL1 = 0x05; // First time value
ET1 = 1; // Enable Timer1 interrupts
EA = 1; // Global interrupt enable
TR1 = 1; // Start Timer 1
}
void Timer1_ISR (void) interrupt 3 // It is called after every 250usec
{
Out = ~Out; // Toggle Out pin
TF1 = 0; // Clear the interrupt flag
}
- Now you can see in the above code that its exactly the same as we used for Timer0 with a slight difference that now we are using registers for Timer1.
- Instead of TL0, now we are using TL1 and similarly TH1 instead of TH0 and TR1 instead of TR0.
- Rest of the code is exactly the same and hence it will give the same result as for Timer0 and is shown in below figure:
- You can download the code for Timer1 along with simulation by clicking the below button.
Download Timer1 Code and Simulation
That's all for today, I hope you guys have got something out of today's post and gonna like this one. In the coming post, I am gonna design some simple project on 8051 Microcontroller in which I will use these Timers, then you will get know more about them. So, stay tuned and subscribe us by email. Take care !!! :)
8051 Microcontroller Projects
Hello everyone, hope you all are fine and having fun with your lives. Today, I am going to share 8051 Microcontroller Projects. Recently, I have shared quite a lot of tutorials on 8051 Microcontroller which are not much arranged as a whole. So, today, I thought to arrange all those tutorials and place them here so that you can get all of them quite easily. I will upload more 8051 Microcontroller Projects and I am gonna add their links in this post so stay subscribed to this post if you are interested in learning 8051 Microcontroller.
8051 Microcontroller, as we all know, is another Microcontroller series just like PIC Microcontroller or Arduino etc. The benefit of 8051 Microcontrollers is that they are quite cheap and easily available so if you are going to design some product then its better to use 8051 Microcontroller instead of PIC Microcontroller or Arduino etc. As they are cheap so they also come with a disadvantage which is that they are not much rich with features. Few of 8051 Microcontrollers doesn't even support Serial Communication. So, before choosing it for your project, must check their datasheet to confirm that they are suitable for your projects.
In most of these below projects, I have designed the complete simulation in Proteus and the code is also given but my suggestions is don't simply download the simulation and run it. Instead design the simulation from scratch and then design your code and run the simulation on your own. Consider my codes and simulations as a guide but dont get dependent on them as then you are not gonna get anything. Anyways let's get started with 8051 Microcontroller Projects.
8051 Microcontroller Projects
Below are mentioned all the 8051 Microcontrollers Projects, which I have shared on this blog. You can check these projects and can also download their simulations designed in Proteus. I have given codes for most of these projects but few are paid, which you can buy from our shop at a quite minimal rate.
Basic Projects
These are basic projects and are best for beginner level programmers. If you are new to 8051 Microcontroller then first read these projects. These all projects contain complete codes as well as the Proteus simulation so you can quite easily test them in Proteus software and can edit the codes and learn from it.
Intermediate Projects
These are Intermediate level 8051 Microcontroller Projects. If you wanna do these projects then you must first learn or atleast have a look at basic 8051 Microcontroller projects as they are using same components as we interfaced in basic level. If you feel any problem then ask in comments.
That's all for today, but I am gonna add more projects in it and will keep on updating the list. Subscribe us and get these exciting tutorials straight to your mail box.
XBee Library for Proteus
Hello everyone, today I am going to share a new XBee Library for Proteus. I am quite excited while sharing it as we are the first developer for this XBee Library. Now you can quite easily use XBee module in your Proteus software using this XBee Library for Proteus.Wehave spent quite a lot of time in developing this and that's the reason I couldn't share new tutorials in the past few days. Anyways we are done with this new exciting XBee Library for Proteus, hope you are gonna enjoy this one. I have already sharede two libraried for Proteus which are Arduino Library for Proteus and GPS Library for Proteus. You can also interface this XBee module with Microcontrollers like Arduino, PIC Microcontroller and 8051 Microcontroller quite easily.
As its the first version of our XBee Library for Proteus so its not quite perfect and can't do the complex tasks such as analog inputs etc. It will just do the serial communication. This xbee module has two pins TX and RX and you can do your communication with it quite easily. We have designed this XBee Library for Proteus, after quite a lot of effort and we are quite proud that we are presenting it first time for Proteus. Other bloggers are welcome to share this library on their blogs to share the knowledge but do mention our blog post link in your post. :) You should also have a look at XBee Arduino Interfacing. So, let's get started with it.
XBee Library for Proteus
- First of all, download this XBee Library for Proteus by clicking on the below button:
XBee Library for Proteus
- Now once you click it you will get a zip file to download so download this zip and open it.
- In this zip file you will get two files named as:
- So, now place these two files in the libraries folder of your Proteus software.
Note:
- Now, start your Proteus ISIS software or restart it if its already running.
- Go to your components library and search for XBee Module as shown in below figure:
- Now place it in your workspace and it will look something as shown in below figure:
- If you don't know much about xbee module then you should also have a look at Introduction to XBee Module.
- As you can see in the above figure, its our xbee module in Proteus for the first time.
- As, I mentioned earlier, its a first version of xbee module so its not very advanced and it will do just the basic serial communication i.e. sending and receiving data.
- It has two pins on it which are TX and RX and using these two pins you can send and receive data quite easily.
- So, let's design a simple example and we will see How to do the Serial communication using this new XBee library for Proteus.
- Design a simple circuit as shown in below figure:
- Now what I did is, I simply place a Virtual terminal with both of these xbee modules.
- Now we need to change the Properties of one of these XBee module so double click on any one of these and you will get the below window:
- You should also have a look at Interfacing of XBee with Computer.
- Now, I have simply changed the Physical Port of this module to COM2 while the other module is at COM1.
- So, now one of my XBee module is at COM1 while the second module is at COM2.
- Now when I run my simulation then both XBee will start sending and receiving data on their respective COM Ports.
- So, what I need to do is to virtually combine these two ports and for that I have used a software named as Virtual Software Driver from Eltima and I combine these two ports.
- Now, run your simulation and whatever you type in the Virtual Terminal of first xbee will appear in the virtual terminal of second xbee. as shown in below figure:
- You can also interface this XBee modue with other microcontrollers like Arduino, PIC Microcontrollers or 8051 Microcontrollers etc.
- I have explained this whole tutorial in below video as well.
I hope you have enjoyed it and are gonna like it. Let me know if you got into any trouble and have problems in using this library. Also share your suggestions about improvement in this
XBee Library for Proteus. :)
GPS Library for Proteus
Hello friends, hope you all are fine and having fun with your lives. In today's tutorial, I am gonna share another awesome library designed by our team for Proteus, which is GPS Library for Proteus. It's my second library for Proteus, the first one was Arduino Library for Proteus which I have already shared. I am really enjoying designing these modules in Proteus because its a new and quite challenging thing. I haven't found even a single website who has designed these modules in Proteus already. So, now for the first time, you can have the GPS Library for Proteus using which you can easily simulate your GPS module in Proteus and can design your code for Arduino, PIC Microcontroller or 8051 Microcontroller.
Other bloggers are welcome to share this library and its my humble request that do mention our blog in credits. :) The GPS module, I have designed for Proteus is a simple GPS which has TX and RX pins and when you start the simulation, this module starts sending the NMEA data on its TX pin, which you can easily check using Virtual Terminal. I am gonna show you how to check it in today's post. Another important thing, obviously in Proteus Simulation we can't get the actual values of longitude,latitude etc, so in our model, I have used the dummy values for all these data. The benefit of this module is that you can easily design your code for GPS and can test it in your simulation. Plus, its design is cool as well. ;)
Note:
GPS Library for Proteus
- First of all, click on the below button and download GPS Library for Proteus.
GPS Library for Proteus
- After downloading, you will get a zip file containing three files in it.
- Now extract all these three files named as:
- GpsTEP.LIB
- GpsTEP.IDX
- GpsTEP.HEX
- Place these files in Libraries folder of your Proteus software.
Note:
- Now open your Proteus software, if you have already opened it then restart your Proteus software.
- Now in components list search for GPS Module and place it in your workspace.
- If everything's fine then you will get your module as shown in below figure:
- As you can see in the above figure, it has two pins in total which are TX and RX.
- Now double click this GPS module and you will get to its properties as shown in below figure:
- Now, one last thing you need to do is to upload the GpsTEP.HEX file, which you got in the downloaded zip file, in the Program File section.
- This GpsTEP.HEX file is essential for this model as its adding the functionality of GPS in this model.
- So, after adding the link of GpsTEP.HEX file in the Program File section, now your Gps module is ready to use in your circuit.
- So, now let's add a Virtual terminal and check the output of this GPS Module. If you haven't worked on Virtual Terminal before then you should read How to use Virtual Terminal in Proteus ISIS.
- Design a small circuit as shown in below figure:
Note:
- The baud rate of this GPS Module is 9600.
- The data sent by this GPS module is dummy as we can't get these values in simulation.
- Now let's run the simulation and check the Virtual Terminal and if everything goes fine then you will get results as shown in below figure:
- The first line is just the intro for this module and after that you will start receiving data which is in NMEA format.
- NMEA data will remain constant but will keep on coming.
- Now, instead of using this Virtual Terminal, you can use any microcontroller here like Arduino, PIC Microcontroller or 8051 Microcontroller etc. and can write your code easily and test it.
- In my coming tutorials, I am gonna share examples for this GPS module in which I will interface it with different Microcontroller.
- In the below video, I have explained this tutorial again so if you got any trouble then watch it as well.
That's all for today. You should also have a look at
Interfacing of GPS Module with Arduino in Proteus ISIS. I hope you guys have enjoyed today's post and are gonna get benefit from it. Let me know your views about today's tutorial and also give your suggestions and help us in making this GPS Library for Proteus more smarter. :)