This Project is Suitable for Everyone Including student and Professional
Bluetooth-based relay control using an 8051-based microcontroller involves using Bluetooth communication to remotely control the switching of a relay. Here’s a general overview of the system:
Hardware components:
8051-based microcontroller board
HC-05 Bluetooth module
Relay board
Power supply
AC Bulb 230v
Bulb Holder
Android based Mobile phone
Connections:
The HC-05 module is connected to the microcontroller’s serial port pins.
The relay board is connected to the microcontroller’s output pins.
Power supply connections are made to power the microcontroller and the relay board.
Software:
The software for this system involves two main parts:
Code for the microcontroller to receive commands from the Bluetooth module and switch the relay on or off accordingly.
An Android application to send Bluetooth commands to the HC-05 module.
Operation:
The Android application sends Bluetooth commands to the HC-05 module.
The HC-05 module receives the commands and sends them to the microcontroller.
The microcontroller interprets the commands and switches the relay on or off based on the command received.
Overall, this system provides a wireless means of controlling a relay, which can be useful for a variety of applications, such as home automation or industrial control systems.
#include<reg51.h>
sbit X = P1^0; // connect relay1 to P1.0
sbit Y = P1^1; // connect relay2 to P1.1
void delay(unsigned int count)
{
unsigned int i;
while(count)
{
i = 115;
while(i > 0)
i--;
count--;
}
}
/*
Uart initialization function, call this function by passing a valid baud rate value to initialize UART
currently Supported Baud Rates are 9600,4800,2400,1200
*/
void uart_init(unsigned int baud)
{
unsigned int a = 9600, b = 4800, c = 2400 , d = 1200;
TMOD = 0x20; // timer 1 8-bit auto-reload
SCON = 0x50; // Tx and Rx enable
if(baud == a)
{
TL1 = 0xFD;
TH1 = 0xFD;
}
if(baud == b)
{
TL1 = 0xFA;
TH1 = 0xFA;
}
if(baud == c)
{
TL1 = 0xF4;
TH1 = 0xF4;
}
if(baud == d)
{
TL1 = 0xE8;
TH1 = 0xE8;
}
TR1 = 1; // Start timer
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Trasmitting 8 bit data
Send 8-bit data while callinjg this function
to send it over UART
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void uart_write(unsigned char value)
{
SBUF = value;
while(!TI);
TI = 0;
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Receiving 8-bit data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
char uart_read()
{
while(!RI);
RI = 0;
return(SBUF);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Xmitting String
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void uart_write_text(char *str)
{
unsigned char i=0;
while(str[i])
uart_write(str[i++]);
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Read a particular number of bytes in a string
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void uart_read_text(void *buff, unsigned int len)
{
unsigned int i;
for(i=0;i<len;i++)
{
((char*)buff)[i]=uart_read();
}
}
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Echoing received data
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
void uart_echo()
{
uart_write(uart_read());
}
void main()
{
unsigned char byte;
uart_init(9600);
//P2 = 0x00;
X=0;
Y=0;
delay(100);
uart_write_text("Welcome");
while(1)
{
byte = uart_read(); // receive a byte serially, wait 1 second and again send it back
if(byte == 'A')
{
X = 1;
}
if(byte == 'a')
{
X = 0;
}
if(byte == 'B')
{
Y = 1;
}
if(byte == 'b')
{
Y = 0;
}
delay(100); // little delay so that user can recognize it
uart_write(byte); // resend received data over UART
}
}
for more learning of Python Raspbery Pi, Internet of things , ESP 32 ,and Arduino click on courses
Seven-segment displays are commonly used to display numbers and characters in various electronic devices. They are easy to read, low-cost, and consume very little power. Interfacing a seven-segment display with a microcontroller like the 8051 is a simple task that can be accomplished with minimal hardware and software requirements.
In this blog post, we will discuss the basics of seven-segment displays and how to interface them with an 8051 microcontroller.
What is a Seven-Segment Display?
A seven-segment display is a display device consisting of seven LEDs arranged in a specific pattern to display numerals and some letters or symbols. Each of the seven LEDs can be controlled independently to display different combinations of characters. By turning on or off the appropriate LEDs, it is possible to display all the numbers from 0 to 9 and some letters like A, b, C, d, E, F.
The seven segments are labeled as A, B, C, D, E, F, and G. Each segment is connected to a different pin of the display. In addition, there is an eighth pin that controls the decimal point.
Interfacing a Seven-Segment Display with 8051: To interface a seven-segment display with an 8051 microcontroller, we need to connect the segments of the display to the output pins of the microcontroller. We also need to connect the common cathode or anode of the display to a suitable voltage source, depending on the type of display.
For a common cathode seven-segment display, we need to connect the common cathode pin to ground and the segment pins to the output pins of the 8051. For a common anode display, we need to connect the common anode pin to Vcc and the segment pins to the output pins of the 8051.
Once the display is connected to the microcontroller, we can write a program to control the display. We can use the P1 port of the 8051 to connect to the segment pins of the display. To display a number, we need to send the appropriate combination of signals to the segment pins. For example, to display the number 0, we need to turn on all the segments except G. Similarly, to display the number 1, we need to turn on only segments B and C.
Circuit:
Note : in above circuit diagram connect reset circuit to pin number 9 and crystal oscillator 11.0592 to Pin number 18 and 19
Code Example: Here is an example program to display the numbers 0 to 9 on a common anode seven-segment display connected to the 8051 microcontroller:
**************************************************************
#include <reg51.h>
#define SEG_PORT P1
void delay(unsigned int count) {
unsigned int i, j;
for(i=0; i<count; i++) {
for(j=0; j<1275; j++);
}
}
void display(unsigned char num) {
switch(num) {
case 0: SEG_PORT = 0xC0; break;
case 1: SEG_PORT = 0xF9; break;
case 2: SEG_PORT = 0xA4; break;
case 3: SEG_PORT = 0xB0; break;
case 4: SEG_PORT = 0x99; break;
case 5: SEG_PORT = 0x92; break;
case 6: SEG_PORT = 0x82; break;
case 7: SEG_PORT = 0xF8; break;
case 8: SEG_PORT = 0x80; break;
case 9: SEG_PORT = 0x98; break;
default: SEG_PORT = 0xFF; break;
}
}
void main() {
unsigned char i;
while(1) {
for(i=0; i<=9; i++) {
display(i);
delay(500);
}
}
}
In this code, we define the SEG_PORT pin using a #define statement. We also define a delay function to add some delay between the display of each number. The display() function is used to display a number on the seven segment display. We use a switch statement to determine which segments of the display need to be lit up for each number. Finally, in the main function, we use a for loop to continuously display numbers 0-9 on the seven segment display, with a delay of 500ms between each number. The while(1) loop is used to keep the program running indefinitely.
Note that this code assumes that the seven segment display is connected to the 8051 microcontroller as follows: the common anode pin is connected to ground, and the 7 segment pins (A-G) are connected to P1. You may need to modify these pins depending on your specific hardware configuration
Interfacing an LCD (Liquid Crystal Display) to a microcontroller is a common task in embedded systems design. we are making its simplicity and ease of use. In this blog post, we will discuss how to interface an LCD to an 8051 microcontroller in 4-bit mode.
LCD Basics
LCD is a display that uses the properties of liquid crystals to produce an image. It consists of an array of pixels that can be individually controlled to produce text and graphics. The most commonly used type of LCD is the character LCD, which displays characters and symbols in a fixed format.
LCD requires a minimum of 7 pins to interface with a microcontroller: RS, RW, E, and 4 data pins. RS (Register Select) and RW (Read/Write) pins are used to select between data and command modes and to control the direction of data flow. The E (Enable) pin is used to trigger the LCD to latch in data. The 4 data pins are used to send the 4-bit or 8-bit data to the LCD.
Interfacing an LCD to 8051 Microcontroller
follow these steps:
1.Connect the power supply: An LCD requires a power supply of +5V and 0V. The +5V can be obtained from the 8051 microcontroller’s Vcc pin, and 0V can be obtained from the GND pin.
2.Connect the control pins: Connect the RS, RW, and E pins of the LCD to the 8051 microcontroller’s GPIO pins. Set the RS pin to 0 for command mode and 1 for data mode. The RW pin should be set to 0 to write data to the LCD. The E pin should be pulsed high and low to trigger the LCD to latch in data.
3.Connect the data pins: Connect the 4 data pins of the LCD to the 4 GPIO pins of the 8051 microcontroller. We are using 4-bit mode for this example, so we only need to connect the 4 least significant data pins (D4-D7) of the LCD to the GPIO pins of the 8051 microcontroller.
4.Initialize the LCD: To initialize the LCD, we need to send some commands to it.
The following commands are commonly used:
a. Function Set: This command sets the interface data length, number of display lines, and font size. The command is 0x28 for 4-bit mode.
b. Display ON/OFF: This command turns the display on or off. The command is 0x0C for display on and 0x08 for display off.
c. Clear Display: This command clears the display and sets the cursor to the home position. The command is 0x01.
5.Write data to the LCD: To display data on the LCD, we need to send the data to it. We set the RS pin to 1 to select data mode and the RW pin to 0 to write data. We then send the data in 4-bit mode, one nibble at a time. We pulse the E pin high and low after each nibble to latch in the data.
In this code, we define the RS, RW, E, and LCD_PORT pins using #define statements. We also define a delay function to add some delay between the execution of each instruction. The lcd_cmd() function is used to send commands to the LCD, and the lcd_data() function is used to send data to the LCD. The lcd_init() function is used to initialize the LCD with some common commands. Finally, in the main function, we call the lcd_init() function to initialize the LCD, and then we send the string “Hello, World” to the LCD using the lcd_data() function. The while(1) loop is used to keep the program running indefinitely.
Note :LCD is connected to the 8051 microcontroller as follows: RS is connected to P1.0, RW is connected to P1.1, E is connected to P1.2, and the 4 data pins (D4-D7) are connected to P2.0-P2.3. You may need to modify these pins depending on your specific hardware configuration.
Conclusion
Interfacing an LCD to an 8051 microcontroller in 4-bit mode is a simple task that can be accomplished with a few GPIO pins. By following the steps outlined in this blog post, you can easily display data on an LCD using an 8051 microcontroller. With this knowledge, you can create a wide range of embedded systems projects that use an LCD for user interaction and