You are on page 1of 5

PRACTICAL 7 GROUP2

BATCH1
CONTROLLING LED USING TELEGRAM BOT

Hardware Requirements

1. Raspberry Pi Model A/B/B+

2. LED

3. Breadboard

4. Jumper Wires

Connect 4 LED with Raspberry Pi's GPIO Pins.


(Here only 1 Red LED is connected)

Yellow Positive Pin 33 GPIO 13

Negative of all Pin 9 GND

Red Positive Pin 31 GPIO06


Install Telegram App in Mobile. Follow process to obtain access
token

Install Telegram Bot on Raspberry Pi

Install python-pip and telepot on the system using the below commands
respectively..

sudo apt-get install python-pip

Sudo pip install telepot


SOURCE CODE:

import telepot from telepot.lop

import MessageLoop

red = 21

now = datetime.now()

GPIO.setmode (GPIO.BCM)

GPIO.setwarnings (False)

GPIO.output(red,0)

#LED Red GPIO.setup(red, GPIO. OUT) GPIO.output (red, 0) #Off initially

def action(msg):

chat_id = msg['chat']['id']

command = msg['text']

print ('Received: %s % command')

if 'on' in command:

message = "on"

if 'red':

message = message + "red"

GPIO.output (red, 1)

message = message + "light(s)"

telegram_bot. sendMessage (chat_id, message)


if 'off' in command:

message = "off"

if 'red' in command:

message = message + "red"

GPIO.output (red, 0)

message = message + "light(s)" telegram_bot. send Message (chat_id,


message)

telegran_bot = telepot.Bot('915524308:
AAGmc_b1H9E_XvMfnMKTaExWqPL40ttbAdo')print (telegram_bot.getMe())

MessageLoop(telegram_bot, action).run_as_thread() p

rint ('Up and Running....')

while 1:

time. sleep(10)

OUTPUT:
Output video is also posted in classwork along with this document as an external

file

You might also like