🔥 How to Make the Best IoT Project Using PIC16F877A | Bluetooth Controlled Relay System

by Jhuman in Circuits > Electronics

62 Views, 3 Favorites, 0 Comments

🔥 How to Make the Best IoT Project Using PIC16F877A | Bluetooth Controlled Relay System

IOT Device 2.jpg

In this project, we’ll learn how to design and build a complete IoT-based control system using the PIC16F877A microcontroller.

This project allows you to control electrical appliances wirelessly via Bluetooth — an ideal example of combining microcontroller programming, communication, and circuit design for smart home automation.

🧠 Project Overview

This IoT-based Bluetooth Relay Control System uses the PIC16F877A microcontroller to receive commands from a Bluetooth module and control multiple relays connected to electrical loads.

It’s a perfect embedded systems project for IoT learners, electronics students, and automation enthusiasts.

You’ll learn:

  1. Bluetooth communication with PIC microcontroller
  2. Relay interfacing and switching logic
  3. Circuit simulation and PCB design using Proteus
  4. Mobile app control via serial commands


Supplies

⚙️ Components Required

Below is the complete list of components used in this IoT project:

  1. PIC16F877A Microcontroller (1 pc)
  2. Bluetooth Module HC-05 or HC-06 (1 pc)
  3. 5V Relay Module (4 pcs)
  4. Transistor BC547 or TL917 (4 pcs)
  5. Resistors 330Ω (4 pcs)
  6. Resistors 10kΩ (4 pcs)
  7. LED Indicators (4 pcs)
  8. Diodes 1N4007 (4 pcs)
  9. Voltage Regulator IC 7805 (1 pc)
  10. Electrolytic Capacitor 100µF (2 pcs)
  11. Ceramic Capacitor 104pF (2 pcs)
  12. Crystal Oscillator 20MHz (1 pc)
  13. 22pF Capacitors (2 pcs)
  14. Push Buttons / Switches (3 pcs)
  15. DC Power Jack (1 pc)
  16. Jumper Wires (as needed)
  17. 12V DC Power Supply (1 pc)
  18. Custom PCB Board (1 pc)

💻 Circuit Diagram Explanation

Screenshot 2025-10-07 180515.png

Discover Easy, Affordable, and Reliable PCB manufacturing with JLCPCB!Register to get $70 New customer coupons:https://jlcpcb.com/?from=EST

Special Deal: Get a $30 coupon for JLCPCB premium 6-layer PCBs: https://jlcpcb.com/6-layer-pcb?from=getcoupon


The circuit diagram (shown above) illustrates how the PIC16F877A communicates with the Bluetooth module and controls four relays through its PORTB pins.

  1. Bluetooth Communication:
  2. The Bluetooth module is connected to the microcontroller via RC6 (TX) and RC7 (RX) pins for UART communication.
  3. Relay Control:
  4. Relays are connected to pins RB0, RB1, RB2, and RB3 using transistors as drivers. Each relay operates an LED indicator for visual feedback.
  5. Power Supply:
  6. The circuit uses a 7805 voltage regulator to step down and stabilize the 5V supply for both the microcontroller and Bluetooth module.

🧾 C Code Explanation

Here’s the C code used to control the relays via Bluetooth commands. The code is written in MPLAB X IDE using the XC8 compiler.


#include <16f877a.h>

#fuses HS, NOWDT, NOPROTECT, NOLVP

#use delay(clock=20000000)

#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)


#define RELAY1 PIN_B0

#define RELAY2 PIN_B1

#define RELAY3 PIN_B2

#define RELAY4 PIN_B3


void main() {

char data;

set_tris_b(0xF0); // RB0–RB3 as output


while(TRUE) {

if(kbhit()) {

data = getc();

switch(data) {

case '1': output_high(RELAY1); break;

case '2': output_low(RELAY1); break;

case '3': output_high(RELAY2); break;

case '4': output_low(RELAY2); break;

case '5': output_high(RELAY3); break;

case '6': output_low(RELAY3); break;

case '7': output_high(RELAY4); break;

case '8': output_low(RELAY4); break;

default: break;

}

}

}

}


📘 Code Description:

The program reads Bluetooth data using UART communication.

Each received character (‘1’–‘8’) triggers a corresponding relay ON/OFF action.

Four relays are controlled through PORTB pins RB0–RB3.

🧩 PCB Design Overview

Screenshot 2025-10-07 180434.png

The PCB layout, designed in Proteus ARES, integrates all components neatly on a single board.

Features of the PCB Design:

  1. Four relay control circuits with flyback diodes
  2. On-board Bluetooth interface
  3. 7805 regulator power supply section
  4. LED status indicators
  5. 12V DC input with polarity protection
  6. Clearly labeled connectors and ports

This compact PCB ensures durability, professional look, and ease of assembly for IoT and automation projects.

📱 Mobile App Integration

Screenshot 2025-10-07 180851.png

To control the system, connect your smartphone to the Bluetooth module (HC-05/06).

Use any Bluetooth Terminal App or Arduino Bluetooth Controller to send commands like:


1 → Turn ON Relay 1

2 → Turn OFF Relay 1

3 → Turn ON Relay 2

4 → Turn OFF Relay 2

5 → Turn ON Relay 3

6 → Turn OFF Relay 3

7 → Turn ON Relay 4

8 → Turn OFF Relay 4


🚀 Applications

✅ Smart Home Automation

✅ IoT-Based Device Control

✅ Industrial Load Switching

✅ Smart Energy Systems

✅ Embedded Systems Training Projects

🎯 Conclusion

You’ve now learned how to create a Bluetooth-controlled IoT project using PIC16F877A — from coding and circuit design to PCB layout and wireless control.

This project demonstrates the true power of microcontrollers in IoT automation, and you can easily upgrade it with Wi-Fi (ESP8266), sensors, or mobile app dashboards for more advanced applications.

Video Reference

চলুন IOT Home Automation ডিভাইস নিজেরাই তৈরি শিখি 🔥 EST Experiments

Discover Easy, Affordable, and Reliable PCB manufacturing with JLCPCB!Register to get $70 New customer coupons:https://jlcpcb.com/?from=EST

Special Deal: Get a $30 coupon for JLCPCB premium 6-layer PCBs: https://jlcpcb.com/6-layer-pcb?from=getcoupon