Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
29 views11 pages

ESD Project

Uploaded by

anmolrehan68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views11 pages

ESD Project

Uploaded by

anmolrehan68
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

EMBEDDED SYSTEM DESIGN

J-Component Report

Bluetooth Enabled Smart Bulb using STM32

Team Members:
Anmol Rehan (20BEE0024)
Arka Dey (20BEE0105)

Course Code: EEE4020


Slot: G1
Faculty Name: Prof. SelvaKumar K
Date: 24/11/2023
Introduction:
In this project, we make a Bluetooth enabled Smart Bulb with STM32. Home
automation involves automating household environment equipment. To
achieve that, we have created a smart bulb that is easy to install, and the
attached equipment can be controlled over a web browser or smartphone app.
The aim of this project is to control different home appliances using a web
browser or smartphone.
The project is showcasing a simple way of using a HC05 Bluetooth Module to
turn on and off a Smart light bulb that is connected to the STM32 Board via a
5V Relay. It accepts 3 different inputs from the UART:
input Result

1 Manually turn the light bulb on

0 Manually turn the light bulb off

Components Required:
● STM32F401 Nucleo Microcontroller
● STM32CubeIDE

● A 5V Relay

Relay is one kind of electro-mechanical component that functions as


a switch. The relay coil is energized by DC so that contact switches
can be opened or closed. A single channel 5V relay module generally
includes a coil, and two contacts like normally open (NO) and
normally closed (NC).
● A Light Bulb

● A HC05 Bluetooth Module

The HC-05 Bluetooth module is a popular wireless communication module


widely used in electronics projects. Operating on the Bluetooth 2.0
standard, it offers a reliable and low-cost solution for establishing wireless
connections between devices. With a working voltage of 3.3V and a
communication range of approximately 10 meters, the HC-05 is versatile for
various applications, such as wireless data transmission and remote control.
Its UART interface simplifies integration with microcontrollers, making it
suitable for Arduino and other embedded systems. Additionally, the module
supports multiple communication modes, including master and slave,
providing flexibility in creating diverse Bluetooth-enabled projects.
Circuit Diagram:
As the relay was rated at 5V input and our STM32 board could only give an
output of maximum 3.3V, we created an inverter circuit using an npn
transistor (BC547) with a pull-up configuration (5V) so as to get good one and
good zero for the relay input.
Code:
#include "main.h"
#define BUFFER_LEN 1
UART_HandleTypeDef huart1;
uint8_t RX_BUFFER[BUFFER_LEN] = {0};
uint8_t status = 0;
uint8_t debug_var = 0;
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if(huart->Instance == huart1.Instance)
{
HAL_UART_Receive_IT(&huart1, RX_BUFFER, BUFFER_LEN);
status = RX_BUFFER[0];
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
HAL_UART_Receive_IT(&huart1, RX_BUFFER, BUFFER_LEN);
while (1)
{
if(RX_BUFFER[0] == '1')
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 1);
debug_var = 1;
}
else if(RX_BUFFER[0] == '0')
{
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_5, 0);
debug_var = 0;
}
}
}
void SystemClock_Config(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
__HAL_RCC_PWR_CLK_ENABLE();
__HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2
);

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PLLM = 8;
RCC_OscInitStruct.PLL.PLLN = 80;
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
RCC_OscInitStruct.PLL.PLLQ = 4;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
{
Error_Handler();
}
RCC_ClkInitStruct.ClockType =
RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
{
Error_Handler();
}
}
static void MX_USART1_UART_Init(void)
{
huart1.Instance = USART1;
huart1.Init.BaudRate = 9600;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK)
{
Error_Handler();
}
}
static void MX_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_GPIOH_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Pin = LED_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
}
void Error_Handler(void)
{
__disable_irq();
while (1){}
}
#ifdef USE_FULL_ASSERT
void assert_failed(uint8_t *file, uint32_t line){}
#endif
Results:
Demonstration Link

Conclusion:
In conclusion, our project successfully showcased the integration of STM32,
HC05 Bluetooth Module, and smartphone-based control for a Smart Bulb. The
project's versatility allows users to control home appliances conveniently.
Emphasizing safety precautions, especially concerning high voltages, highlights
our responsible approach. Overall, the project demonstrates the practical use
of embedded systems and wireless communication in home automation.

You might also like