Build a Bluetooth smart switch with Arduino/ESP32 and control it via an Android app made with MIT App Inventor – no coding experience required for the app side. This complete DIY tutorial creates a wireless switch system for Indian homes that works without WiFi or internet, using classic Bluetooth (HC-05) or BLE (HM-10), making it ideal for rural areas or homes with unstable broadband.
Table of Contents
- Why Bluetooth Smart Switches for India?
- Hardware: HC-05 vs HM-10 vs ESP32 BLE
- Circuit: Arduino, Relay, and Bluetooth Module
- Arduino Firmware for Bluetooth Switch Control
- Building the Android App with MIT App Inventor
- Extending to Multi-Switch Control
- India Use Cases and Room Configurations
- Frequently Asked Questions
Why Bluetooth Smart Switches for India?
Bluetooth smart switches offer unique advantages for the Indian market:
- No WiFi dependency: Works in areas with limited/no broadband (village homes, farmhouses, storage godowns)
- No cloud subscription: Unlike Tuya/Alexa switches, there are zero monthly fees and no privacy concerns
- Low cost: HC-05 Bluetooth module (Rs 120) + Arduino Nano (Rs 200) + relay (Rs 30) = Rs 350 total per switch point
- No electrician for control: Add smart control without rewiring – the Bluetooth receiver fits inside a standard Indian gang box (60mm x 60mm modular)
- Custom app: MIT App Inventor app shows your home layout with room-labelled buttons – more intuitive than generic commercial apps
Recommended: UNO WiFi R3 (ATmega328P + ESP8266)
The UNO WiFi R3 provides both Bluetooth control via its ESP8266 module and physical relay switching. For multi-room Bluetooth switch systems, each room gets one UNO WiFi R3 acting as a Bluetooth peripheral.
Hardware: HC-05 vs HM-10 vs ESP32 BLE
| Module | Protocol | India Price | Range | App support |
|---|---|---|---|---|
| HC-05 | Bluetooth 2.0 Classic SPP | Rs 120 | 10m | MIT App Inventor (BluetoothClient) |
| HM-10 | BLE 4.0 | Rs 150 | 15m | MIT App Inventor (BluetoothLE) |
| ESP32 built-in | BLE 5.0 | Rs 400 (full board) | 30m | MIT App Inventor (BluetoothLE) |
For this tutorial we use HC-05 with MIT App Inventor’s BluetoothClient component (most widely documented approach) and an Arduino UNO/Nano as the controller.
Circuit: Arduino, Relay, and Bluetooth Module
HC-05 Bluetooth Module:
VCC -> Arduino 5V
GND -> Arduino GND
TXD -> Arduino RX (pin 0) [or SoftwareSerial pin]
RXD -> Arduino TX via 1kohm+2kohm voltage divider to 3.3V
Relay Module (5V coil, optocoupler isolated):
VCC -> Arduino 5V
GND -> Arduino GND
IN1 -> Arduino Digital Pin 8 (Light)
IN2 -> Arduino Digital Pin 9 (Fan)
IN3 -> Arduino Digital Pin 10 (Plug point)
IN4 -> Arduino Digital Pin 11 (Spare)
The voltage divider on HC-05 RXD is essential – HC-05 logic is 3.3V but Arduino TX outputs 5V. Connecting 5V directly to HC-05 RXD can permanently damage the module.
Arduino Firmware for Bluetooth Switch Control
#include <SoftwareSerial.h>
SoftwareSerial btSerial(2, 3); // RX, TX (use pins 2,3 to keep pins 0,1 free for USB)
const int RELAY_PINS[] = {8, 9, 10, 11};
const int NUM_RELAYS = 4;
bool relayState[4] = {false, false, false, false};
void setup() {
for (int i = 0; i < NUM_RELAYS; i++) {
pinMode(RELAY_PINS[i], OUTPUT);
digitalWrite(RELAY_PINS[i], HIGH); // Active LOW: HIGH = OFF
}
btSerial.begin(9600);
Serial.begin(9600);
}
void loop() {
if (btSerial.available()) {
char cmd = btSerial.read();
// Commands: '1','2','3','4' = toggle; 'A','B','C','D' = ON; 'a','b','c','d' = OFF
if (cmd >= '1' && cmd <= '4') {
int idx = cmd - '1';
relayState[idx] = !relayState[idx];
digitalWrite(RELAY_PINS[idx], relayState[idx] ? LOW : HIGH);
// Send status back
btSerial.print("S");
for (int i = 0; i < NUM_RELAYS; i++) btSerial.print(relayState[i] ? '1' : '0');
btSerial.println();
}
}
}
Recommended: Mega WiFi R3 (ATmega2560 + ESP8266)
Scale up to whole-home Bluetooth control with the Mega WiFi R3. Its 54 digital I/O pins handle 16+ relay channels, and the built-in ESP8266 adds WiFi bridge capability when your router is available.
Building the Android App with MIT App Inventor
Go to ai2.appinventor.mit.edu and sign in with a Google account. Create a new project:
Designer Screen Setup
- Add BluetoothClient component (non-visible, from Connectivity palette)
- Add a ListPicker button labelled “Connect to Bluetooth” – this will scan for paired devices
- Add 4 ToggleButton components labelled: Light, Fan, Plug Point, Spare
- Add a Label for connection status display
- Arrange in a vertical layout with your home name as the title
Blocks Editor Logic
// ListPicker.BeforePicking
set ListPicker.Elements to BluetoothClient.AddressesAndNames
// ListPicker.AfterPicking
if BluetoothClient.Connect(ListPicker.Selection)
set StatusLabel.Text to "Connected"
// ToggleButton1.Click (Light)
if BluetoothClient.IsConnected
BluetoothClient.SendText("1") // Toggle command
// Update button text based on state received
Build the APK (Build > Android App APK) and install on your Android phone. Enable Bluetooth, pair the HC-05 (default PIN: 1234 or 0000), and connect. Each button toggle sends a character command and receives the current relay states back.
Extending to Multi-Switch Control
For whole-home control from one app, pair multiple HC-05 modules to one phone simultaneously:
- Name each HC-05 uniquely via AT commands:
AT+NAME=BEDROOM,AT+NAME=KITCHEN - In MIT App Inventor, use multiple BluetoothClient components (one per room module)
- Add a room selector (TabbedLayout or separate screens) in the app for intuitive navigation
- Limit: Android can maintain ~7 simultaneous Bluetooth connections (more than enough for Indian homes)
India Use Cases and Room Configurations
Common 4-relay configurations for Indian rooms:
- Living room: Main light, fan, TV plug point, decorative/diya lamp
- Master bedroom: Main light, fan, AC control (via SSR), charging point indicator
- Kitchen: Main light, exhaust fan, chimney, water purifier plug
- Terrace/balcony: Security light, garden water pump, decorative string lights
Recommended: 12V 1-Channel Relay Module (RS485/Modbus)
This optocoupler-isolated relay module provides safe switching for your Bluetooth-controlled Indian home appliances. The RS485 interface also allows wired fallback control when Bluetooth range is exceeded.
Frequently Asked Questions
- Can I use MIT App Inventor for iOS (iPhone)?
- MIT App Inventor only creates Android apps. For iOS, use the MIT App Inventor companion app for testing only – distributing to iPhone users requires Xcode. Alternatively, use Blynk (works on both Android and iOS) with HC-05 via a custom UART-to-WiFi bridge.
- What is the maximum Bluetooth range in an Indian flat?
- HC-05 Class 2 module: 10m in open air, approximately 5-7m through one Indian concrete wall. For 2BHK coverage, you need separate HC-05 modules per room cluster. HM-10 (BLE) and ESP32 BLE offer better range at 15-30m.
- Will the relay switch be active during a phone reboot or disconnect?
- Relay states are preserved via the Arduino’s current GPIO levels, not stored in EEPROM. On Arduino power cycle, all relays reset to the boot state (all OFF for active-LOW configuration). Add EEPROM state saving if persistence across power cuts is needed.
- Can family members in the same house control switches from their own phones?
- Classic Bluetooth (HC-05) supports only one master connection at a time. For multi-user access, use BLE (HM-10 or ESP32) which supports multiple concurrent connections, or switch to WiFi-based control with a shared MQTT broker.
- Is the HC-05 module legal to use in India?
- Yes. Bluetooth operates in the 2.4GHz ISM band which is license-exempt in India under WPC (Wireless Planning and Coordination Wing) regulations for low-power (up to 1W) devices. The HC-05 at 4dBm output power is well within limits.
Add comment