- Notice
A Remote Controlled WiFi Antenna Switch
Introduction
This article describes the design and construction of a remote WiFi Antenna Switch for HF that is an order of magnitude more economical than any wireless remote switch available today. It is limited in its power handling and frequency bandwidth, but I believe it is of great use for most of ham radio operators.
The ESP8266, a little wonder
The core control processor for the switch is a WiFi enabled microcontroller from Espressif with a very small footprint, the ESP8266. It can be programmed in C by flashing it with the manufacturer’s (Espressif) software development kit (SDK). But it can also be programmed in LUA using the NodeMCU SDK (open source, just Google it or go to GitHub). LUA is a scripting language used widely in the gaming industry and I picked it to program the ESP8266 because of being compact, very high level and allowing me rapid prototyping.
The ESP8266 acts as an access point and/or a WIFI station, so once it is configured it acquires an IP address and then you can communicate with it via a web browser or a TCP connection (phone, tablet, computer, etc). The ESP8266 comes in many different packages, depending on the number of I/O ports you want to have access to. Figure 1 shows the ESP8266 ESP-12 which is the one I’ve chosen for the project. It has 8 available GPIOs (input/output ports or general purpose input/output) available, which was not enough for this application, but that was all I had. 8 GPIOs means that we can program the module so it can read and write stuff on these GPIOs. The ‘stuff’ is simply digital signals, a 0 or a 1, or in volts, a few millivolts or 3.3 volts. This is perfect to drive LEDs or relays and make them open or close according to some logic and control, either running on the module or instructed via a web or TCP server.
Fig. 1 - ESP8266 ESP-12
The module also features a serial interface so you can communicate with it to program or debug it.
There is plenty of material out there to get anyone going with this little wonder. The key things to know is that you will need a USB to serial module to initially talk to the ESP8266, be familiar with serial communication and able to do some script programming. For USB to serial, any FTDI232 based module will pretty much work, but be careful as they are counterfeit FTDI232 that can render useless, make sure whatever you get is genuine. Then you need to choose a serial terminal to send commands to the serial module that will send commands to the ESP8266. Something like CoolTerm available here would do the job. I use CoolTerm mostly on the Mac. Also, when you start copying LUA code into the module, CoolTerm does a great job. You can find more information, programming code examples and detailed instructions about setting up and programming the ESP8266 here
With this brief introduction to the ESP8266, you can start having a lot of fun prototyping all kinds of interesting WIFI projects. For example, if you have equipment that you can control with digital signals, like a tuner, you can easily build a remote switch that can do the job!
Driving the relays
I looked at several relay types, and for this first version of the switch, I decided that going with something on the lower power side would be a wise choice, something that could handle 100-300 Watts. There is plenty of time to improve the design and make it robust for high power transmitters. I started with a 4 position switch (but eventually I would be upgrading to 8 positions), so I needed to drive 4 relays. The ESP8266 has 8 GPIOs, more than enough to drive 4 relays (will it suffice to drive the 8 positions switch?). Not so fast. I wanted to be able to remotely find out the status of the switch, so for this I will need to monitor the state of the outputs, hence I needed another 4 GPIOs to do this (or 8 additional GPIOs once I upgraded to 8 positions). This is a total of 8 GPIOs. Oh, I forgot, ideally I also need a GPIO to drive an LED and show when the unit was successfully connected to the WiFi router and effectively grabbed an IP address. So, 9 GPIOs are needed. Am I out of luck? No, I am not. What if I used a x-to-y line decoder? I just needed a 2-to-4 line decoder but since I had a bunch of the 74HC238 3-to-8 line decoder, lets use them, and connect the unused input line to ground. The ESP8266 GPIOs were going to feed the 74HC238 and provide the logic to switch the outputs, then these outputs will drive a Darlington power driver like the ULN2803; this is because we could not drive the relays with the output of the 74HC238. Just for the 4 position switch and to make it safer, I decided to split the 8 ULN2803 outputs into 2 groups of 4, one group feeding the relays, the other the indicator LEDs.
Lets look at how the GPIOs from the ESP8266 would be driving the 74HC238:
GPIO0 |
GPIO2 |
Relay1 |
Relay2 |
Relay3 |
Relay4 |
L |
L |
H |
L |
L |
L |
H |
L |
L |
H |
L |
L |
L |
H |
L |
L |
H |
L |
H |
H |
L |
L |
L |
H |
GPIO0 and GPIO2 are the outputs from the ESP8266 being feed to the inputs of the 74HC238 , and Relay1 to 4 are the outputs of the 74HC238 being fed to the ULN2803. The outputs of the ULN2803 are then driving the relays and the indicator LEDs
Monitoring the output state
I had 8 GPIOs available and needed 4 for controlling the relays and 4 for checking the output state, plus 1 more to show connectivity state, nine in total. I am one GPIO short. After using the 3-to-8 decoder, I was just fine, two GPIOs for the 74HC238, one GPIO for WiFi connectivity, four GPIOs for switch status, exactly seven GPIOs needed, one less than what I have available. Now, how about if I upgraded to eight positions? Then I would need three GPIOS for the 74HC238 (as I needed to use the three inputs for the 3-to-8 scheme, and not just two), one for WiFi indication, eight for switch output status, which gives me a total of eleven GPIOs. Way too many!
How about using a multiplexer to read the output state? If I used a multiplexer like the 74HC4052, for the four position switch I would need two GPIOs to drive the multiplexer switching, one GPIO to drive the inhibit and one GPIO to read the output. That amounts to four GPIOs needed. So the number of GPIOs was fine for a four position switch.
How about eight positions? We saw that I needed eleven GPIOs, and that was too many. If we used the multiplexer solution, we could choose the 74HC4051, then we would need three GPIOs to drive the multiplexer switching, one GPIO to drive the inhibit and one GPIO to read the output. That amounts to five GPIOs needed. Considering I needed three GPIOs for the 74HC238 and one more for the WiFi indication, that totals to nine GPIOs. Oh, no! We only have eight GPIOs available. Well, there is a solution. The ESP8266 has an analog to digital (ADC) pin, and I could use it to read the output status of the switches.
In summary, using a 3-to-8 decoder to do the switching and a multiplexer to read the outputs allows me to use the ESP8266 with eight GPIOs and an ADC pin both for the four position and an eight position switch, without having to redesign the electronics or the firmware programming too much.
Schematics and Circuit Description
I split the antenna switch into two modules, the control module and the connector/relay module.
Figure 2 shows the schematics for the control module and Figure 3 shows the schematics for the connector/relay module. For detailed information on how the circuits work, please see my website
Fig. 2 - Control board schematics
Fig. 3 - Connector and relay board schematics
The final product
I programmed the ESP8266 so it can be configured via a web browser to connect to the WIFI router. Once configured, the module acquires an IP address and then I can communicate via TCP or HTTP protocol. The module responds to the simple commands 1, 2, 3, 4 to switch between the antennas. The command to switch the relays can be sent using a web browser or TCP commands can be sent from a laptop or computer using a simple utility written in Python, for example. If using a mobile device, there are apps that send and receive TCP commands. But better yet, I went ahead and wrote an iPhone app that specifically pairs nicely with the antenna switch. A simple command string ‘status’ returns the status of the outputs as a string of the form: 0,0,1,0 (output 3 is ON)
Figure 4a and Figure 4b shows a screen dump of the app, which is available for free on the Apple app store under AntennaSwitch.
Fig. 4a - AntennaSwitch iPhone app available on the Apple App Store
Fig. 4b - AntennaSwitch iPhone app available on the Apple App Store
Figure 5 shows the WiFi control board, featuring the ESP8266, 74HC238, ULN2803 and 74HC4051 and Figure 6 shows the relay and connector board.
Fig. 5 - Control board
Figure 6 - Relay and connector board
3D printed enclosures
To bring a bit more of the new technologies such as 3D printing, I looked into printing enclosures for the control board and the connector board. Figure 7 to Figure 14 show the results of printing the enclosures. The 3D printing files (STL) are available here
The connector enclosure should be a metal enclosure, but for experimenting, it was interesting to design and print both enclosure boxes. Hopefully soon 3D printers will be able to handle metal printing!
Figure 7 - Relay and connector board enclosure
Figure 8: Relay and connector board enclosure with board
Figure 9: Relay and connector board enclosure with board and lid
Figure 10: Control board enclosure
Figure 11: Control board enclosure with board
Figure 12: Assembled relay and connector board enclosure and control board enclosure
Figure 13: Assembled relay and connector board enclosure and control board enclosure
Figure 14: System at work
Final thoughts and future enhancements
I was impressed with the performance and flexibility that the ESP8266 brings. Its small and extremely powerful, and inexpensive!!! It can be programmed using standard C language or LUA scripts. It can even be programmed using the Arduino environment, but I did not go in that direction. If you are interested in the Internet of Things (IoT), this module will allow you to hit the ground running and implement all sorts of IoT solutions. It is truly awesome.
Next steps could be: Increase the power handling to 1kW or more. The PCB board will have to be upgraded to handle this and I will need to find the right relays, keeping the cost down.
Build a 6x1 or even 8x1 switch. Although 2 of the 4x1 can be easily combined, I think a compact 8x1 would be really nice UHF?
Comments or questions about this article can be sent to: Horacio Bouzas (VA6DTX) - Email: horacio(at)snaptekk.com or va6dtx(at)gmail.com
DIY kits of this project can be ordered here