You are on page 1of 55

HOME AUTOMATION USING TELEGRAM BOT

A Term Paper / Project

Report
Submitted in the partial fulfillment of the requirements for
the award of the degree of

Bachelor of Technology

in

Department of Electronics and Communication


By

K Kishore Babu - 170040400


V V N Chakravarthy - 170040924
V GopiRam - 170040957

under the supervision of

Dr. Ch.SreeVardhan (Professor,Guide)

1
Declaration

The (Term Paper/Project) Report entitled “ HOME AUTOMATION USING TELEGRAM BOT“ is a
record of bonafide work of K KishoreBabu(170040400),VVN Chakravarthy(170040924), V
GopiRam(170040957) submitted in partial fulfillment for the award of B.Tech in Electronics and
Communications to the K L University. The results embodied in this report have not been copied from
any other departments/University/Institute.

Signature of the Students

170040400 – K Kishore
170040924 – V V N Chakravarthy
170040957 - V GopiRam

2
Department of Electronics & Communication Engineering

CERTIFICATE

This is to certify that the project entitled “HOME AUTOMATION USING TELEGRAM BOT”
is the bonafide work carried out by V.V.N.CHAKRAVARTHY (170040924) students of IV year
B.Tech, E.C.E dept, College of Engineering, K.L deemed to be University The results embodied in
this report have not been copied from any other departments/University/Institute.

Signature of the Supervisor Signature of External Examiner

Head of the department

3
ACKNOWLEDGMENT

It is great pleasure for me to express my gratitude to our honourable President Sri. Koneru
Satyanarayana, for giving the opportunity and platform with facilities in accomplishing the
project report.

I express the sincere gratitude to our faculty Dr.N.V.K.Ramesh for his administration towards
our academic growth.

I record it as my privilege to deeply thank our pioneer, Dr. Suman Maloji HOD-ECE for
providing us the efficient faculty and facilities to make our ideas into reality.

I express sincere gratitude to our research head Dr. D. Bhavana for his leadership and constant
motivation provided in successful completion of our academic semester.

I express my sincere thanks to our project supervisor Dr.Ch.Sreevardhan for their novel
association of ideas, encouragement, appreciation and intellectual zeal which motivated us to
venture this project successfully.

Finally, it is pleased to acknowledge the indebtedness to all those who devoted themselves
directly or indirectly to make this project report success.

Place: KL University S. No Name of the Student


Date : 16-12-2020
1 V.V.N.CHAKRAVARTHY(170040924)

4
ABSTRACT

As we are heading towards digital era where machine to machine interaction takes place with the
help of Internet of things. The appliances in the home, office and industry are becoming smart every
day. Various implementations of IoT could be done by using both proprietary hardware and open
hardware. This project provides technologies and models that allow people to communicate with
different hardware for different purposes. This paper aims at designing a home security system
using Raspberry Pi.

This project seeks to introduce the integration between the smartphone messenger Telegram and
the Raspberry Pi platform using Telegram Bots, allowing common people to create hardware
prototypes and communicate with them using the same tool applied in the communication with
other people. Upon few software instructions, the Pi board would work as per the instructions with
the connected devices. I have placed a PI board with an OS and an application called “Telegram” to
deploy the IoT software to sense and state the condition of a device and also the temperature of the
location. Accordingly, I have recorded the values against the reports generated by the bot of
telegram.

5
INDEX

S. NO CHAPTER CONTENT PAGE


NO. NO.
1 1 INTRODUCTION 9
2 2 LITERATURE SURVEY 10
3 THEORETICAL ANALYSIS 13
3.1 HARDWARE DESCRIPTION 13
3
3.2 SDHC (SECURE DIGITAL HIGH
19
CAPACITY CELL)
3.3 RELAY 21
3.4 INITIAL STATE (IOT PLATFORM) 23
3
3.5 2N2222A TRANSISTOR DESCRIPTION 24
3.6 12V DC FAN 25
3.7 DHT11 29
3.8 PI CAMERA 31
3.9 BREADBOARD 33
3.10 RESISTOR 34
3.11 TELEPOT 35
4.0 EXPERIMENTAL INVESTIGATIONS 36
4.1 PROJECT CIRCUIT DIAGRAM 37
4 4 4.2 PROJECT BLOCK DIAGRAM 38
5 5 PROGRAM CODE 39
6 6 EXPERIMENTAL RESULTS 48
7 7 DISCUSSION OF RESULTS 52
8 8 CONCLUSION 54
9 9 FUTURE SCOPE 54
10 10 REFERENCES 55

6
1. INTRODUCTION

As the number of devices are increasing with the development of the technology, people are
getting more concerned about the electricity bill and the devises condition when they are a-part.
The rise if Technology industry and electronic industry is allowing us to make our home smart.
Home Automation enables us change the condition of the devises/home appliances which are used
frequently. Home Automation is developing now a-days and automation is often seen in several
fields. The idea of a fully functional smart home has been a dream since the mid of the twentieth
century.

The first trials started in the 1960s with the use of domestic smart devices, but this has become
reality only during the last decades. Smart home, as a term, was also introduced in 1984 by the
American Association of House builders. Since then, things have dramatically changed with
significant advances in the domain of intelligent building control.Now-a-days many technology
platforms are available for home automation process. The important role of this platform is to make
every device in the home connected and take necessary actions when a certain command is given.
There are too many common home automation protocols that enables the different devices to
communication with the common language to interact with them easily.

The Protocol is must because the user gets their product or devices from different brand, only with
the help of protocol functions the devices can communicate with other devices. Selection of
protocol is a difficult task. Choosing right protocol will help us to connect many devices of different
brand. The bot applications are making a world even better and smart and it will be very easy for
the users to communicate. It is changing the usage of other small devices. It will be more
convenient for the user to use a bot rather than using a traditional handheld device Nowadays
people are wishing to have a bot so it makes their work simple and it has a huge market in the
upcoming world. In this project, basic home appliances get connect to the telegram bot and one will
be able to control their home appliances from a distance or their work place.

7
2. LITERATURE SURVEY

[1] Telegram is a free cloud-based instant messaging service. Telegram clients exist for both
mobile and desktop systems. Users can send messages and exchange photos, videos, stickers, audio,
and files of any type. Telegram also provides optional end-to-end encrypted messaging. It also
provides bot service by creating a new bot using the telegram app one can control the appliances
present in the home or office by just chatting to the bot.

[2] The Internet of things (IoT) is the inter-networking of physical devices, vehicles (also referred
to as "connected art devices"), buildings, and other items embedded with electronics, software,
sensors,actuators, and network connectivity which enable these objects to collect and exchange data.
In 2013 the Global Standards Initiative on Internet of Things (IoT-GSI) defined the IoT as "a global
infrastructure for the information society, enabling advanced services by interconnecting (physical
and virtual) things based on existing and evolving interoperable information and communication
technologies" and for these purposes a "thing" is "an object of the physical world (physical things) or
the information world (virtual things), which is capable of being identified and integrated into
communication networks".

[3] Experts estimate that the IoT will consist of about 30 billion objects by 2020. Ishan Krishna,
K. Lavanya explained in the proposed system is very useful for elderly and physically disabled
persons who are in need of a physical assistance for daily needs. It eliminates the limitation of
wiring complications also the range of voice commands can be extended by using wireless routers
and lOT. On the off chance the viable usefulness and the cost of home automation decrease will
enable compatibility with future technologies for customized user support. It implies that creation
capacity as well as innovation level ought to enhance increasingly. In Future, the use of Arduino can
enable the control via., centralized server through smart mobile phones. Home Automation Systems
(HAS) have gained world-wide popularity these days. It guarantees security, surveillance and
solace to the user and make their life more comfortable.

8
[4] Cloud Based home automation system:

Home Automation using cloud based system focuses on design and implementation of home
gateway to collect data about data from home appliances and then send to the cloud-based data server
to get store on Hadoop Distributed File System, it is process using MapReduce and use to implement
a monitoring tasks to Remote user Presently home Automation System is persistently developing its
resilience by assimilating the current characteristics which gratify the rising interest of the people.
This paper presents the design and development of home automation system that use the cloud
computing as service. The current system consists of three important units: the first part is cloud
server, handle and controls the data and information of client and users and the status of devices the
hardware interface module is the second part which implement the relevant connection to the actuators
and sensing devices which give the physical service. Last part is Home Server, which construct the
hardware device and gives the user interface. This paper focus to build the web services using cloud
which is need for security and storage and availability of the data.

[5] Raspberry pie home automation:-

Home Automation System has been developed with Raspberry Pi by reading the algorithm
and subject of telegram. Raspberry Pi guarantees to be an efficient platform for implementation
powerful, and economic smart home automation. home automation using Raspberry pi is better than
any other home automation methods in several ways. For example, DTMF (dual tone multi-
frequency) using home automation, the call tariff is a big demerit, which is not the problem in their
proposed method. In Home Automation using web server, the design of web server and the memory
space required is dismiss by this method, because it just uses the already established web server
service given by telegram connectivity. LEDs were used to identify the switching action.

[6] This System is efficient and flexible interactive.

9
[7] Alkar and Buhur presented a home automation system (HAS) that uses internet to access the
home remotely and infrared communication for communication with the devices within home.

[8] Sunehra and Tejaswi implemented a speech based HAS using Bluetooth and GSM, which is
very comfortable to use by elderly and physically handicapped people who may not be able to
manually operate the home devices.
Sunehra and Veena implemented a HAS for controlling the home appliances through Email remotely and
Bluetooth when in the home. Anvekar and Banakar implemented an IoT based home security system using
telegram.

Fig. 1. Integration of Raspberry Pi and Telegram for Telegram chatbox

10
THEORITICAL ANALYSIS

3.1 HARDWARE DESCRIPTION

3.1.1 RASPBERRY PI 3 MODEL B+

The Raspberry pi is a small sized computer, which usually works on NOOBS (New Out of
the Box Software) or Raspbian software.

The Raspberry Pi is of three generations: Pi-1, Pi-2 and Pi-3, where each generation is classified
into two models: Model A and Model B.

The current work is based on Raspberry Pi-3B+ in fig 2, which comprises of 40 GPIO
(general- purpose input and output) pins, for which various home appliances such as lights,
fans, motors, Air conditioners etc. are connected.

Generally, Raspberry Pi has both ethernet and WIFI provision i.e., it has dual-band of

2.4 GHz and 5 GHz wireless LAN (local area network).

11
Fig 2 Raspberry pi board 3B+ and its components

12
3.1.2 SPECIFICATIONS

• Quad core 64-bit processor clocked at 1.4GHz.

• 1GB LPDDR2 SRAM.

• Dual-band 2.4GHz and 5GHz wireless LAN.

• Bluetooth 4.2 / BLE.

• Higher speed ethernet up to 300Mbps.

• Power-over-Ethernet capability (via a separate PoE HAT).

• CPU type – ARM cortex

3.1.3 RASPBERRY PI PARTS 3B+

• CSI Camera Connector

• 4 USB ports

• 5V Micro USB Power

• Ethernet Out Port

• HDMI

• Video and Audio Socket

• 40 General purpose Input Out Pins

• Micro SD Card Slot

• DSI Display Connector

• Ethernet Controller

• Broad Com

13
3.1.4 APPLICATIONS

• Residing room PC.

• A little scale web program.

• Arcade Pi.

• Robotics.

• Firefox OS on Pi.

• Bit Torrent Server.

• Climate Station.

• House robotization.

• Raspberry Pi Cluster.

• Gadget information.

3.1.5 ARCHITECTURAL OVERVIEW

The Raspberry Pi is reliant upon the Broadcom system on a chip (SoC), which
incorporates a sixty-four-bit quad-core ARM Cortex-A53, 1.4GHz processor, Video Core
IV GPU, and used to be toward the start moved with 512 megabytes of RAM, later refreshed
(mannequin B and model B+) to 1GB. The structure has quiet Digital (SD) or Micro SD
(mannequin B+) connections for boot media and decided accumulating. The Raspberry Pi 3
passes on a few events the preparing limit of past units. This second era Raspberry Pi has an
updated Broadcom BCM2837 processor, which is a compelling ARM Cortex-A53 based
quad-center processor that runs at 1.2GHz. The board in like manner involves an assortment
in memory potential to 1Gbyte.

14
3.1.6 PERFORMANCE

The Raspberry Pi 3, with a quad-center Cortex-A53 processor, is depicted as two or


multiple times the presentation of a Raspberry Pi 1. This used to be prescribed to be mainly
penniless upon mission hanging and guiding set use. Benchmarks tried the Raspberry Pi 3
to be generally 80% faster than the Raspberry Pi 2 in parallelized assignments. Raspberry
Pi 2 includes a quad-center Cortex-A7 CPU running at 900 MHz and 1 GB RAM. It is
portrayed as 4–6 occasions additional predominant than its predecessor. The GPU is
undefined from the first.
In parallelized benchmarks, the Raspberry Pi 2 would be as much as two or multiple times
faster than a Raspberry Pi 1 model B+. While working at 700 MHz obviously, the since
quite a while ago settled Raspberry Pi gave an authentic introduction when all is said in
done same to zero.041 GFLOPS. On the CPU degree, the introduction resembles a 300
MHz Pentium II of 1997–ninety-nine.
The GPU offers 1 Gpixel/s or 1.5 Gtexel/s of representations making prepared or 24
GFLOPS of extraordinarily valuable enlisting execution. The graphical favorable position
of the Raspberry Pi is ordinarily proportionate to the show of the Xbox of 2001. The
Raspberry Pi consists 40 general purpose input output pins and they are shown in below
diagram.

15
3.1.7. PIN DESCRIPTION OF PI

Fig 3 Pin Description of Pi 3B+

16
3.2 SDHC (Secure Digital High Capacity Card)

Agreeable comprehensively adaptable things, for representation, cell phones, advanced


cameras, GPS course contraptions, handheld consoles, and pill PCs. The casual Digital ordinary
was once granted in August 1999 as a transformative improvement over Multi Media playing
cards. casual common amassed affiliation. progresses had realized path over many item
groupings and in undeniably more than eight,000 models. The agreeable Digital game plan
suits 4 reachable individual structure. 4 principal customary limit comprehensive merges
enter/yield limits with know-how storing. The three structure reasons are the primary
estimation, the littler than conventional size, and the scaled down scale estimation. Electrically
uninvolved connectors license suit capacity machine worked bigger.

3.2.1 SD card working

The designed comfortable (or loosened up common) made expand Multimedia Card (MMC)
normal, which continued progressing, in any case in an elective way. plan various outstanding
manners:

Spaces inside parts block embeddings even as a goes in for all intents and purposes the entire
technique yet comes to at whatever point changed over.Most SD playing cards are 2.1 mm
(zero.083 inches) thick, appeared differently in relation to 1.4 mm (zero.). definite portrays known
as slender Four in any case unmistakable, as continued symbolize broadly humbler
structure.Underneath outside defensive them customers.One of a kind envisioned breaking points
and move rates outperforming these of MMC, and these have both created after some time.Full-
sized SD cards don't coordinate inside the openings, exceptional effect capacity utilize course of
action number gadget planned inverse.

3.2.2 SDHC card working

The quiet Digital high potential (SDHC) structure said portrayed variety choice,
reinforces playing limits up to approved guarantee comparability the gigantic closeness issue
among exact information variety Zero, most ideal way playing sent report.

17
Fig 4 SDHC of PI

Structure 2.Zero in addition exhibits an extreme pace transport mode for both SDSC and
SDHC playing a game of cards, which copies the primary typical pace make have objects
understood increasingly prepared playing a card game. Regardless, extra settled host devices
don't see SDHC or SDXC memory cards, though various articles can do in that capacity by
method for a firmware update. Extra arranged home windows working structures released
sooner than home windows 7 require fixes or organization packs reinforce access to SDHC
playing a card game as in Fig 4.

Fig 5 Micro SD and its pin description

18
3.2.3 SD card Compatibility

Host things that fit in with additional present adjustments of the decision supply
backward comparability and prestigious additional ace SD playing a game of cards. For
instance, SDXC have devices prestigious each earlier workforce of SD memory playing a
game of cards, and SDHC have things moreover eminent common SD cards in fig 5. Extra
prepared host protests ordinarily don't support extra up to the minute card plans, and in any
occasion, when they are going to reinforce the vehicle interface used by method for the
cardboard, there are two or three intentions that rise.

3.3 2x1 CHANNEL RELAY

A relay is an electrically operated switch. It consists of a set of input terminals for a


single or multiple control signals, and a set of operating contact terminals. The switch may have
any number of contacts in multiple contact forms, such as make contacts, break contacts, or
combinations thereof. Relays are used where it is necessary to control a circuit by an independent
low-power signal, or where several circuits must be controlled by one signal. Relays were first
used in long-distance telegraph circuits as signal repeaters: they refresh the signal coming in from
one circuit by transmitting it on another circuit.

Relays were used extensively in telephone exchanges and early computers to perform
logical operations Relays are electric switches that use electromagnetism to convert small
electrical stimuli into larger currents. These conversions occur when electrical inputs activate
electromagnets to either form or break existing circuits. Relay is an electro- mechanical device
used to turn on/off a device by sending a small signal at the output.

19
Figure 6 shows a two-channel relay with two relays on a single PCB. The input to relays IN1
and IN2 are connected to Raspberry Pi GPIO pins, to turn on the corresponding relay. The output
pins contain a common terminal (COM1 and COM2), normally open (NO) and normally closed
(NC)

Fig 6 Hardware of 2x1Relay channel

20
3.4 INITIAL STATE (IOT PLATFORM) :

Initial State is a data streaming and visualization platform. We make it easy for anyone,
from novice to enterprise, to send data from web-connected devices, sensors, and
applications to a cloud where that data can be accessed anytime and instantly turned into
something awesome - interactive real-time dashboards, charts, statistics, notifications, etc.
We are focused on creating a fantastic experience from the instant data is created until the
moment data is consumed.

21
3.5 2N2222A Transistor

Fig 7 Pin description of 2N222 transistor

2N2222A is a NPN semiconductor in Fig 7 subsequently the authority and producer will be left open
(Reverse one-sided) when the base pin is held at ground and will be shut (Forward one-sided) when a sign
is given to base pin. 2N2222A has an addition estimation of 110 to 800, this worth decides the
enhancement limit of the semiconductor. The greatest measure of current that could course through the
Collector pin is 800mA, thus we can't interface stacks that burn-through more than 800mA utilizing this
semiconductor. To inclination a semiconductor we need to supply current to base pin, this current (IB)
should be restricted to 5mA.

At the point when this semiconductor is completely one-sided then it can permit a limit of 800mA to
stream across the authority and producer. This stage is called Saturation Region and the ordinary voltage
permitted across the Collector-Emitter (V-CE) or Base-Emitter (VBE) could be 200 and 900 mV
individually. At the point when base current is taken out the semiconductor turns out to be completely off,
this stage is canceled as the Cut Region and the Base Emitter voltage could be around 660 mV.

22
3.6 12V DC fan interfacing Raspberry pi

Fig 8 Hardware setup of Pi interfacing DC fan

Fans are valuable gadgets that make wind current to chill something off, give a new stockpile of air, or
help the flow of pressurized canned products. Most homegrown fans have diverse speed settings,
however these are frequently as mechanical catches, which might be hard to control utilizing a Raspberry
Pi. Indeed, a circuit that has a servo and an arm could be utilized to squeeze catches, however that is a
fairly mind boggling arrangement. All things being equal, it is simpler to control how much force the fan
is permitted to devour and using PWM signals permits the framework to have unlimited oversight over
the fan speed.

HOW IT WORKS:-
Working of Circuit:-

PWM signals are conveyed of GPIO14 utilizing the Python content (depicted underneath) which
brings about the semiconductor Q1 turning on and off. At the point when the semiconductor Q1 is on, at
that point the compelling obstruction of Q1 is 0ω and hence the voltage at the door of Q2 is additionally
0V. Sie the Gate-Source voltage on Q2 is presently 0V, at that point Q2 kills and keeps the 12V fan from
having the option to draw any current. At the point when the yield of GPIO14 kills, at that point
semiconductor Q1 additionally kills and results in the door voltage of Q2 being 12V. Since the Gate-

23
Source voltage of Q2 is currently 12V, the semiconductor Q2 completely directs and empowers the fan
to turn on.
In the event that the PWM signal from GPIO14 had an exceptionally low recurrence - turning on and off
once at regular intervals - at that point the fan would accelerate completely, at that point quit moving, at
that point accelerate, at that point quit moving once more. In any case, the recurrence of the PWM signal
is in the several hertz and this outcomes in the PWM sign to the fan being smoothed and found the
middle value of. In this manner, the speed of the fan will be generally relative to the information PWM
obligation cycle. As the obligation cycle builds, at that point the speed of the fan additionally increments.

Fig 9 Fan internal circuit

Working of Software:-

The product for PWM DC control is basic and utilizations the library RPi.GPIO. The initial two lines of
the code import all the required libraries which incorporate the time library (for making delays) and the
GPIO library. The GPIO library is designed to utilize the BCM numbering plan and GPIO 14 is arranged
as a yield.
24
The following two lines arranged in Fig 9 GPIO 14 as a PWM yield, make a PWM object called
pwmOut, and start the PWM signal. The .PWM() work takes two contentions; the main contention
characterizes which pin is being utilized as the PWM yield, and the subsequent contention decides the
recurrence of the PWM signal. In this program, we set the PWM sign to a recurrence of 200Hz.

The primary program circle sets the estimation of the obligation cycle variable and afterward changes the
obligation pattern of the PWM signal utilizing the .ChangeDutyCycle() work.

The motivation behind why the worth is obligation cycle variable is deducted from 100 is because of the
utilization of the 2N3904. The 2N3904 is in an altering setup, which implies when we need to turn the
fan on, we need to kill the 2N3904.

Fig 10 12V DC fan

25
Fig 8 tells about DC fan interfacing Pi

Specifications of fig 10:

• 12V DC power supply

• 0.07A current

26
3.7 DHT11 sensor

-Fig 11 DHT11 interfacing PI

The modules have three pins and are easy to connect directly to the Pi’s GPIO header.

 Humidity : 20-80% (5% accuracy)


 Temperature : 0-50°C (±2°C accuracy)

DHT11 sensor quantifies and gives dampness and temperature esteems sequentially over a solitary wire.
It can gauge relative mugginess in rate (20 to 90% RH) and temperature in degree Celsius in the scope of
0 to 50°C.
It has 4 pins; one of which is utilized for information correspondence in sequential structure.
Beats of various TON and TOFF are decoded as rationale 1 or rationale 0 or start heartbeat or end of an
edge.

By interfacing the DHT11 Sensor with Raspberry Pi in Fig 11, you can fabricate your own IoT weather
Station. All you require to execute such IoT Weather is a Raspberry Pi, a DHT11 Humidity and
Temperature Sensor and a Computer with Internet Connectivity.

27
DHT11 Temperature and Humidity Sensor is one of the famous sensor modules utilized by specialists for
actualizing in a ton of IoT Projects. This sensor alongside Raspberry Pi can likewise be utilized in:

• Central air Systems


• Indoor regulators
• Home and Office Climate Control
• Climate Station

28
3.8 Raspberry Pi Camera

RPi Cam Web Interface is a web interface for the Raspberry Pi Camera module. It tends to be utilized
for a wide assortment of uses including reconnaissance, dvr recording and time pass photography. It
is exceptionally configurable and can be reached out with the utilization of large scale contents. It
very well may be opened on any program (cell phones included) and contains the accompanying
highlights:

• View, stop and restart a live-see with low inertness and high framerate. Full sensor territory
accessible.

• Control camera settings like brilliance, contrast, ... live

• Record full-hd recordings and spare them on the sd-card stuffed into mp4 holder while the live-
see proceeds

• Do coordinated or constant video recording with parting into fixed length fragments

• Take single or numerous (timelapse) full-res pictures and spare them on the sd-card (live-review
hangs on for a short second)

• See, download and erase the spared recordings and pictures, compress download for numerous
documents

• Trigger catches by movement discovery utilizing interior or outer identification measures.

• Trigger catches by many booking prospects

• Roundabout cradle to catch activities paving the way to movement discovery

• Control Pan-Tilt or Pi-Light

29
• Closure/Reboot your Pi from the web interface

• Show comments (eg timestamp) on live-review and taken pictures/recordings

• Supports choice from


Fig 12 Pi Cam interfacing Pi

Needs of Pi Cam in fig 12:-

For this model, I utilized the Raspberry Pi 3 as it had implicit WiFi yet you can utilize some other form
of the Raspberry Pi as long as you have an approach to associate with the web utilizing either WiFi or
Ethernet.

Raspberry Pi 3 Model B+

MicroSD Card with Raspbian OS

Raspberry Pi Camera

Power Supply

30
Prior to fueling up the Raspberry Pi, you should complete two things. To begin with, associate the
Raspberry Pi camera into the CSi space on the Raspberry Pi. You can find in the above figure the right
direction of the lace link embedded into the CSi opening.

3.9 BreadBoard

Fig 13 Pi on Breadboard

The associations are not lasting, so it is anything but difficult to eliminate a part on the off chance
that you commit an error, or simply begin once again and do another venture. This makes
breadboards extraordinary for tenderfoots who are new to hardware. You can utilize breadboards
to make a wide range of fun gadgets ventures, from various sorts of robots or an electronic drum
set, to an electronic downpour identifier to assist save with watering in a nursery, just to name a
few.Breadboards are planned so you can drive these leads into the holes.They will be held set up
cozily enough that they won't drop out (regardless of whether you flip around the breadboard),
yet daintily enough that you can undoubtedly pull on them to eliminate them.

31
3.10 Resistor

Fig 14 Normal 10k resistor

1/6th Watt, +/ - 5% tolerance PTH resistors. Generally utilized in PCBs and perf sheets, these 10K
resistors make brilliant draw ups, pull-downs, and current limiters. On account of the dainty leads we
don't suggest them for breadboards.

A resistor in fig 14 is an aloof two-terminal electrical part that executes electrical obstruction as a circuit
component. In electronic circuits, resistors are utilized to diminish current stream, change signal levels,
to isolate voltages, inclination dynamic components, and end transmission lines, among different
employments.

32
3.11 Telepot

Telepot is a python structure that is utilized in building applications for Telegram Bot API [9]. The Bot
API from message permits clients to make programs for connecting with bots utilizing the wire
messages or orders sent by the clients. Telepot is introduced in Raspberry Pi to visit with the Message
bot utilizing the entrance badge of the bot, the entrance token is the novel ID given during the making of
the bot in message.

Code required:

import teleport

Bot=teleport.Bot(“Copy token from browser”)

Bot.getMe()

33
4.0 EXPERIMENTAL INVESTIGATIONS

Further we are building up this undertaking to incorporate with various API's utilizing Jasper. We
use voice acknowledgment not exclusively to machines in home or office yet in addition make the
framework to cooperate with the client.

The framework can be made to tell the date, time, mail notices, understanding news, wiki search of
specific expression, climate figure, adding occasions to a schedule and so on voice acknowledgment
has parcel of degree to incorporate into new degrees of innovation. This voice framework helps the
genuinely impaired people to control everything without moving their legs and hands. This
framework can be changed over into computerized right hand to collaborate like virtual individual.
The clients can arrange this framework effectively in less time.

34
4.1 PROJECT CIRCUIT DIAGRAM

Fig 15 Circuit Diagram

35
4.2 PROJECT BLOCK DIAGRAM

Fig 16 Block Diagram

36
5. PROGRAM CODE

// Authorized users, replace with your real IDs


// Code for light,temperature and fan interaction with bot.

var authorized_users = [
502909633,
];

// Include required libraries


var sensorLib = require('node-dht-sensor');
var Bot = require('node-telegram-bot');

// Initialize relay board (using onoff library)


var Gpio = require('onoff').Gpio,
relay1 = new Gpio(2, 'out'),
relay2 = new Gpio(3, 'out');
fan = new Gpio(23,'out');

// Turn both the relays off


relay1.writeSync(1);
relay2.writeSync(1);

// Initialize DHT11 sensor


sensorLib.initialize(11, 4);

// Initialize and start Telegram BOT (insert your real token)


var bot = new Bot({
token: '1496034547:AAHOv41lEbWbxjLV35uzXdeQSW3IbgHzfUU'
});

// Attach event on every received message


bot.on('message', function (message) {
parseMessage(message);
37
});

// Start the bot


bot.start();
console.log("BOT ready!");

// Function that handles a new message


function parseMessage(message) {

if(!isAuthorized(message.from.id)) return;

switch(true) {

case message.text == "/gettemp":


bot.sendMessage({
chat_id: message.chat.id,
text: 'Actual temperature: ' + sensorLib.read().temperature.toFixed(0) + '°C',
});
break;

case message.text == "/gethum":


bot.sendMessage({
chat_id: message.chat.id,
text: 'Actual humidity: ' + sensorLib.read().humidity.toFixed(0) + '%',
});
break;

case message.text == "/getouts":


bot.sendMessage({
chat_id: message.chat.id,
text: 'Actual outputs status:\nOutput 1 is ' + relay1.readSync() + '\nOutput 2 is ' +
relay2.readSync(0),
});
break;

38
case /^\/setout1/.test(message.text):
var command = message.text.replace("/setout1 ", "");
if(command.toLowerCase() == "off") {
relay1.writeSync(1);
bot.sendMessage({
chat_id: message.chat.id,
text: 'Output 1 turned OFF',
});
} else if(command.toLowerCase() == "on") {
relay1.writeSync(0);
bot.sendMessage({
chat_id: message.chat.id,
text: 'Output 1 turned ON',
});
} else
bot.sendMessage({
chat_id: message.chat.id,
text: 'Unknown command: ' + command,
});
break;

case /^\/setout2/.test(message.text):
var command = message.text.replace("/setout2 ", "");
if(command.toLowerCase() == "on") {
relay2.writeSync(0);
bot.sendMessage({
chat_id: message.chat.id,
text: 'Output 2 turned ON',
});
} else if(command.toLowerCase() == "off") {
relay2.writeSync(1);
bot.sendMessage({
chat_id: message.chat.id,

39
text: 'Output 2 turned OFF',
});
} else
bot.sendMessage({
chat_id: message.chat.id,
text: 'Unknown command: ' + command,
});
break;
}
}
Thre = 20
if(('Actual temperature: ' + sensorLib.read().temperature.toFixed(0) + '°C')>Thre)
fan.writeSync(0);

// Function that checks if the user is authorized (its id is in the array)


function isAuthorized(userid) {

for(i = 0; i < authorized_users.length; i++)


if(authorized_users[i ] == userid) return true;

return false;
}

//Code for photo detection & commands with bot

import telepot
import picamera
import RPi.GPIO as GPIO
import glob
from telepot.loop import MessageLoop
import os
import datetime

40
import time

def handle(msg):
global sendPhoto
global chat_id

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

print('Message received from ' + str(chat_id))

if command == '/photo':
sendPhoto = True
elif command == '/time':
sendMessage = True
elif command == '/video':
sendVideo = True
elif command == '/audio':
sendAudio = True

elif command == '/start':


bot.sendMessage(chat_id, 'Welcome to Boo Bot')

else:
bot.sendMessage(chat_id, 'Invalid command.')

def capture():
print('Capturing photo...')
camera = picamera.PiCamera()
camera.capture('./photo.jpg')
camera.close()
print('Sending photo to ' + str(chat_id))
bot.sendPhoto(chat_id, photo = open('./photo.jpg', 'rb'))

41
bot.sendMessage(chat_id, 'now is '+str(datetime.datetime.now()))
bot.sendAudio(chat_id, audio=open('/home/pi/test.mp3'))
video = max(glob.iglob('/home/pi/motion/detected/vids/*.mp4'), key=os.path.getctime)
bot.sendVideo(chat_id, video=open(video, 'rb'), caption='last video')

bot = telepot.Bot('1496034547:AAHOv41lEbWbxjLV35uzXdeQSW3IbgHzfUU')
bot.message_loop(handle)

print('Bot ready!')

sendPhoto = False

try:
while True:
if sendPhoto == True:
sendPhoto = False
capture()

except KeyboardInterrupt:
GPIO.cleanup()

//code for video detection with bot

from picamera import PiCamera # Importing the library for camera module
from time import sleep # Importing sleep from time library to add delay in program
from subprocess import call
import time

command = ['text']
bot = telepot.Bot('1496034547:AAHOv41lEbWbxjLV35uzXdeQSW3IbgHzfUU')

if command == '/video':

42
sendVideo = True
# Initiate the camera module with pre-defined settings.

camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 15

camera.start_preview() # You will see a preview window while recording


camera.start_recording('/home/pi/Desktop/video.h264') # Video will be saved at desktop
sleep(5)
camera.stop_recording()
camera.stop_preview()

def convert(file_h264, file_mp4):


# Record a 15 seconds video.
filename = "./video_" + (time.strftime("%y%b%d_%H%M%S"))
camera.start_recording(file_h264)
sleep(5)
camera.stop_recording()
print("Rasp_Pi => Video Recorded! \r\n")
# Convert the h264 format to the mp4 format.
command = "MP4Box -add " + file_h264 + " " + file_mp4
call([command], shell=True)
print("\r\nRasp_Pi => Video Converted! \r\n")
bot.sendVideo(502909633, video = open(filename + '.mp4', 'rb'))

sendVideo = False

try:
while True:
if sendVideo == True:
sendVideo = False

43
capture()

except KeyboardInterrupt:
GPIO.cleanup()

//Display in pi

import sys
import time
import random
import datetime
import telepot
import RPi.GPIO as GPIO

def on(pin):
GPIO.output(pin,GPIO.HIGH)
return
def off(pin):
GPIO.output(pin,GPIO.LOW)
return
GPIO.setmode(GPIO.BOARD)
GPIO.setup(16, GPIO.OUT)

def handle(msg):
chat_id = msg['chat']['id']
command = msg['text']

print 'Got command: %s' % command

if command == 'on':
bot.sendMessage(chat_id, on(16))
elif command =='off':
bot.sendMessage(chat_id, off(16))

44
bot = telepot.Bot('1496034547:AAHOv41lEbWbxjLV35uzXdeQSW3IbgHzfUU')
bot.message_loop(handle)
print 'I am listening...'

while 1:
time.sleep(100000)

45
6. EXPERIMENTAL RESULTS

6.1 Live Connections and Hardware Setup

Fig 17 Hardware

46
6.2 Pi Software running

Fig 18 Software

47
6.3 Telegram Bot User Interface

––––––

Fig 19 User Interface

48
6.4 Telegram snapshot capture and video streaming recorded from pi:-

Fig 20 Live Streaming

49
7. Discussion of Results:-

7.1. Setting up Bot in Telegram

Stage 1: Search and select BotFather in Telegram

Stage 2: Give the beginning order to BotFather by composing/start .

Stage 3: You‟ll see a rundown of orders that help you make, alter, and deal with your bots.
Since it‟s your first time, you‟ll need/newbot .

Stage 4: After providing the/newbot order, you will pick a name and username for your bot. The
name is what your clients will consider the to be as in their contacts list, and the username is the
manner by which they‟ll discover it.

Stage 5: With that done, you‟ll be given your bot‟s API key. The API key is the means by
which Telegram knows the code you compose is related with this specific bot. Each bot has its
own API key.

7.2. Blinking of LED lights

• In our program, we need to use GPIO.output(ledPin, GPIO.HIGH) for turning ON the LED
and GPIO.output(ledPin, GPIO.LOW).
• We developed a home automation system that states about automatic led on/off system
according to the command we have given in telegram.
• Here we have performed the automatic lighting on 2 LED’s.

7.3. Temperature and Humidity

• DHT22 — This temperature and moistness sensor has temperature exactness of +/ - 0.5 C
and a stickiness range from 0 to 100%. It is easy to wire up to the Raspberry Pi and doesn't
need any draw up resistors.

50
• DSB18B20 — This temperature sensor has a computerized yield, which functions admirably
with the Raspberry Pi.
• In the process of home automation we also needed to control the fan in our home using the
temperature outside the space.So,I wrote a code which says about the temperature and
humidity inside the room and according to the temperature if it exceeds >45C the fan
automatically gets on else it switches off.
• We aslo calculated humidity since it is a dependent component of temperature.

7.4. DC Fan

• As said if the temperature in the room exceeds 45C the fan component connected to pi by
means of resistor and transistor automatically gets on.
• It is based on principle,temperature directly proportional to humidity and pressure in air.

7.5. Pi Camera

• For capturing pictures to recording videos pi camera is useful in many ways.In my project I
performed its functionality regarding its spy activities in home automation
• .It successfully captures the pictures and sends to the telegram api.
• It also sends the videos to the telegram.This is the main functionality which is pi camera is
useful.
• It is also useful for object detection purposes.

51
8. CONCLUSION

The home framework proposed through this paper was tentatively demonstrated to work with
the help of the different techniques actualized like voice, Telegram and application. Control of
apparatuses accomplished through these techniques with voice in home and distantly through
applications anyplace on the world. This will assist the client with examining the conditions in
the home whenever anyplace. The framework is like an attachment and play which can be
mounted anyplace in the house with not so much expense but rather more security. This solitary
is conceivable by utilizing open equipment and free and open source programming.

9. FUTURE SCOPE

Further we are building up this undertaking to incorporate with various API's utilizing
Jasper.We use voice acknowledgment not exclusively to machines in home or office yet in
addition make the framework to cooperate with the client[5]. The framework can be made to tell
the date, time, mail notices, understanding news, wiki search of specific expression, climate
figure, adding occasions to a schedule and so on voice acknowledgment has parcel of degree to
incorporate into new degrees of innovation[5]. This voice framework helps the genuinely
impaired people to control everything without moving their legs and hands[7]. This framework
can be changed over into computerized right hand to collaborate like virtual individual. The
clients can arrange this framework effectively in less time [8].

52
10. REFERENCES

1. Alkar. Z and Buhur.U, “ An Internet based wireless home automation system for
multifunctional devices”, IEEE Transactions on Consumer Electronics, Vol. 51, No. 4,
pp. 1169-1174, Nov. 2005.

2. Xiaohua Zeng, Abraham O. Fapojuwo, and Robert J (2007), „Design and Performance Evaluation of
Voice Activated Wireless Home Devices‟, IEEE Transactions on Consumer Electronics, Vol. 52,
No. 31, pp. 983 – 989.

3. R. G. Anvekar and R. M. Banakar, “IoT application development: Home security system”, IEEE
Technological Innovations in ICT for Agriculture and Rural Development (TIAR 2017), Apr. 7-8,
2017, Chennai, India, pp. 68-72.

4. N. S. Yamanoor and S. Yamanoor, "High quality, low cost education with the
Raspberry Pi," 2017 IEEE Global Humanitarian Technology Conference (GHTC), San
Jose, CA, 2017, pp. 1-5.

5. Makled Esraa.A , Halawa Hassan.H, Ramez M. Daoud, H. Amer Hassanein, "Wi-Fi-based


Hierarchical Wireless Networked Control Systems", Electronics and Communications Engineering
Department American University in Cairo (AUC) Cairo Egypt IEEE, 2015.

6. Zhao,Yanbo, and Zhaohui Ye, “A low cost GSM/GPRS based wireless home security
system”, IEEE Transactions on Consumer Electronics 54, no. 2 (2008).

7. Rakesh, V. S., P. R. Sreesh, and Sudhish N. George, “An improved real-time


surveillance system for home security system using BeagleBoard SBC, Zigbee and
FTP webserver,” IEEE Int.Con, 2012, pp. 1240-1244.

8. Ansari, Aamir Nizam, Mohamed Sedky, Neelam Sharma, and Anurag Tyagi, “An
Internet of things approach for motion detection using Raspberry Pi,” IEEE Int.Con.
Intelligent Computing and Internet of Things, 2014, pp. 131-134.

9. Hattie Clougherty, Alec Brown, Margaret Stonerock, “Home Automation and


Personalization through Individual Location Determination”, IEEE 978-1-5386-1848-
6/17/$31.00 2017.

53
10. Ishan Krishna, K. Lavanya,”Intelligent Home Automation System using BitVoicer”,
11th International Conference on Intelligent Systems and Control, 2017.

11. ShibliNisar, Muhammad Asadullah, “Home Automation Using Spoken Pashto Digits
Recognition”, IEEE 978-1-5090-3310-2/17/$3\.00 2017.

12. Juan Carlos de Oliveira, Danilo Henrique Santos,” Chatting with Arduino Platform
through Telegram Bot”, IEEE International Symposium on Consumer Electronics,
2016.

13. Vedan rattan vasta , Gopal singh, “Raspberry Pi based Implementation of Internet of
Things using Mobile Messaging Application - „Telegram‟”, International Journal of
Computer Applications (0975 – 8887), Volume 145 – No.14, July 2016.

14. Ankush B.powar, shasikanth gumhre, “A SURVEY ON IoT APPLICATIONS,


SECURITY CHALLENGES AND COUNTER MEASURES”, international
conference on computing, dec 19-21, 2016.

54
55

You might also like