WiFi Outlet Raspberry Pi
by ScottieDigital in Circuits > Raspberry Pi
1009 Views, 2 Favorites, 0 Comments
WiFi Outlet Raspberry Pi
This project is a breakdown version of my previous project here >>>
https://www.instructables.com/Raspberry-Pi-IoT/
AND MY NEW PROJECT HERE! >>>>>>
https://www.instructables.com/WiFi-Outlet-X2-Raspberry-Pi/
https://www.instructables.com/Wifi-Outlet-X4-Raspberry-Pi/
I then wanted just to control and outlet for security purpose. ONLY nothing else.
So I came up with this! As you can see from the video it functions very easy and fast! In an instant!
Also with a ton of bells & whistles!
Supplies
Raspberry Pi Zero W or Zero 2W & memory card 8-32GB Anything above will NOT work.
Any 5V Relay from scrap parts with NPN transistor and resistor. [x2 EVERYTHING]
Outlet Power Socket (snap in type, square) [x2]
5V 1A USB type power supply (picture in file)
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
CPU Heatsink (I cut and made one from scrap so that it was bigger fins)
NEON light and resistor [x2]
120VAC OUTLET PRONGS (came from scrap timer outlet)
Various wire, solder, liquid tape, hardware screws, super glue
3D printer and filament
3D Printing
Soldering & Assembly
The Pi is mounted in place with screws.
Thermal compound on heatsink and apply to chip. Don't Forget! It does get hot inside there~!
The relays are wired to Pins: 29, 31.
NEON lights are directly on the outlets.
The transistors are hot glued in place over the relays.
Run Power Supply (+) over to the relays direct. And the (-) comes from the transistors. Other end transistor goes to power supply (-) Then off the resistor you goto the pi data pins.
***PLEASE NOTE*** This relay setup runs on getting a "HIGH" while relay module runs on "LOW". So this had to be changed from my original code in MASTER PROJECT using a module. So if you decide on a module you need to change according in code. Else it will be backwards. My original code would work for module but you have to remove all extra's... Posted above.
electrical tape over the 5V power supply and glued in corner.
EXTERNAL ANTENNA EXTREMELY HARD! (youtube search)
Hopefully you get the antenna on and your good to go.
The Outlet prongs can be cut from an existing gadget? You want these close and not long so I printed out this part to hold them in place while I use a cut-off wheel.
Outlet prongs are UV super glued in place. I use another outlet on the other end to hold the prongs in place at other end all the way in. So ensure a proper connection. Then you can remove the extra outlet to see the prongs in place. You can add more glue on this side also. There is plenty of room for everything inside the box just keep wires tight! Also as you can see from picture every connection is liquid taped up for insulation and no short could happen.
Things Todo on Pi
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%20Server2.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!!!
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
The price will vary with the purchase of the Pi Zero. For a $5 originally priced board to the current price is $60 for a Zero 2W. 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!
TESTED IN WISCONSIN WINTER INSIDE GARAGE SURVIVED WONDERFUL!!! (YEARS)
ALSO NOTE IF IN GARAGE TRY TO AIR OUT DURING SUMMER THE RAFTERS CAN GET TO BE 145F.
I WAS WORRIED BUT IT DID SURVIVE.