WiFi Outlet X4 Raspberry Pi
by ScottieDigital in Circuits > Raspberry Pi
1242 Views, 22 Favorites, 0 Comments
WiFi Outlet X4 Raspberry Pi
This is on-going from previous projects.
https://www.instructables.com/WiFi-Outlet-X2-Raspberry-Pi/
https://www.instructables.com/WiFi-Outlet-Raspberry-Pi/
https://www.instructables.com/Raspberry-Pi-IoT/
I hope you Enjoy this project as much as I do! ~8ms response time!
***PLEASE NOTE THAT WITH PREVIOUS IOT PROJECT YOU CAN UPGRADE TO ADD A CAMERA OR SENSOR OF YOUR CHOICE!*** (jUST DOWNLOAD THAT PACKAGE INSTEAD)
I can now control all I need from the luxury of my bed without moving! I know the first thing you guys want to say is hey you have here listed 4 channel and there are 5 outlets. Well 4 of them are controlled and the 5th is always on without any control. Just giving you an extra outlet at hand than running an extra cord.
Supplies
Raspberry Pi Zero W or Zero 2W & memory card 8-32GB Anything above will NOT work.(I prefer 1W)
Get some nice heatsinks with fan 15mm
30mm fan to mount for air flow (optional)
DHT 22 (optional)
5V 2A power supply (harvested from some random and cut out circuit board with cutoff wheel)
IEC Standard C-14 Inlet Connector
5v 20 A relay (x4)
NPN transistor (x4)
1N4007 diode (x5)
1K resistor (x5)
LED red (x4)
LED yellow
330 OHM (x4)
AC Outlet, NEMA 5-15R, 3 Wire 15A, Snap-in 32041 [x5]
External Antenna
(U.FL/IPX to RP-SMA Female Antenna wire, antenna)
U.FL IPX RF SMD SMT Solder PCB Mount Socket Jack Female Connector
capasiter metalized film ~ 1uF
Various wire, solder, liquid tape, hardware screws, super glue
3D printer and filament
Cost ~ $148
3D Printing
Bonding
Use super glue OR soldering iron with extra material for plastic welding! I did this and enjoy it!
Use plain super glue for mounting on the feet and mounting support on bottom of case.
When finished you and push and "snap-in" place all connectors! *I personally added in EXTRA support by adding UV super glue around the borders of all the outlets and inlet*! Because I don't trust PLA and spent many rolls worth getting it the right fit! and many projects! So YES the snap-in works and can hold. Just gluing in place helps it NEVER go anywhere. =)
Soldering
This can take much time! Also air soldering the antennae connector was very difficult! Prepping the relay circuit separately was helpful. View pics for help. The LED's can be hot glued in place. Power Supply as shown is from Adapter cut out with cutoff wheel. You can use wire cutters to "trim" down the power supply to get a better fit under inlet where it's suppose to sit. ****** When soldering the Inlet jack in place cable! IMPORTANT! ****** Else pins can wind up crooked!! !******
Relay 1 = GPIO 5
Relay 2 = GPIO 6
Relay 3 = GPIO 13
Relay 4 = GPIO 26
DHT 22 = GPIO 23
The sensor is optional but if you are adding it in you will have to drill a hole for it out the back. I tap into 5V power supply but I put a 3.3 logic level converter on it, sensors "usually" are more accurate? Than 5V.
I have to APPOLOGIZE for that the Pi can ONLY fit in 1 direction :( and it's the wrong way. I found out too late I couldn't switch it. But at least everything does FIT in place! AND WORK! But if I RE_DID or RE-ENGINEER I wouldn't be using a rectangle. and shrink it down in size. But this works well and got plenty of space and air flow.
Raspberry Pi Command Line
Download and burn image to micro sd card
Go through settings and enable Remote GPIO
sudo raspi-config
Personal settings
sudo nano /boot/config.txt
add to bottom
avoid_warnings=1
Save and Exit. Next we change settings at startup
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
add these lines
@xset s off
@xset s noblank
@xset -dpms
(comment out screensaver with # like # @xscreensaver)
Save and Exit. Next we can set static IP
sudo nano /etc/dhcpcd.conf
Goto Bottom and add
interface wlan0
static ip_address=192.168.2.190/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
save and exit. Next Wifi Settings
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=us
network={
ssid=""
psk=""
key_mgmt=WPA-PSK
}
Save and Exit. Now we'll Reboot for settings to take efect.
sudo reboot
sudo apt-get update
sudo apt-get full-upgrade
sudo apt-get -y dist-upgrade
Now Install Python
sudo apt install python
sudo apt install python3 idle3
To get sensor working.
sudo apt-get install python-setuptools
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get install build-essential python-dev
sudo python setup.py install
Next we'll do Apache webserver
sudo apt install apache2 -y
Next we need permission for ftp to transfer files
cd /
cd /var/www
sudo chown pi: html
Next we change the port # of the pi
cd html
sudo nano /etc/apache2/ports.conf
change "Listen 80" to Listen 8030 Save and Exit
Now install PhP
sudo apt install php
Set permissions on ppi for browser access
sudo visudo
add the following lines at the bottom
www-data ALL=(ALL)NOPASSWD:ALL
www-data ALL=/sbin/reboot
www-data ALL=NOPASSWD:/sbin/reboot
www-data ALL=/sbin/shutdown
www-data ALL=NOPASSWD:/sbin/shutdown
www-data ALL=/sbin/sysctl
www-data ALL=NOPASSWD:/sbinsysctl
Save and Exit.
cd ..
In the "www" folder run command
sudo chwon -R www-data:www-data /var/www
Next WE NEED Wiring Pi ABSOLUTE MUST!
cd ~
In "home/pi" folder
sudo git clone https://github.com/WiringPi/WiringPi
cd WiringPi
sudo ./build
Now you can read GPIO pins
gpio readall
Now you should be all setup that you can put the ip address and port that we had assigned in your web browser in view what we have!. Currently there should be some sort of basic index.html page there. Finally here is the link you NEED to download and unzip to replace in the "html" folder. I used filezilla to ftp to the pi and transfer the files. [/var/www/html/] If doesn't work change file permissions. There are many ways you can do this but I just do this in FTP and do all the files in folder to 777. Click link for code package
https://github.com/ScottieD369/Raspberry-Pi-IoT/raw/main/Pi%20Server%204.zip
I can say there is a "hidden feature" in IE browser! via pc. Then you can use any browser on ANY device to view! These lovely buttons love to change color! Just like anything else if you want to access this outside your network port forward on router! Yes tested and WORKS! ***PLEASE NOTE***(Your IP and port may differ? Just change in the files.)
http://IPADDRESS:PORT/index.html
Then if you have port forward that port the IP becomes the IP of your location NOT the pi!!!
Troubleshooting
I gave plenty of wire for pulling out the Pi Zero to work with. For some reason it wouldn't work so I had to redo everything. Having the extra length of wires on the board worked out GREAT! Even if you had to swap out boards this still works out! I am glad for the extra length. It does get slightly warm in there so you can drill holes appropriately and mount a 5V fan to cover. It dropped 20 degrees when I did. But now a fan is running and you can hear it. So it's either deal with it or remove it? They do seem fine to work well "hot".
Mounting
I added in screw mount to be super glued on back for mounting to wall.
Transfer/Move Location
If you are moving to a different location or gifting to a friend or family. These are the things you need to check and change. Everything you need to connect to network
SSID PASSWRORD IP ADDRESS RANGE
sudo nano /etc/dhcpcd.conf
interface wlan0
static ip_address=192.168.2.190/24
static routers=192.168.2.1
static domain_name_servers=192.168.2.1
save and exit. Next Wifi Settings
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=us
network={
ssid=""
psk=""
key_mgmt=WPA-PSK
}
Save and Exit. Now we'll Reboot for settings to take efect.
sudo reboot
That is all the changes you need to make.
ENJOY!
Final Conclusion
This is a fun project I really love! You can now remotely control anything you want from anywhere in the world you want! From practical jokes to Christmas or Halloween! or Security Deterrent. Or if you want just a fan and a light in your bedroom. ENJOY!