This project is a Telegram-controlled smart bulb system using a Bolt IoT module and a relay. With a simple message like /on
or/off
on Telegram, the user can switch a regular 230V AC bulb on or off from anywhere in the world.
I wanted to explore how everyday appliances could be remotely controlled using affordable IoT tools. Many smart home solutions are expensive or complex — this project simplifies it using basic components and open platforms like Telegram and Bolt IoT.
Applications of This Project:
This project demonstrates how IoT and automation can simplify real-world tasks. Below are some practical applications:
Smart Home Automations:
Control your home appliances like lights, fans, or coffee makers remotely using Telegram — from anywhere in the world.
Timed Appliance Control
The automatic switch-off feature after a delay makes it ideal for:
- Night lamps that turn off after a few seconds.
- Electric kettles or irons to avoid overheating.
- Lights in corridors or bathrooms.
Energy Efficiency
- Reduces electricity waste by ensuring devices turn off automatically after a set time, even if the user forgets.
Components Used In The Project:
a) Single-Channel 5V Relay
b) BOLT IOT Module:
c) BULB
d) Bulb Holder
e) 2 Pin Socket
- A Telegram bot receives user commands (
/on
,/off
). - These commands trigger a Python script that sends a web API request to Bolt IoT.
- The Bolt WiFi module receives the request and controls a relay module, which switches the bulb.
- The relay is low-level triggered, so it activates when the GPIO pin is set to
LOW
.
Click here to connect your BOLT IOT to your personal Wi-Fi.
STEP-1:Making the Circuit Connections....!
- COM (Relay): Connected to the live AC wire.
- NO (Normally Open): Connected to the bulb's live input.
- Bulb Neutral: Directly connected to the AC socket neutral.
- Relay VCC & GND: Connected to Bolt module's 5V and GND.
- Relay IN Pin: Connected to GPIO '1' of the Bolt module.
- Make a telegram bot. You can refer this video:
Step-3: Installing Python and installing suitable libraries for telegram and then creating a local server for it.
Refer the website to install Python locally on your Windows System: https://builtin.com/software-engineering-perspectives/how-to-install-python-on-windows
Use the below command on your CMD to install libraries related to Telegram.
pip install python-telegram-bot --upgrade
- You must make sure the Python edition is equal to or above 3.11.
- The edition of telegram library must be v13.0.
- Both can be checked using the commands:
python --version
pip show python-telegram-bot
- Once done, create a new file on Notepad and paste this code. This code will help you create your own server which can allow you to commnunicate with the BOLT IOT locally.
from telegram.ext import Updater, CommandHandler
import requests
import time
import logging
# Replace with your actual keys
BOLT_API_KEY = 'abc'
DEVICE_ID = 'xyz'
BOT_TOKEN = 'asd'
# Enable logging (optional but helpful for debugging)
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO)
# Function to turn ON the bulb and automatically turn it OFF after 5 seconds
def turn_on(update, context):
url_on = f'https://cloud.boltiot.com/remote/{BOLT_API_KEY}/digitalWrite?pin=1&state=LOW&deviceName={DEVICE_ID}'
response_on = requests.get(url_on)
if response_on.ok:
update.message.reply_text('Bulb turned ON !!')
time.sleep(5)
url_off = f'https://cloud.boltiot.com/remote/{BOLT_API_KEY}/digitalWrite?pin=1&state=HIGH&deviceName={DEVICE_ID}'
response_off = requests.get(url_off)
if response_off.ok:
update.message.reply_text('Bulb turned OFF automatically after 5 seconds.')
else:
update.message.reply_text('Bulb did not turn OFF !!')
else:
update.message.reply_text('Failed to turn ON the bulb !!')
# Optional manual OFF function
def turn_off(update, context):
url = f'https://cloud.boltiot.com/remote/{BOLT_API_KEY}/digitalWrite?pin=1&state=HIGH&deviceName={DEVICE_ID}'
response = requests.get(url)
if response.ok:
update.message.reply_text('Bulb turned OFF manually.')
else:
update.message.reply_text('Failed to turn OFF the bulb.')
def main():
updater = Updater(BOT_TOKEN)
dp = updater.dispatcher
dp.add_handler(CommandHandler("on", turn_on))
dp.add_handler(CommandHandler("off", turn_off))
updater.start_polling()
logging.info("Bot is running...")
updater.idle()
if __name__ == '__main__':
main()
- Replace the telegram bot api keys, BOLT ID and BOLT API keys in the code and save the file as bolt_telegram_bot.py.
NOTE: The BOLT ID and BOLT API keys can be found from cloud.boltiot.com
Code Explanation:
The script utilizes Python’s telegram.ext
library to interface with the Telegram Bot API and requests
to interact with the Bolt IoT Cloud API. The bot is initialized with a valid Telegram Bot Token using the Updater
class. When a user sends the /on
command, the bot issues an HTTP GET
request to the Bolt Cloud, setting GPIO pin 1 to LOW
— activating a low-level triggered relay that powers the bulb. A time.sleep(5)
call introduces a delay before another request sets the pin to HIGH
, deactivating the relay and turning the bulb off. An additional /off
command allows users to turn the bulb off manually. The system provides real-time feedback via Telegram messages and logs key events using Python’s logging
module. All API keys and device IDs are stored as constants for easy configuration.
STEP-3: Final Stage
- Power up your devices using a 5V adapter and turn on your AC supply.
- Open your CMD on Windows and run it as adminstrator.
- Using cd command (Change Directory), choose the location you have saved your code in.
After changing the directory, run the python file as mentioned:
python bolt_telegram_bot.pyYou will be getting an output screen as:
Thus now you have sucessfully created a local server using Python.
Now, open your Telegram application and search for bot that you created. Write /start and give it commands /on or /off.
Now you can control your Bulb using a Telegram from anywhere in the world..!!!!
Check Out the working of the project here: 📽️ (Youtube)
Comments