STM32

STM32 Bluetooth Home Automation with Feedback, STM32CubeIDE

STM32 Bluetooth:

 

STM32 Bluetooth Home Automation with Feedback, STM32CubeIDE– Today, we are going to make the world’s fastest Home Automation system using the STM32F103C8T6 controller board, HC05 or HC06 Bluetooth Module, a Solid-state 4-channels relay module, and an android cell phone application designed in Android Studio.

Now, you might be wondering, “Why not just use Arduino for this job?” Well, buckle up as we unravel the reasons why STM32 steals the spotlight in this home automation extravaganza.

allpcb circuit




Arduino has long been a favorite for DIY projects, but STM32 is preferred over the Arduino for more complex projects due to its advanced ARM Cortex-M architecture, offering higher processing power, larger memory, and a wide range of peripherals. It excels in multitasking, real-time capabilities, and provides a more robust development environment, making it ideal for applications that demand performance and scalability beyond the capabilities of Arduino.

STM32 Bluetooth

During initial experiments, I used mechanical relays that we commonly use. Even now, I can control loads at a considerable speed, and I believe this switching speed is sufficient. However, my goal is to create the world’s fastest home automation system, and achieving this is not possible by using mechanical relays.

STM32 Bluetooth

Mechanical relays are slow due to the physical movement involved in their operation. The mechanical parts, such as contacts, have inertia, leading to delays in switching. Additionally, contact bounce, where contacts make and break several times before stabilizing, contributes to the overall response time. The energizing and de-energizing of the relay coil also take time, influenced by both electrical and mechanical factors. And because there are moving parts in it, the lifespan of mechanical relays is also reduced due to wear and tear.



Anyway, I replaced the mechanical relays with the Solid-state relays and then I was like wow.

STM32 Bluetooth

In contrast, solid-state relays (SSRs) use electronic components for switching, eliminating mechanical parts and offering faster response times, making them more suitable for applications requiring rapid and precise switching.

This home automation system is not only faster but also quite user-friendly. As you can see, I have some loads currently switched on.

STM32 Bluetooth

For now, let’s imagine these loads are installed in another room. After a couple of hours, I want to switch one of these loads on or off, but I’ve forgotten which one I turned ON or turned OFF. To eliminate this kind of confusion, I’ve integrated a feedback feature into this home automation system. As soon as I open the application on my cell phone, STM32, through Bluetooth, provides me with feedback on which load is currently on and which one is off.

STM32 Bluetooth

This ensures seamless control and eliminates any confusion.

What are your thoughts on this feedback idea? Drop a comment and let me know!



You can program the STM32 controller board using the Arduino IDE, I have explained it in several videos and articles, and you can also program the STM32 controller board using the STM32CubeIDE, and I have explained it in my 45 minutes long video and article “STM32 CubeIDE course”.

Anyway, using STM32CubeIDE over Arduino IDE for programming the STM32 controller board offers several advantages. STM32CubeIDE is tailored specifically for STM32 microcontrollers, providing advanced debugging features, a graphical interface for peripheral configuration, and seamless integration with STM32CubeMX.

Its support for complex projects, real-time capabilities, and optimized code generation make it superior for leveraging the full potential of STM32 architecture. In contrast, Arduino IDE, designed for simplicity, may lack the sophisticated tools required for complex STM32 applications. STM32CubeIDE streamlines development with a comprehensive ecosystem, making it the preferred choice for developers aiming for efficiency, precision, and optimal performance in STM32-based projects.

Note: Read my article on ESP32 and Low Energy BLE Application.

Amazon Links:

STM32F103C8T6

Solid State Relays module

HC05 Bluetooth Module

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!



Stm32 Bluetooth, Circuit diagram:

STM32 Bluetooth

About STM32 Cube IDE:

I have already created a 45-minute video on the STM32 and CubeIDE, where I explained the technical specifications of the STM32 board, I explained its pin configurations, demonstrated how to upload a program to the STM32 board using ST-link V2, and I have also explained how to setup your STM32CubeIDE. I’ve covered every detail comprehensively. Therefore, I highly recommend that you watch that video because I won’t be explaining those things again right now. You can also read my article on “STM32 course”.

Connect your STM32 board to the Laptop via ST-link V2; you can follow this connections diagram.

STM32 Bluetooth




STM32 Bluetooth Programming:

While the STM32CubeIDE is open; to start a new project, go to the File then to New, and click on the STM32 Project.

STM32 Bluetooth

STM32CubeIDE may take a moment to load and download the necessary libraries. Please be patient during this process as it may take some time depending on the speed.

On the Target Selection Window and while the MCU Selector Tab is active; select the Commercial Part Number that is STM32F103C8T6, Select it from the MCUs list and then click on the Next Button.

STM32 Bluetooth



Write the project name.

STM32 Bluetooth

Select the

  • Targeted Language.
  • Target Binary Type. and
  • Targeted Project Type.

On the Pinout & Configuration Tab click on the System Core and select SYS. Click on the Debug and select Serial Wire.

STM32 Bluetooth

 Next, click on the USART2 and on the Mode drop down menu select Asynchronous.

STM32 Bluetooth

Next, we are going to set the GPIO pins PB9, PB8, PB7, and PB6 as the outputs. We are using these pins to control a 4-channels relay module.

STM32 Bluetooth

Finally, click on the save button if it asks you Do you want to generate Code?  click yes, again press the yes button. STM32CubeIDE will generate the necessary code based on your pin configuration and open the associated perspective. This perspective provides you with the appropriate tools and views for further development and customization of your project.

STM32 Bluetooth

This is the generated code and now we will need to modify it in order to control the loads and send the feedback message to the android cell phone application. I have already done it. You will need to download the following code, next select the generated code, delete it and paste the following code.



STM32 CubeIDE Code:

Finally, click the save button and then click on the Hammer Icon or Build.

STM32 Bluetooth

There are no errors and warnings now we can click on the Play button.



STM32 Bluetooth

  • Click on the Debugger Tab.
  • Select ST-LINK.
  • Click on Show Generator options and set the Reset Mode to Software system reset

and click the Apply button and then click the OK button. Finally, click the run button and that’s it.

STM32 Bluetooth

You can see the shutdown command invoked, this means everything is done correctly, now you can unplug your stm32 and plug it again. Connect your android application and start controlling your home appliances.

Download the App:

Read my article on Android App development if you want to design your own android application.




Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Related Articles

One Comment

  1. Your needs come first! Purplewaveindia has no agendas, and no loyalties to anyone other than you, our client. Purplewaveindia was established in 2018. And in a short span of 4-years, Purplewaveindia has become one of the prominent players in the Indian Audio Video Manufacturing and Integration Industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button