NameNetIdEnrolled Course
Jai Anchaliajaia2ECE110
Sara Alabbadisaraa6ECE120
Aleksai Herreraaleksai2ECE120
Pranshu Teckchandanipat4ECE110
Satyansh Yelurisyeluri2ECE110




  1. Introduction

Statement of Purpose:

Our goal for this project was to build an IoT Home System through which users are able to control various parts of their houses. We wanted to create a device that could add convenience to daily tasks. Our basic ideas were to provide light control, door lock control, and create a very basic personal assistant. 

2. Features:

Through the use of a raspberry Pi, we hosted a web server that gives and user connected to the network the power to control the color of an RGB strip. THe IoT Home System will also be able to unlock and lock doors and act as an assistant that scrapes a weather website to provide the daily weather information as well as the events scheduled for that day through google calendar. 

3. Background Research

With an increasing number of smart devices being used in homes, a system that is able to connect to and control all these devices becomes extremely convenient. Our inspiration for this project are pre-existing systems such as Google Home, the Home Pod, and Alexa. Unlike them however, we aim to make our system strictly dedicated to operating smart devices. Our initial research pointed us to use a raspberry pi. A Raspberry Pi provides very many useful features such as its Input and Output pins which allows us to power and have complete control over a RGB strip and its color. Since the Raspberry pi is essentially a small computer, it can run a web server that is accessible to other devices on the network. With python code and the available API’s the raspberry pi is able to send and receive commands from the web server which controls the devices through the raspberry’s GPIO pins. 

4. Design Details

Hardware

Like most other Iot’s, our project includes a single-board computer (Raspberry Pi) that is connected to an interface/ web server through wifi. The user can control the home system through this. The Raspberry Pi is connected to the LED strip. The user can then control the appliance through the connections on the Raspberry Pi.


As shown in the circuit diagram below, the connection between the LED strip and the raspberry pi is through the transistors. There is one transistor for each of the R-G-B chips. For each transistor, the gate is connected to the GPIO pins on the pi. The drain is connected to the respective prong of the RGB strip and the source is connected to the negative terminal. The Raspberry Pi is powered through a wall adapter and the RGB strip is powered separately with a 12V wall adapter. The Pi does not supply enough power for the RGB strip so it needs to be powered separately. 



Software

Through the use of a python API meant for Raspberry PI’s, we were able to easily control the input and output on the transistors. For each color, a pin needed to be supplied a certain amount of power. Depending on what the user clicks on the website, a message is retrieved through the javascript code (ii.appendix) and is interpreted by the python code (i.appendix) to change the output of power to the RGB strip. 

5. Results:

On connecting the pi to the power source and debugging our circuit as well as testing our code, we find that the LED strip lights up. Moreover, the web server can be accessed through a mobile phone which allows to switch between the different colours. The web server also contains a sidebar to enable us to vary the intensity according to our preferences. Our system gives perfect functionality and desirable results.

6. Problems and Challenges:

Our biggest problem was with the javascript code. No one in the group had prior experience with javascript and how to retrieve elements from an html file. Because of this, the “OFF” functionality and the custom “color slider” functions do not work and cause errors when called. 

7. Future Plans

Our future plans include enhancing the web server to have more functionality and be more aesthetic. We would like to begin by integrating a simple door lock mechanism to lock and unlock a door using the web server. Another plan is to integrate a personal assistant that can scrape the web to provide data to users depending on what they ask for. As for now, we have a simple one that gathers data about the weather and reads a google calendar. Further along the line, we would like to add voice recognition so that the user can do the same tasks with a voice command instead of opening up their phone. There are countless devices that we could design and connect to the server to control. 

8. References

Microcontrollers Lab. 2021. IOT based home automation system over cloud using Arduino. [online] Available at: <https://microcontrollerslab.com/iot-based-home-automation-system-wifi/> [Accessed 19 February 2021].

Appendix

Python Code:

i.

import os

import sys

import os.path

import tornado.httpserver

import tornado.websocket

import tornado.ioloop

import tornado.web

import termios

import tty

import pigpio

import time

from thread import start_new_thread

RED_PIN   = 13

GREEN_PIN = 19

BLUE_PIN  = 37

red=pigpio.pi()

green=pigpio.pi()

blue=pigpio.pi()

#code to set individual pin brightness- change brightness value

#Tornado Folder Paths

settings = dict(

        template_path = os.path.join(os.path.dirname(__file__), "templates"),

        static_path = os.path.join(os.path.dirname(__file__), "static")

        )

#Tonado server port

PORT = 80

class MainHandler(tornado.web.RequestHandler):

  def get(self):

     print("[HTTP](MainHandler) User Connected.")

     self.render("index.html")      

class WSHandler(tornado.websocket.WebSocketHandler):

  def open(self):

    print('[WS] Connection was opened.')

  

  def on_message(self, message):

    print('[WS] Incoming message:', message)

    if message == "ON":

      red.set_PWM_dutycycle(RED_PIN, 100)      

      green.set_PWM_dutycycle(GREEN_PIN, 100)

      blue.set_PWM_dutycycle(BLUE_PIN, 100)

    if message == "OFF":

      red.set_PWM_dutycycle(RED_PIN, 100)      

      green.set_PWM_dutycycle(GREEN_PIN, 100)

      blue.set_PWM_dutycycle(BLUE_PIN, 100)

    if message == "Red":

      red.set_PWM_dutycycle(RED_PIN, 255)      

      green.set_PWM_dutycycle(GREEN_PIN, 0)

      blue.set_PWM_dutycycle(BLUE_PIN, 0)

    if message == "Green":

      red.set_PWM_dutycycle(RED_PIN, 0)      

      green.set_PWM_dutycycle(GREEN_PIN, 255)

      blue.set_PWM_dutycycle(BLUE_PIN, 0)

    if message == "Blue":

      red.set_PWM_dutycycle(RED_PIN, 0)      

      green.set_PWM_dutycycle(GREEN_PIN, 0)

      blue.set_PWM_dutycycle(BLUE_PIN, 255)

    if message == "White":

      red.set_PWM_dutycycle(RED_PIN, 255)      

      green.set_PWM_dutycycle(GREEN_PIN, 255)

      blue.set_PWM_dutycycle(BLUE_PIN, 255)

    if message == "Yellow":

      red.set_PWM_dutycycle(RED_PIN, 255)      

      green.set_PWM_dutycycle(GREEN_PIN, 255)

      blue.set_PWM_dutycycle(BLUE_PIN, 0)

    if message == "Purple":

      red.set_PWM_dutycycle(RED_PIN, 100)      

      green.set_PWM_dutycycle(GREEN_PIN, 0)

      blue.set_PWM_dutycycle(BLUE_PIN, 100)

    if message.startswith("Send"):

      values= message.split()

      red.set_PWM_dutycycle(RED_PIN, int(values[1]))      

      green.set_PWM_dutycycle(GREEN_PIN, int(values[2]))

      blue.set_PWM_dutycycle(BLUE_PIN, int(values[3]))

  def on_close(self):

    print('[WS] Connection was closed.')

application = tornado.web.Application([

  (r'/', MainHandler),

  (r'/ws', WSHandler),

  ], **settings)

if __name__ == "__main__":

    try:

        http_server = tornado.httpserver.HTTPServer(application)

        http_server.listen(PORT)

        main_loop = tornado.ioloop.IOLoop.instance()

        print("Tornado Server started")

        main_loop.start()

    except:

        print("Exception triggered - Tornado Server stopped.")

Java Script code

ii.

 $(document).ready(function(){

        var WEBSOCKET_ROUTE = "/ws";

        if(window.location.protocol == "http:"){

            //localhost

            var ws = new WebSocket("ws://" + window.location.host + WEBSOCKET_ROUTE);

            }

        else if(window.location.protocol == "https:"){

            //Dataplicity

            var ws = new WebSocket("wss://" + window.location.host + WEBSOCKET_ROUTE);

            }

        ws.onopen = function(evt) {

            $("#ws-status").html("Connected");

            };

        ws.onmessage = function(evt) {

            };

        ws.onclose = function(evt) {

            $("#ws-status").html("Disconnected");

            };

        $("#ON").click(function(){

            ws.send("ON");

            });

        $("#OFF").click(function(){

            ws.send("OFF");

            });

        $("#Green").click(function(){

            ws.send("Green");

            });

        $("#Red").click(function(){

            ws.send("Red");

            });

            $("#Blue").click(function(){

            ws.send("Blue");

            });

        $("#White").click(function(){

            ws.send("White");

           });

        $("#Yellow").click(function(){

            ws.send("Yellow");

            });            

        $("#Purple").click(function(){

             ws.send("Purple");

            });

        $("#Send").click(function(){

            var Green= $("#Green_slider").value;

            var Red= $("#Red_slider").value;

            var Blue= $("#Blue_slider").value;

            Green = String(Green);

            Blue = String(Blue);

            Red = String(Red);

             ws.send("Send " + Red + " " + Green + " " + Blue);

            });

      });\

HTML code

iii.

<html>

<head>

<title> Art1 - Leds </title>

</head>

<body>

<div> <!-- LEDs -->

<h2>Control</h2>

ON/OFF

<p>

<input type="button" id="ON"  value="ON">

<input type="button" id="OFF" value="OFF">

</p>

RED:

<p>

<input type="button" id="ON"  value="Red">

</p>

GREEN:

<p>

<input type="button" id="ON"  value="Green">

</p>

BLUE:

<p>

<input type="button" id="ON"  value="Blue">

</p>

WHITE:

<p>

<input type="button" id="ON"  value="White">

</p>

YELLOW: 

<p>

<input type="button" id="ON"  value="Yellow">

</p>

Purple: 

<p>

<input type="button" id="ON"  value="Purple">

</p>

Green:

<p>

<div class="slidecontainer">

  <input type="range" min="1" max="255" value="50" class="slider" id="Green_slider">

</div>

</p>

Red:

<p>

<div class="slidecontainer">

  <input type="range" min="1" max="255" value="50" class="slider" id="Red_slider">

</div>

</p>

Blue:

<p>

<div class="slidecontainer">

  <input type="range" min="1" max="255" value="50" class="slider" id="Blue_slider">

</div>

</p>

SEND:

<p>

  <input type="button" id="Send"  value="Send">

  </p>

</div>

<hr>

Websocket status:

<br>

<div id="ws-status"> Waiting... </div>

<!-- Scripts -->

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>

<script src="{{ static_url("ws-client.js") }}"></script>

</body>

</html>



Comments:

Hey guys! There's lots of documentation on projects similar this so I'm not concerned about your ability to complete the project but if you aren't familiar with a lot of Pi and IoT code then I would suggest starting to collect resources and learning ASAP. Debugging WiFi and Bluetooth will take a lot of time if you don't know what you are doing. It seems that you have three main components that you would like to create. A light, garage controller, and lock. These parts could be entire projects within themselves. It is fine to go for this wide of a scope but make sure that you try to finish each part before moving onto the other. This will ensure that you have a certain threshold of functionality to present on at the end. 

I'll approve this proposal.

Posted by dbycul2 at Feb 23, 2021 22:59