logo-mobile

ROHM

ROHM
Menu
  • Arduino –
  • Raspberry Pi –
  • Trending –
  • Others –
  • About –
  • Contact –

Raspberry Pi

Diving into IoT: Geekcraft your own Wi-Fi Switch!

Lasse Efrayim Jespersen
Published by Lasse Efrayim Jespersen at November 15, 2019
Categories
  • Raspberry Pi
Tags
Arduino Electricity Meter
Internet of Things DIY

Tierney – stock.adobe.com

Table of contents

  1. Introduction
  2. A fuzzy spec
  3. ESP32 hardware overview
  4. Loading the firmware to ESP32
  5. Runtime!
  6. Choose your hub: home is where Heart.local is
  7. Building the Wi-Fi switch

1 Introduction

The Internet of Things has indelibly imprinted itself into popular culture. Things have been around since the Big Bang, but connecting them in an intelligent manner, to make them behave beneficially, all while interconnected, is a recent development. Cells did it in the primordial ooze of Earth’s oceans after a few lightning strikes, and amino-acids had created the foundation for the first cells. A cooperative endeavor? No, not at all, cells lack higher intelligence. They want to live, in endless mutating iterations, over the eons. Just so you came to be, now reading this in an article about IoT.

IoT development must be carried out with a clear purpose, and designed with future iterations in mind. Of course, you don’t have eons, just an idea and perhaps some months to design your prototype. Then, it’s time for PCB design. It may please you to know that your contribution to IoT will, like a single cell joining with another in the dawn of time, one day result in blossoming AIs, which may or may not choose to wipe out humanity. It’s binary. Carry on!

In this article, you will learn how to make Wi-Fi switch that you can use for your IoT project with MicroPython and ESP32.

2 A fuzzy spec

I needed a local IoT Wi-Fi switch for two 230V AC loads up to 500-600W each. It would be highly subject to change (in code), needed to be mountable anywhere in my home while remaining connected to my WLAN, and also be quick to modify/expand on the hardware side. That meant I had to use MicroPython…

… On an ESP32! Its pins can source ~10mA, and only need a 330-ohm resistor in series to protect them. All outputs drive 3.3V, which is perfectly fine for modern MOSFETs to drive even higher voltage loads. Just be sure you use logic level MOSFETs. The WiFi bit can drive ~150Mbit/s (18.75MByte/s), and using Loboris’ ESP32 firmware (available here) much time can be saved, because it already has the libraries for mDNS and all the other things needed.

mDNS makes your ESP32 discoverable on your network (multicast to 224.0.0.251 for you Wireshark enthusiasts out there), and lets you tell the other peers what services a device offers. It is the same system that is used by media centers and Chromecasts to offer streaming. I use it to autodiscover my Raspberry Pi hub (HEART.local), and only accept commands from this.
—
When connected with a USB TTL adapter to your ESP32’s UART, you can break out of a running program at any time with CTRL+C, look at variables, investigate memory usage (micropython.meminfo(1), esp.freemem() ), free up memory ( gc.enable(), gc.collect() ), enter paste-mode ( CTRL+E, paste, CTRL+D ) and see how that a idea will work out.

Using ampy ( ‘ampy –port COM4 –put boot.py’ ), mpfshell ( ‘mpfshell -o ttyUSB0 -nc “put boot.py ; put main.py” ‘ ) or simply ESPlorer for a graphical interface on Linux, Windows, and MacOS X. That is, if you don’t just use the WebREPL ( ‘import webrepl’, ‘webrepl.start()’ ), which lets you upload/download code and view output from the running code. For simplicity’s sake, you can browse here to interact with MicroPython boards on your network.

3 ESP32 hardware overview

ESP32 diagram

ESP32 specifications

  • CPU dual-core @ 160/240MHz, Xtensa(R) 32-bit LX6 microprocessors
  • Performance: <=600 DMIPS
  • Chip ESP32D0WDQ6 (revision 1)
  • Wi-Fi: 802.11/b/g/n/e/i – 802.11n @ 2.4GHz up to 150Mbit/s
  • Bluetooth
  • RAM:
    • 448KB ROM for booting and core functions
    • 520KB on-chip SRAM for data and instructions
    • 8KB SRAM in RTC (RTC FAST MEMORY) for recovery from deep-sleep mode
    • 8KB SRAM in RTC (RTC SLOW MEMORY) for co-processor during deep-sleep mode
    • 1Kbit eFuse (256 bits for system (MAC and chip config), 768 bits for user applications, flash encryption, and Chip-ID
    • 40MHz crystal, can output PWM at 40MHz
    • Can be expanded with SPIRAM! Up to 4 x 16MB external QSPI flash/RAM chips, up to 8MB of external flash/SRAM mapped to CPU data space, supporting 8-bit, 16-bit, and 32-bit access. This SRAM can be written to:
      • FLASH: 4MB SPI flash (on GPIO6, GPIO7, GPIO8, GPIO9, GPIO10 )
      • SECURITY: IEEE 802.11 standard security features:
        • WPA/WPA2/WAPI
        • Secure boot
      • Flash encryption
      • 1024-bit OTP, up to 768-bit for end users
      • Cryptographic hardware acceleration for AES, SHA-2, RSA, elliptic curve cryptography (ECC), random number generation (RNG)

ESP32 datasheet

The dual-core CPU and 520KB RAM is a great leap forward from the 16MHz and 2KB SRAM you may be used to from Arduino’s atmega328p (the Uno for example), and gives you plenty of speed and space to develop even highly complex IoT systems. My Wi-Fi switch is trivial, compared to what could have been done. But, I’ve added male pin headers on both sides of the ESP32 and can add more functionality to my build whenever I want.

ESP32 Wi-Fi Switch

wifiswitch.zip

4 Loading the firmware to ESP32

You’ll only need esptool to upload the Loboris MicroPython firmware. For your convenience, use my script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
[begin flash_lobo_esp32_all.sh]
# Enable flashing by holding the button to the right of
# microUSB port when powering ESP32 on
_baudrate=230400
_port=/dev/ttyUSB0
esptool.py --chip esp32 --before no_reset --after no_reset \
--baud $_baudrate --port $_port erase_flash
esptool.py --chip esp32 --port $_port --baud $_baudrate \
--before no_reset --after no_reset write_flash -z \
--flash_mode dio --flash_freq 40m --flash_size detect 0x1000 \
bootloader/bootloader.bin 0xf000 phy_init_data.bin \
0x10000 MicroPython.bin 0x8000 partitions_mpy.bin
[end flash_lobo_esp32_all.sh]
 

To connect, you can use the terminal command ‘python3 -m serial.tools.miniterm’, on Windows, Linux, and MacOS. Miniterm is installed with the python3-serial package; or, simplify your life by downloading putty. The port will follow different naming conventions, depending on whether you use Windows, Linux, or MacOS. Both programs ask you to enter the port you want to connect to, as well as baud rate. Use 115200 for MicroPython. The port to connect to will vary on Windows systems (look for COM# port changes in Device Manager when you plug your device in), whereas on Linux/similar, it’ll typically be ‘/dev/ttyUSB0’ for the first USB serial adapter connected, ‘/dev/ttyUSB1’ for the second, etc.

MicroPython’s ease of use and flexibility all add up to you being able to devote your time to developing electronics, without the code standing in the way.

5 Runtime!

Your ESP32 running MicroPython will concern itself first with ‘boot.py’, and next, if it exists, ‘main.py’. ‘boot.py’ is generally used to initialize Wi-Fi, and make the system ready for use. I kept all my instructions in ‘boot.py’, but you can shuffle the last few forever-loops into ‘main.py’ if you prefer. If you’re familiar with Arduino, think of ‘boot.py’ as ‘setup()’, and ‘main.py’ as ‘loop()’, though you’ll need to add a ‘while True:’ to make ‘main.py’ loop forever.

The function ‘connection_handler()’ sets up a Wi-Fi connection, iterating over any configured WLANs in the ‘_wlans’ tuple. If it cannot connect, it’ll start over until it succeeds. It should be called every once in a while.

The “sta_if.status(‘rssi’)” call sadly doesn’t work in this build, which is otherwise helpful for placing your ESP32 IoT device where signal is just excellent. It’s great for seeing your Wi-Fi signal strength. Anything lower than -80 is likely to result in intermittent network failures, whereas -65 or higher is good.

Controlling the relays is ‘relay_handler()’, a self-documenting ifthis-dothis-ifthat-dothat block of code. It’ll return a string of text to inform the hub the command it sent to the ESP32 was dutifully executed. We don’t have a simple state machine to track relay states, simply because Loboris’ ESP32 build doesn’t seem to work with ‘state = pin.value()’. You can still add state tracking, but it should be done with ‘pin.value()’. I’m sure this will be fixed eventually; it’s worked flawlessly with the official MicroPython firmware.

When setting up mDNS and discovering the hub (‘HEART.local’), the code stubbornly keeps trying to resolve the hub until it succeeds. This is intended to assist you in getting your setup right on the Raspberry Pi. The commands ‘avahi-browse -avtr’ and ‘avahi-resolve –address/–name’ are useful!

Finally, after much printing of useful information, we enter the main loop. Listening on port 10101/tcp, the ESP32 checks for valid commands, and passes those that check out on to ‘relay_handler()’. You can disable the check for “are-you-in-fact ‘HEART.local’?” trivially, it’s just a novelty and not a true authentication mechanism. mDNS network names can be forged, and over time, the hub will change its IP address.

The final loop will keep running forever, only concerning itself with input from the network. You may want to add an ‘except KeyboardInterrupt: break’ if you want to play around with it. It’s included in wifiswitch.zip.

6 Choose your hub: home is where Heart.local is

Wi-Fi switch with Raspberry Pi hub

For your hub, I recommend using a Raspberry Pi. View our guide on how to set up a Raspberry Pi, and connect it to your network. A Raspberry Pi Zero W is ideal for headless operation, but if you want a graphical interface, use a Raspberry Pi 2/3/4 B/B+. Of course, you can merely operate your Wi-Fi switch from your laptop, if it’s already running Linux or something similar. Advanced users can try OpenWRT, which is as capable on a modern router as the Raspberry Pi 4 B, and already running 24/7. The only software packages needed are avahi-daemon and avahi-discover (Linux/similar); see wifiswitch/rpi/etc/avahi/avahi-daemon.conf in wifiswitch.zip for an example configuration. If you use a Raspberry Pi, be sure to run upgrade.sh and setup.sh in wifiswitch/rpi on your hub, and then everything should be fine; just a few useful extra packages will be installed, in addition to avahi-daemon. Particularly useful is ‘nmap’, which will let you view every node and service on your network.

The avahi-daemon is usually pre-installed on desktop and laptop Linux distributions such as Ubuntu. If not, use your package manager to add it to your system. The avahi-discover package must also be installed. In your terminal, enter ‘sudo apt update; sudo apt install avahi-daemon avahi-discover’. Then, use wifiswitch/rpi/wifi_switch.sh from wifiswitch.zip to operate your WiFiSwitch. It’s easy to time events, and if you’re on vacation, cron will turn your lights etc. on and off when you like, giving thieving types the impression there’s someone home. Flipping the living room and bedroom lights at 1-second intervals? Scary people do that kind of thing. Don’t do 3-30Hz cycles, however, as this can induce epileptic seizures.

When checking your setup, use ‘avahi-browse -avtr’ to see all mDNS peers and their services. ‘avahi-browse -lavtr’ will show everything except the system you’re on. Using ‘avahi-browse -avtr’ to see all services is a great way to debug your setup! The script ‘wifi_switch.sh’ uses the command ‘avahi-resolve –name WiFiSwitch.local’, which you should use for looking up what mDNS name a device has, with the command ‘avahi-resolve –address “.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
[begin wifi_switch.sh]
#! /usr/bin/env bash
# &lt;relay1|relay2|both&gt; &lt;on|off&gt;
set -eu -o pipefail
# Usage: wifi_switch.sh &lt; relay1 | relay2 | both &gt; &lt; on | off &gt;
# Examples:
# wifi_switch.sh relay1 on
# wifi_switch.sh relay1 off
# wifi_switch.sh relay2 on
# wifi_switch.sh relay2 off
# wifi_switch.sh both on
# wifi_switch.sh both off
 
USAGE() {
echo "Usage: "$( basename $0)" &lt; relay1 | relay2 | both &gt; &lt; on | off &gt;"
cat &lt;&lt;-"EOF" Examples: wifi_switch.sh relay1 on wifi_switch.sh relay1 off wifi_switch.sh relay2 on wifi_switch.sh relay2 off wifi_switch.sh both on wifi_switch.sh both off EOF } if [ $# -ne 2 ] ; then USAGE ; exit ; fi NC=$( which nc 2&gt;/dev/null ) ; if [ X"" = X"$NC" ] ; then \
echo "[!] No netcat in \$PATH? Exiting ..." ; exit ; fi
# avahi-resolve --name foo.local
# avahi-resolve --address 192.168.0.101 , etc.
AR=$( which avahi-resolve 2&gt;/dev/null ) ; if [ X"" = X"$AR" ] ; then \
echo "[!] No avahi-resolve in \$PATH? Exiting ..." ; \
exit ; fi
SW_NAME='WiFiSwitch.local'
SW_ADDR=$( $AR --name $SW_NAME 2&gt;/dev/null | awk \
'{print $2}' )
# Did $SW_NAME reply?
if [ -z $SW_ADDR ] ; then echo \
"[!] No reply from $SW_NAME - is the name correct? Is it online?" ; \
exit ; fi
SW_PORT=10101
 
# Check arguments
case $1 in
'relay1')
  RELAY=$1
  ;;
'relay2')
  RELAY=$1
  ;;
'both')
  RELAY=$1
  ;;
*)
  USAGE
  exit
  ;;
esac
case $2 in
'on')
  ACTION=$2
  ;;
'off')
  ACTION=$2
  ;;
*)
  USAGE
  exit
  ;;
esac
# Remove these two lines once you have adapted this example script to your purposes
echo "INFO: Name=&gt;$SW_NAME address=&gt;$SW_ADDR port=&gt;$SW_PORT relay=&gt;$RELAY action=&gt;$ACTION"
echo "COMMAND: echo $RELAY $ACTION | nc -w 1 $SW_ADDR $SW_PORT"
 
# The '-w' flag sets timeout in seconds
echo -n "REPLY: " ; echo "$RELAY $ACTION" | nc -w 1 $SW_ADDR $SW_PORT
echo
[end wifi_switch.sh]

Here’s a log from the ESP32, booting up, and acting on commands from my hub.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[begin esp32.log]
...
D (1096) MicroPython: Main task exit, stack used: 1392
I (1098) MicroPython: [=== MicroPython FreeRTOS task started (sp=3ffc5c10) ===]
 
Internal FS (SPIFFS): Mounted on partition 'internalfs' [size: 1048576; Flash address: 0x200000]
----------------
Filesystem size: 956416 B
Used: 10752 B
Free: 945664 B
----------------
[!] Booting, running boot.py ...
I (2058) phy: phy_version: 3960, 5211945, Jul 18 2018, 10:40:07, 0, 0
[!] Hostname: WiFiSwitch.local
[!] Connecting to b'TestNetwork' using key b'TestPassword' ...
[!] Network configuration: ('192.168.0.100', '255.255.255.0', '192.168.0.1', '192.168.0.1')
[!] Starting mDNS ...
[!] Discovering control hub HEART.local ...
[!] HEART.local has address 192.168.0.101
[!] Entering listener loop, responding to arg1=&gt;relay1|relay2|both arg2=&gt;on|off - but only from HEART.local (192.168.0.101)
[!] relay1: OFF
[!] relay1: ON
[!] relay1 + relay2: OFF
[!] relay1 + relay2: ON
[!] Connected peer 192.168.0.103 is _NOT_ HEART.local (192.168.0.101), rejecting it ...
[!] Connected peer 192.168.0.103 is _NOT_ HEART.local (192.168.0.101), rejecting it ...
[!] relay1 + relay2: OFF
[!] relay1: ON
[!] relay1: OFF
[!] relay2: OFF
[!] relay2: ON
[!] relay2: OFF
[!] relay1 + relay2: ON
[end esp32.log]

And on the hub:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
[begin hub.log]
$ # give wifiswitch a rigorous workout!
$ while true
do
wifi_switch.sh relay1 on ; sleep 2
wifi_switch.sh relay1 off ; sleep 2
wifi_switch.sh relay2 on ; sleep 2
wifi_switch.sh relay2 off ; sleep 2
wifi_switch.sh both on ; sleep 2
wifi_switch.sh both off ; sleep 2
done
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;relay1 action=&gt;on
COMMAND: echo relay1 on | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay1 ON
WiFiSwitch: OK
 
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;relay1 action=&gt;off
COMMAND: echo relay1 off | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay1 OFF
WiFiSwitch: OK
 
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;relay2 action=&gt;on
COMMAND: echo relay2 on | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay2 ON
WiFiSwitch: OK
 
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;relay2 action=&gt;off
COMMAND: echo relay2 off | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay2 OFF
WiFiSwitch: OK
 
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;both action=&gt;on
COMMAND: echo both on | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay1 + relay2 ON
WiFiSwitch: OK
 
INFO: Name=&gt;WiFiSwitch.local address=&gt;192.168.0.102 port=&gt;10101 relay=&gt;both action=&gt;off
COMMAND: echo both off | nc -w 1 192.168.0.102 10101
REPLY: WiFiSwitch: relay1 + relay2 OFF
WiFiSwitch: OK
[end hub.log]

7 Building the Wi-Fi Switch

You’ll need these parts when constructing your device. If you don’t have them, check the part datasheets and use something with similar characteristics. For example, an LM317 is a perfectly good substitute for a 7805.

ESP32 Wroom (ESP32D0WDQ6 (revision 1))  https://www.adafruit.com/product/3269  
12V power supply, 1A https://www.newark.com/xp-power/vel12us120-us-ja/adaptor-ac-dc-12v-1a/dp/71Y7923  
Raspberry Pi Zero/Zero W/2 B+/3 B+ https://www.newark.com/raspberry-pi/rpi3-modbp/sbc-arm-cortex-a53-1gb-sdram/dp/49AC7637 
5.25V power supply https://www.newark.com/raspberry-pi/t6712dv/raspberry-pi-power-supply-90-264vac/dp/81AC2841 
2x 12V automotive relays, >=8A https://www.newark.com/te-connectivity/v23086c1001a403/relay-automotive-spdt-12vdc-30a/dp/86K0343 
2P 2.54mm screw terminal https://www.newark.com/buchanan-te-connectivity/282834-2/terminal-block-pcb-2-position/dp/12H8386  
2x 3P 2.54mm screw terminals https://www.newark.com/buchanan-te-connectivity/282834-3/terminal-block-pcb-3-position/dp/12H8387 
7805 voltage regulator https://www.newark.com/on-semiconductor/mc7805actg/ldo-voltage-regulator-5v-1a-to/dp/45J1442 
0.1uF + 0.33uF capacitors https://www.newark.com/multicomp/mc0805b334k500a5-08mm/ceramic-capacitor-0-33uf-50v-x7r/dp/46P6304 
3-5W heatsink https://www.newark.com/aavid-thermalloy/sw25-4/heat-sink/dp/01M9146  
2x PC817 opto-isolators https://www.newark.com/sharp/pc817x1nsz0f/transistor-output-optocoupler/dp/55X3057  
2x 330 + 2x 10Kohm resistors https://www.newark.com/velleman-sa/k-res-e3/480-piece-misc-resistor-kit/dp/43W7615 
Soldering iron, TS100 recommended https://www.newark.com/weller/wp35/temperature-controlled-soldering/dp/34F1023  
Solder, rosin core https://www.newark.com/gc-electronics/6033/solder-60-40-rosin-core-20g-1/dp/01E0120?st=solder%20rosin%20core 
Male and female 2.54mm pin headers https://www.newark.com/mcm/ph1-40-ua/break-away-2-54mm-40-pin-strip/dp/97W4638 

https://www.newark.com/mcm/rs1-06-g-413/1-x-6-position-female-socket-with/dp/97W4645 

2x BAT86 schottky diode https://www.newark.com/nexperia/bat86/rectifier-diode-single-50-v-200/dp/96K6771 
2x 2N7000 MOSFETs https://www.newark.com/on-semiconductor/2n7000/n-channel-mosfet-60v-200ma-to/dp/58K9650 
Project box (plastic, metal will block WiFi signal) https://www.newark.com/hammond/1591dbk/enclosure-multipurpose-plastic/dp/65F1761 
Thin solid-core wire (teflon coated!) https://www.newark.com/alpha-wire/2936-br005/hook-up-wire-36awg-brown-30-5m/dp/22AC3546  

Additionally, you’ll need some thick stranded wire (strip a power cord, you only need ~10cm), and optionally a rotary tool with a grinding bit.

It’s assumed you already own a soldering iron and have solder with rosin core. You can use any that has temperature control. It’s preferable to solder at 824 degrees F and only touch each solder point for 3-4 seconds.

This Fritzing diagram shows all connections. Note the sliding switch between 7805 Vout to ESP32. If you want complete isolation between the ESP32 and the relay board itself, use a DPDT switch and run both 5V and GND lines across this. Common ground isn’t necessary for correct operation of the opto-isolators. You can get rid of a minor headache by adding a DPDT switch, because it’s a no-no to power the ESP32 from both the 7805 and microUSB simultaneously.

Wi-Fi switch fritzing diagram

The microUSB port is often used for uploading code. The 5V pin on the microUSB port isn’t directly connected to the 5V pin; there’s a Schottky diode forward biased to that pin. Connecting two 5V power sources will not only blow the ESP32 but also maybe your USB port as well. Let’s never find out. Simply turn the sliding switch to its OFF position before connecting your microUSB cable to your ESP32. It won’t affect the board’s operation; the opto-isolators aren’t galvanically connected to the MOSFETs driving the relays. Consider getting a USB TTL adapter, which will also let you connect to your ESP32 without resetting it each time, restarting your program. Don’t connect its 5V wire to the board if you’ve powered it by other means.

Connect everything as shown in the diagram, paying particular attention to the AC carrying terminals on your relays. If you have a rotary tool with a grinding bit, remove the copper pads surrounding the terminals, and run the thick isolated wire over the cleared surfaces. A switching relay will always arc, but those arcs should never leave the relay itself. Grind those pads. It’s not a big concern for 230V, but worth doing.

Wi-Fi switch relays

Once it’s done, and you’ve verified the relays work, apply hot glue on and between all points where AC flows, with all its lethal potential, and tape it over with some electrical tape. Hot glue is form-stable up to 194 degrees F, so it’ll stay there forever. Now, we’re certain there’ll be no physical injury.

WiFi Switch electricity meter

The PC817 opto-isolators are marked A-K, C-E. That means the pin by the little round mark is the anode (A), and the pin next to it is the cathode (K). You’ll need to place a 330 ohm resistor in series from the ESP32 pins to each of the opto-isolator anodes. It’s an infrared LED inside. I’m sure you know LEDs — they will burn out without current limitation. The emitted infrared light turns on a transistor collector (it’s not quite the same as an NPN though), letting the load on the collector (C) side pass through the emitter (E), to the 2N7000 MOSFET gate. When this happens, the 2N7000 will switch on, letting current flow from the relay through the drain, to GND via the source, and it’ll click right away.

The 2N7000 MOSFETs are easy, but only if you remember to place the 10Kohm pull-down resistors between gate and GND. If you forget this, the gate won’t ever really be off, and your relays won’t switch reliably.

Your build doesn’t have to be pretty; it’s going to be in a box for years and years. It won’t draw much power (about ~2.7W), but it’s still a good idea to add a few small holes in an unseen part of the project box so the system can cool itself passively. Without a few holes, heat buildup can make things behave in an undefined way.

Wi-Fi switch

Below is a similar board, connected to my Raspberry Pi hub. This has its own 5V power supply, and only relies upon four 3V3 signal lines and a GND connection from the Pi. While this is also not pretty, it’s smaller than a PCB designed with the same capacity and relays.

Wi-Fi switch

Test your circuit first on a breadboard, and then build it. When you’ve built it, you can begin adapting the code to your own ideas. Whatever your ideas are, they’re going to be much better than IoT shoes. I guess I’ll never really know why Amazon recommends these to me when I only ever bought some tools and books, on IoT.

Lasse Efrayim Jespersen
Lasse Efrayim Jespersen
Born in Israel, Lasse moved to colder latitudes. His natural inclinations led him to the gore of Perl, the efficiency of C/C++, and the final elegance of MicroPython. He enjoys making machines with ESP8266/ESP32/Raspberry Pi and Arduino.

Check us out on Social Media

  • Facebook
  • Twitter

Recommended Posts

  • How to Use a Raspberry Pi as a Web ServerHow to Use a Raspberry Pi as a Web Server
  • DIY Arduino Home Security System using ROHM Sensor Kit Part 2 – Cayenne SetupDIY Arduino Home Security System using ROHM Sensor Kit Part 2 – Cayenne Setup
  • Top 6 DIY Projects You Can Do to Expand Your IoT ProjectsTop 6 DIY Projects You Can Do to Expand Your IoT Projects
  • DIY Facial Recognition With Raspberry PiDIY Facial Recognition With Raspberry Pi
  • The History of Raspberry PiThe History of Raspberry Pi
  • How to integrate an RFID module with Raspberry PiHow to integrate an RFID module with Raspberry Pi
Receive update on new postsPrivacy Policy

Recommended Tutorials

  • How to integrate an RFID module with Raspberry Pi How to integrate an RFID module with Raspberry Pi
  • How to Use the NRF24l01+ Module with Arduino How to Use the NRF24l01+ Module with Arduino
  • How to Run Arduino Sketches on Raspberry Pi How to Run Arduino Sketches on Raspberry Pi
  • Setting Up Raspberry Pi as a Home Media Server Setting Up Raspberry Pi as a Home Media Server

Recommended Trends

  • SewBot Is Revolutionizing the Clothing Manufacturing Industry SewBot Is Revolutionizing the Clothing Manufacturing Industry
  • All About The Sumo Robot Competition And Technology All About The Sumo Robot Competition And Technology
  • 5 Interesting Tips to Calculating the Forward Kinematics of a Robot 5 Interesting Tips to Calculating the Forward Kinematics of a Robot
  • Go Inside the Drones That Are Changing Food Delivery Go Inside the Drones That Are Changing Food Delivery
Menu
  • Arduino –
    Arduino Beginner’s Guide
  • Raspberry Pi –
    Raspberry Pi Beginner's Guide
  • Trending –
    Updates on New Technologies
  • Others –
    Interviews / Events / Others

Check us out on Social Media

  • Facebook
  • Twitter
  • About
  • Company
  • Privacy Policy
  • Terms of Service
  • Contact
  • Japanese
  • 简体中文
  • 繁體中文
Don’t Forget to Follow Us!
© Copyright 2016-2023. Device Plus - Powered by ROHM
© 2023 Device Plus. All Rights Reserved. Muffin group

istanbul escort istanbul escort istanbul escort