Post on 22-Jan-2018
Final Presentation
Smart-Home Smart-Switch using Arduino
Students: Edan Shunem, Itzik Cohen
Supervisor: Mony Orbach
Semester: Winter, 2016
Date: 09/03/2016
Department of Electrical Engineering
Presentation Outline
• Motivation• Project Goal• Block Diagram: Hardware• Physical Diagram• Block Diagram: Communication• Problems Encountered• Software Server, GUI, App, Controllers, DB• Arduino Software UML• Controllers Flowchart• Tests• Live Demonstration
2
Motivation
• Home automation makes our lives easier, more
convenient and can allow lower energy
consumption.
– Turn on devices remotely (water boiler, heaters, etc.)
– Schedule devices to work in specific times (lights, AC,
coffee machine, radio, etc.)
– Monitor your energy consumption
3
Motivation
• But unfortunately, today, smart homes
technology is very expensive.
– Controlling devices and installation are expensive.
– Requires 3rd party installations.
– Often needs to be implemented in the house’s
infrastructure.
4
Project Goal
• Design a remotely controlled Multifunction
Outlet Power Strip.
• The power strip will be controlled with an
Arduino Processor using WIFI via a designated
server.
• The power strip will have local functionality and
automatic fail-safes.
5
Block Diagram: Hardware
6
ESP8266
WIFI
Arduino Nano
Controller
Heat Sensors
220V Relay
x3
220V Outlets
x3
x3 Hall effect
Sensors
Arduino Nano Processor
220V Source
5V DC Converter
ESP8266WIFI
Server
220V Outlet
220V Relay
Sensor SensorSensor
Digital
Analog
220V Outlet
220V Relay
220V Outlet
220V Relay
RTC
WIFI LED
TCP LED
3.3V DC Convert
er
Physical Diagram
GND
5V
PC
Mini USB
D11<->TX
D12<->RX
220V Source
5V DC Converter
3.3V DC Converter
GN
DG
ND
22
0V
5V
GN
D
3.3
V
Relay Module x3
Hall Sensors
x3RTC
Block Diagram: Communication
8
JAVA Application
UserVia PC or
Smartphone
mySqlDatabase
Arduino Controller
ESP8266 WIFI
Strip
Router
Server Socket Handler
Problems Encountered• Arduino Environment.
• Integration of ESP with Arduino Nano:
– ESP was a new component, required library implementation.
• Reliable Communication.
• Server platform:
– Attempts with Wampserver (PHP, Apachi, MySQL), problematic blackbox.
– Considered implementing server in C++ but was time consuming.
– Solution: Implemented a JAVA server.
Pros: Cross-Platform, dedicated libraries for socket handling, GUI(!), OOP, Interface
with SQL. Cons: required learning JAVA.
Problems Encountered
• Embedded programming limitations:
– Limited Arduino (Nano) memory, communication via UART, Small buffer.
• RTC:
– Arduino Nano has no inner timer, required for independent functionality.
– Handle clock skew.
– Identify communication loss.
– Solution: save last message time from server, compare to RTC time.
Block Diagram: SW Server
SERVER
GUIThread
Scheduler Thread
(Sensors)
Client ListenerMain Thread
Client Thread
Client Thread
Client Thread
Client Thread
Controller Controller Controller Controller
Client:JAVA App
Client:Android
App
Client:Arduino1
Client:Arduino2
Server GUI• Server GUI for communication
monitoring.
• Connect/Disconnect button,
choose port.
• Events logging
(retries, messages, exceptions).
Client Thread Controller• Wait for a message from the Arduino\Application and handle as a
controller.
• Parses messages:
<SRC>#<DEST>#<SW>#<OP>#<VAL>
• When changing status, Update the SQL.
• Database Handler: Wrapper for DB, handles communication with DB,
has SET/GET methods.
Client Thread ControllerPerform requested commands:
– Send Open\Close request from the Application to Arduino.
– Get Ack from Arduino and update the Database.
– Handle Timer Request from Application and Ack Timer from Arduino and
update the Database.
– Send Request for Temperature and Hall Effect values from Arduino and
update the Database upon response.
– In case of a high temperature send a stop command to Arduino.
MySQL Database• A free web database, always online, can be customized.
• Defines tables and fields, set default values.
• Handles communication between Server and Application.
• Has methods for updating fields on the Server.
JAVA Application• Scheduler updates Arduino status in real time.
• GUI for tables and fields.
• Open / Close Switches.
• Read switch status and sensors data.
• Enable/Disable timer for open/close.
• Set time to open and close.
• Optional: Create graphs, show statistics.
Arduino Controller FlowchartSetup
ServerOnline
?
Connect Timeout
MSG RCV
Yes
Yes
No
No Check Timeout
Close All
Handle MSG
No
Yes
High Temp?
No
Timer expired
?
No
Yes
Open/ Close
YesNo
Software UML: Arduino
Initialize System1. Start server using an opened port.
The Server will start a Socket on the selected port and wait for a new clients.
2. Power On the Arduino:
The Arduino will start a connection.
Connect to Wi-Fi.
Connect to the Server using Socket.
Repeat connections upon failure
When connected, Arduino sends name.
The server saves name and add to the List of Clients.
The Server sends timestamp to Arduino to setup the RTC Time.
Connection established, Arduino listens to incoming messages and performs commands.
After 90 seconds timeout (lost connection) Arduino switches to a self controller.
Initialize System3. Start Application:
The Application opens a socket on the selected port number.
Upon success, the Application registers as a client on the server.
The Application gets information, displays it to the user form the DB.
Send a command to the server and update the status information.
Tests
• Test manual turning on and off of switches.
• Test Scheduled turning on and off of switches.
• Test Failsafe in high Temperature or current according to sensors.
• Test local functionality when communication is down.
• Restart after power lost (server re-Init)
• Sync with RTC.
21
Live Demonstration
Questions?
23