A Remote Controlled WiFi HF/VHF Antenna Switch

I started playing with electronics back when I was 10 years old in Buenos Aires, Argentina, where I grew up. I got my first ham radio operator license when I was 16 years old and I was very active in the ham club and on the air, tinkering with everything I could get my hands on. It was then when I built my first vacuum tube transmitter and refurbished and old receiver (also vacuum tubes) that somebody from the club was throwing away. To top it up, I built my own oscilloscope from scratch using a 2AP1 RCA cathode ray tube. My interest for science and electronics only grew from there on and I ended studying physics but always continue to tinker with electronics, whenever I could. I think this is a pretty classic story for many people in the ham radio hobby.

I’ve moved a lot around the world for work (oil and gas) so my time and dedication dedication to ham radio pretty much faded away for a while. But it came back! Just a few years ago I got my ham radio operator license in Houston, Texas, KG5DTX, and started to get active on HF, mostly on digital modes. I recently moved to Canada and got a Canadian license, VA6DTX, which is the one I exclusively use now.

I am very interested in antennas and I have been doing some light research and experimenting with dipoles, verticals, loops, magnetic loops, yagis. I don’t have a lot of space in the backyard but managed to cram a few of them and most importantly, I have managed to keep my wife somewhat calm, in spite of all the questions she has about what the heck am I doing.

I have been comparing responses of the various antennas for different modes and different atmospheric conditions, power, orientation, etc (this will be the subject of a future article). Switching antennas has been a top priority, and therefore I realized that I needed a remote switch. If I could use the computer or a mobile device to control the switch, that would be a plus. The idea of a WiFi controlled one came up and started to grow in my head. I could switch it with a browser command, iPhone, iPad, or even a script or from another location outside of the shack. I am currently mostly using a FlexRadio 6500 so I can operate from somewhere else in the house, either via the remote features of the 6500 or via something like TeamViewer. If I went with the classic remote antenna switches, I would have to physically go back to the shack and change the switch. With a WiFi switch, I can do it from anywhere.

I checked the prices of remote switches that can be controlled via the internet and they run for 100s (many) of dollars. I did not want to spend 400-500 dollars on a switch. So, lets design one then.

What’s next? I came up with an idea. Get a RaspberryPi and add a relay board and then I have my WIFI wireless relay control. Add some female SO-239s and we have a WIFI Antenna Switch. Well, at least two problems with this, first it is really clunky connecting all those coaxial cables to the relays and there would be a lot of signal loss (and good luck tuning that), its bulky and pretty difficult to assemble in one unit and that would not work properly; second, it was more expensive than I expected, even DIY it was around 100 dollars. I built it anyway and, well, it worked for a while. But I was not happy so I looked around and came up with a better idea (or so I thought!). I found the ESP8266, a WIFI Microcontroler Unit which is small, cheap, I mean a-few-dollars-cheap and fully programmable. Combining this module with a standard relay switch design, I thought I had a solution for WAY under 100.00 dollars integrated all in one or two PCB boards, suitable for mounting on a proper box. Lets look at the design.

The ESP8266, a little wonder

The ESP8266 is a very small WIFI enabled microcontroller. 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.

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 at http://freeware.the-meiers.org/ 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 on http://www.horaciobouzas.com

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.

Detailed 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. Lets go over the circuits in more detail.

Control board
The control board can be subdivided into five sections:

Power supply and regulator
The ESP8266 needs 3.3 Volts, so I used an LM1117 to bring the voltage from 5 Volts to 3.3
C1 and C2 are 10 uf tantalum capacitors used to stabilize the input and output voltages.
R8 is PTC Resettable Fuse and it is used to protect for overcurrent or short circuit.
D1 is a Schoktty diode used to protect for reverse voltage.
LED1 is a power indicator light and R5 is a 680 Ohms current limiting resistor.
A mini USB connector was added so I can use a standard cable and connect to a computer USB or a wall power supply.

WiFi and Microcontroller (MCU)
This is the main controller and WiFi transmitter and receiver. All the logic happens here. The logic drives the GPIOs and the GPIOs control the functions of the 4-to-1 and 3-to-8 multiplexers.
GPIO0 and GPIO2 are used to control the 3-to-8 multiplexer and generate the logic (see table above) to control the relays.
LED10 indicates when a connection to the router has been successful and an IP address has been obtained. R4 is a 680 Ohms resistor to limit the current to the LED.
The push button is used to reset the MCU.
The dip switch is used to program and flash the MCU. Normally this switch is OFF.
C9, C10 and C11 are transient filter capacitors to remove noise from the power supply and feed a stable 3.3 volts to the MCU.
GPIO12 and GPIO13 provide the logic to switch the 4-to-1 multiplexer in order to read the status of the outputs.
GPIO14 enables/disables the reading of the outputs.
GPIO4 reads the status of the outputs.
TX and RX are used to program the MCU via a USB to serial adapter.

3-to-8 multiplexer 74HC238
This multiplexer is used to implement the logic to switch the relays as per the table above. I am only using two of the inputs, pins 1 and 2. The third input is tied to ground, so it implements a count from 1 to 4 instead of 1 to 8, hence I used only four of the eight outputs (pins 15, 14, 13 and 12).
The four outputs IN1, IN2, IN3 and IN4 are then fed into the Darlington driver.

Relay driver ULN2803
Since the 74HC238 is unable to drive the indicator LEDs and the relays, I needed to add a driver that can handle higher loads. The ULN2803 is a workhorse for this.
The four outputs from the 74HC238 are fed into the ULN2803 inputs 1 to 4, and then mirrored on 5 to 8 so we can drive the relays and LEDs on separate lines; this is not necessary but I chose to do it that way for safety.
R1, R2, R3 and R6 are 680 Ohms current limiter resistors to protect the LEDs.
Outputs 1 to 4 of the ULN2803 are fed to the relays via an eight position wire-to-board screw terminal. This terminal also gives access to the TX and RX signals and exposes ground and +5 Volts (could be in or out).
Outputs 5 to 8 of the ULN2803 are fed into the 4-to-1 multiplexer to read the output state.

4-to-1 multiplexer 74HC4052
This multiplexer uses logic generated by the MCU to scan the four relay outputs and send the value sequentially to a GPIO in the MCU.
Lets see how it works. GPIO12 and GPIO13 from the MCU connect to inputs A and B of the multiplexer. According to the arrangement of high and low of A and B and INH low, output X connects directly to input X0, X1, X2 or X3, then the MCU reads the value on GPIO4 and computes the output state. Quite simple.
Y0 to Y3 and Y are not used.

Connector/Relay board

The schematics are shown on Figure 3.
The connector/relay board schematics show the eight pin terminal carrying the signals to activate the relays and a common +5VDC line (+5VDC coming from the control board). The common line is positive because the ULN2803 switches ground on the outputs.
Varistors are used to protect for over voltage.
The UHF female panel mount connectors SO-239 are connected to the relays with a solid wire and not through PCB traces, that’s the reason why they are detached from the rest of the circuit.

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 5 shows the WiFi control board, featuring the ESP8266, 74HC238, ULN2803 and 74HC4051 and Figure 6 shows the relay and connector board.
Figure 4a and Figure 4b shows a screen dump of the app, which is available for free on the Apple app store under AntennaSwitch.

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 at http://www.horaciobouzas.com
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!

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 6×1 or even 8×1 switch. Although 2 of the 4×1 can be easily combined, I think a compact 8×1 would be really nice
UHF?

BOM:

ESP8266 ESP-12: https://www.tindie.com/products/hbouzas/esp32-module-32-bit-bluetooth-42-wifi-new-/ http://www.ebay.com/itm/ESP8266-ESP-12E-Wireless-Remote-Serial-WIFI-Module-Transceiver-Board-Module-/181915771923?hash=item2a5b066413:g:oDMAAOSwARZXmaht
74HC4052: DigiKey part 1727-2808-1-ND
74HC238: DigiKey part 296-25983-5-ND
ULN2803: DigiKey part 497-2356-5-ND
LM1117: DigiKey part 296-41282-1-ND
C1 and C2: 10uf tantalum capacitor, DigiKey part 478-9999-1-ND, 1206 SMD
C9: 1uf ceramic capacitor, 0603 SMD
C10: .1uf ceramic capacitor, 0603 SMD
C11: .01uf ceramic capacitor, 0603 SMD
LED1, LED10, LED14, LED15, LED16, LED17: LED DigiKey part 160-1457-1-ND, 1206 SMD
R1, R2, R3, R4, R5, R6: 680 ohm resistor, 0603 SMD
8 position terminals: DigiKey part ED10566-ND
Push button tactile switch: DigiKey part CKN9112CT-ND
Dip switch: DigiKey part 732-3831-5-ND
SO-239 RF Female Connector: DigiKey part ARF1005-ND
Relays: DigiKey part PB2032-ND
Varistors: DigiKey part MOV-14D152K-ND

DIY kits of this project can be ordered at http://www.wifiantennaswitch.com

Figures:

About hbouzas

Born in Buenos Aires, Argentina. Studied Physics at the University of Buenos Aires. Joined Schlumberger in February 1985 in Houston, Texas, and worked in several technical and managerial positions until 2000. From 2000 until 2008 held several management positions in Abingdon, UK; Calgary, Alberta and London, UK. Worked in the areas of Geophysical Exploration, Geological Modeling, Structural Modeling, Reservoir Modeling and Petroleum Economics and holds several patents. He is currently the Norway Technology Center Manager for Schlumberger Information Solutions and is based in Oslo and Stavanger. Main interest are software, technology, innovation, 3D visualization, design, human computer interaction, energy, environment.
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a comment