- 1 Overview
- 2 Team Members
- 3 Links
- 4 Objectives and Goals
- 5 Challenges
- 6 Budget
- 7 Useful Resources
- 8 Gantt Chart
- 9 Design and Solution
- 10 Results and Solution
- 11 Next Steps
Our project is to create a smart outlet consisting of a raspberry pi zero, a relay, and a container that works between an AC outlet and a device. We'd like to be able to communicate between a web interface and the outlet to be able to turn the device on and off. We would also like to add timing control features through the web interface. If we are successful with the initial project, we will add additional modules to the web interface to be able to control multiple devices.
TA: Keith Kamons
Professor: James Feher
Objectives and Goals
Build a module that can relay between an AC outlet and device that we want to control
Build a web interface that successfully communicates with the built module in at least a binary fashion
Set up a server to host the web interface
- A majority of our programming expertise is in Java, and learning more about web development languages, especially Python, will be time consuming.
- We have minimal background in hardware and circuitry, so a big challenge will be ensuring that we will account for all of the details necessary for our module.
- We have no background in web security, so we need to be very careful in allowing access to the devices and files that we will be using.
- We have never worked with Raspberry Pi before.
- Linux is an unfamiliar operating system.
- Raspberry Pi(s) - provided ($35)
- Raspberry Pi Zero(s) - provided ($5)
- Relay - provided ($1.25)
- AC Prongs - $2.79
- AC Duplex Outlet - $0.43
- Module box - $27.44
- MCP 3008 - $3.75
- TMP 36Gz - $1.50
- SD card - provided ($4.99)
- Component (fan) - $16.99
- Cable - $6
- Outlet Covers - $14.44
Total: -----needs to be updated ----
Temp Sensor Resources
DevOps and Server Side Resources
Design and Solution
The website uses websockets to communicate with the raspberry pi hardware. The html buttons on the website will run a script on the pi to turn on/off the smart outlet.
Figure 1. Communication depicted between the AWS web interface and the user, the database with user data, and the pi module.
Figure 2. Original plan for configuration of the website pages and link paths
Sensors & Hardware
Sensors to Transmit Data: We decided to add sensors to collect data that can be displayed on the main web page. For our project, we were only able to add a temperature and light sensor, but many more features could be added in the future as the MCP3008 that we used has 8 channels available total. We had to wire an AD converter into the Raspberry Pi because it does not have one built in. The AD converter reads a voltage from the device and runs voltage through a conversion equation in the code to output a meaningful value. The AD converter sends that signal to one of the I/O pins on the pi so that it can constantly be reading a stream of data which we can display on the website.
Below is our program for converting values. Inside the for loop is our equation for converting voltage to temperature. For the photo-resistor, we decided to leave the values read from the ADC and tested a range of what values were considered bright or dark.
- Main program loop.
# Read all the ADC channel values in a list. values = *2 for i in range(2): # The read_adc function will get the value of the specified channel (0-7). if i==1: millivolts = mcp.read_adc(i)*(3300/1024) temp_C = ((millivolts-500.0)/10.0) temp_F = (temp_C*9.0/5.0)+32 temp_C = "%.1f" % temp_C temp_F = "%1.f" % temp_F values[i] = temp_F else: values[i] = mcp.read_adc(i)
Power Supply and Relay: Our device plugs directly into the wall, however a typical outlet supplies 120 volts. The Raspberry Pi can only handle 5 volts at a time so we had to include a relay to the module in order to separate the pi from the wall outlet voltage unless the device needs to be turned on. A signal is sent from our pi to tell the relay when to flip the switch closed and allow mains voltage to turn the module on and supply wall voltage to the outlets on the front plate for any device to be plugged into. We also decided to add a small LED beside the outlets that automatically turns on when the relay closes so that the user can always know when the outlets have power even if nothing is plugged in.
Results and Solution
Goals: Create a working website that allows us to interact remotely with a physical device consisting of a relay, raspberry pi, and sensors to be able to turn a connected outlet on and off, with a timing setting.
Actual: The website is able to interact remotely with the physical device and turn the outlet on and off. The server script works pretty consistently to open a websocket connection between the pi and website, and the website is hosted publicly as of right now so that anyone with the QR code or link have access to the outlet.
Problems: The server script on the pi zero does not turn on automatically on boot. Next steps would be to get crontab working so that both the IP Address emailer for the pi (currently have a smtp problem with accessing gmail, although curiously the emailer works on boot when the pi is attached to an HDMI cable) and the automatic server start work. This could be solved in several ways. First, because websockets can be created in a way that allows you to send messages knowing only the server IP address, whether or not the RasPi IP address is consistent, it can be sent as a variable to the EC2 acting as a server to be used to connect to the Pi's server script. This would be helpful if we use this device in an environment like WashU where the wifi makes the IP address of the Pi inconsistent, so the script can be changed dynamically. Otherwise, we can continue to use the email system and change the scripts only when necessary, which might be easier in a more stable internet environment. This would require debugging the gmail bug, which would allow us to obtain the email on boot - there may also be a crontab problem, because the server script is not running on boot.
Goals: Build a module that can contain the pi and its power supply, relay, ADC and other sensors as well as be safely wired to mains voltage.
Actual: A module that contains the pi 0, relay, ADC and sensors, and has two outlet plugs available for safe usage.
Problems: We were only able to have one electrical outlet on the box due to spacing issues inside when we had originally envisioned having four plugs available. Also, there was not enough room in the box itself to contain the power supply for the pi so we had to have a separate external battery. A next step would be to that entirely self contained so there is no need to plug into anything externally but a wall outlet. However, the box was built successfully and safely, and all the components work the way they should.
- Create a database of users that would improve security so that people don't have access to each others' outlets (password protected)
- Fix the crontab commands
- Add different features
- Outlets on timers (allow setting lights to come on at night, or if we have a motion sensor and there's no signal after 5 min, etc.)
- Outlets changing status depending on sensor input (turn outlet off if it's indicated as a light outlet above a certain brightness, use temp sensor to turn on fan outlet above a certain temp, etc.)
- Outlets with different statuses (light outlets, fan outlets, etc. as demonstrated in above examples)