Etekcity Wireless Socket Hacks

Outlets1

There are a zillion RF remote controlled outlets available but one of the most popular appears to be those from Etekcity.  I was able to pick up, at regular price, a set of five and two remote controls for less than $30 on Amazon.  I wasn’t sure what I was going to do with them but I figured it was a prime opportunity to do some hacking.

One thing to keep in mind is that these are only controllable with the included remote, and not via the internet.  But we will fix that.  Also, they are normally off when plugged in and go back to that state if power is lost.  I don’t know about you, but I have some applications where I want the outlet to be normally on instead.  We will fix that as well.  Just keep in mind that these hacks require some knowledge of electronics and basic soldering skills.

Making Normally On Outlets

Changing one of these outlets from normally off to normally on would seem to be a simple task because they use a pretty standard relay which should have pins for both states.  As it turns out the relay may or may not have the normally on pin, but it is not accessible on the circuit board.  That complicates our task but it’s probably a smart safety move by the manufacturer.  What that means, then, is that we need to find a way to reverse the on/off logic.

Unmodified

Cuts

LED Replaced

There are two pieces to reversing the logic.  The first is to change the polarity of the LED.  The solder pads for the LED are shown in the first picture.  Once the LED is removed, we need to make two cuts to the circuit traces as shown in the second picture.  The right hand cut separates the LED solder pad from ground.  We do that so that after the LED is reversed, we can solder that pad to +5 volts.  The left hand cut separates the base of the relay driver transistor from the 4700 ohm resistor.  That will allow the second logic polarity reversal to be installed.  Double check with an ohmmeter to make sure that the cuts are successful.  In the third picture we have reinstalled the LED with the anode now connected to the cut pad and to +5 volts.  The leads were just long enough on my unit so that I could bend it over to the +5 volt output of the 78L05 voltage regulator.

Transistor Added

The fourth picture shows the method used to reverse the logic for driving the relay.  I used a common 2N3904 NPN transistor (an equivalent would be ok) as an inverter.  The emitter is soldered to ground, the base is soldered to the on-board 4700 ohm resistor, and the collector is soldered to the base of the relay driver transistor.  In order to ensure that the relay driver transistor is normally switched on, I had to add a 4700 ohm resistor from its base to +5 volts.  Now, when the logic output is high, it will turn on the new transistor which will turn off the relay driver transistor.

Remote x-wired

If you want to take an extra step you can cross-wire the appropriate buttons in the remote so that the left button will turn on the modified outlet and the right button turn in off.  Basically you need to cut the circuit traces that go to the switch contacts that are closest to the middle of the board and then add jumper wires as shown in the picture

Internet Control

There are two methods possible for controlling the RF outlets from the Internet.  Both require the use of a cheap module like the ESP8266.  One method would be to wire into one of the remote controls and use a microcontroller to simulate the button presses.  The other less messy method is to use a microcontroller to take the place of the remote control.  That is what is described here.  The microcontroller will receive commands via the ESP8266, translate them into the proper RF bit pattern, and then send that bit pattern to an RF transmitter.  It sounds complicated but the only hard part is figuring out what the proper control codes are for your set of RF outlets.

There are many posts online that use an RF receiver and the audio input to a PC to figure out the codes.  I have the luxury of having a decent oscilloscope so it is easy for me to capture them.  I also have an RF sniffer circuit (detailed in one of my other electronics projects on my website) that allows me to capture RF transmissions using a terminal program on my PC.

Waveform

The frequency for communicating with the RF outlets is 433.92-MHz and the commands are comprised of a long sync bit, 24 data bits, and 1 stop bit.  The data encoding method used is On-Off-Keying (OOK) which means that data bits are differentiated by the on/off times.  There are no requirements in OOK for number of bits or period length.  That’s why there are so many variations out there for different devices.  I have seen that first hand by decoding security sensors and weather sensors.  The waveform looks similar to what is shown in the picture here.

Hardware

PIC WiFi Interface2

The schematic shown here is almost identical to the one I used in the one of the earlier Wi-Fi projects listed on my website.  The main difference is that the final version doesn’t have the USB interface but does have an interface to an RF transmitter module.  The transmitter module I used is labeled FS1000A and transmits at 433.92-MHz.  I have not tried other models of RF transmitters but most should work as long as they have similar characteristics.  The RF module is run from the +5 volt input and readily accepts the 3.3-volt logic level for the serial data bit stream from the PIC.

Some ESP8266 modules have their own 3.3 volt regulator onboard so the input to it would be 5 volts.  I have included a 3.3 volt regulator in my schematic for the PIC and it can also be used for the ESP module if it doesn’t have its own voltage regulator.  This allows the PIC and the ESP to communicate at the same logic levels without the need for converters.

You could simplify the ESP hardware by using the ESP-01 module and the adapter (shown here).  The adapter takes +5 volts and has an onboard 3.3 volt regulator.  If you go this route I also recommend that you buy the USB interface that is specifically made for the ESP-01.  It will make the setup of the ESP-01 much easier.

Software

The software listing is available below.  It is an extension of the software I wrote for a previous Wi-Fi project.  I chose that because I wanted to have the status response from the PIC displayed as simple graphics instead of text.  I also added code to output the single-pin serial bit stream to the RF transmitter.  Like the earlier version, I used HTML commands to draw circles that represent the status of each of the five remote switches.  Red=off, green=on, and white=unknown.  The important thing to remember is that there is no feedback from the remote switches themselves so the software can only maintain the status of the last command sent for each switch.  That means that every time there is a power up of the controller hardware the switch statuses are all unknown.  That’s it for this post.  Check out my other electronics projects at: http://www.boomerrules.com

ESP8266 RF Socket Controller

I2C 4-Digit LED Interface

In an earlier project I detailed an I2C (two-wire) interface to the common 1602 LCD.  Recently I found a cheap 4-digit LED module that uses a pseudo I2C interface.  I don’t have a particular need for it but I went ahead and added one to a parts order I made.  If you know a little about I2C you know that it is a serial interface where the controlling circuit provides the clock and controls the direction of the single data line.  Usually you can hang several I2C modules on the same pair of line (e.g.: clock module and display module) because each module has a unique address.  I said this LED module has a “pseudo I2C” interface because it does not have an address.  That means that it needs to be the only device using the data line.

LED I2C Module

TM1637 Module

The module I have is similar to the one shown here.  It is typically listed as part number TM1637.  You can find a variety of information on the web but I had a hard time finding all of the details I needed.  I also looked at some existing code (Python and C) which can often be a dangerous thing to do.  The one critical thing I determined from the code was that the data bits sent to the LED module need to be LSB first.  That differed from the approach for the other I2C projects I have done.  Another idiosyncrasy that I noted is that the addresses for the digits go from left to right (starting with address C0).  That means that data must be written from most significant digit to least significant digit if using the auto increment addressing mode.  In fixed addressing mode you would just pick the appropriate digit and write directly to it.

I2C Communications

I2C communications are accomplished by using just two wires: one for data (SDA) and one for a clock (SCL).  The data line is defined as being bidirectional so there needs to be a “master” device on the bus to control things.  The clock rate is limited by the slowest device on the bus and controlled by the master device.  Basically it sets a data bit and then toggles the clock line.  At the end of each byte transfer the master reverses the direction of the data line and then clocks in the acknowledgement bit from the slave device.

There are three basic commands for the LED module.  One controls the on/off and brightness of the display, one controls the address of the digit to write, and one controls the addressing mode (fixed or auto increment).  Usually an application will just load all four digits each time so the auto increment mode is normally used and the address set to the first (left-most) digit.

Hardware

LED I2C Interface

The connections to the PIC are pretty simple with only two I/O pins being used.  That leaves four other pins on our little 12F683 for getting sensor data.  This same connection can be used with the 16F688 if we want more I/O pins.  The module already has the required pull up resistors on the SDA and SCL lines.

Software

The software link is listed below.  While it is targeted for the 12F683, it is easily ported to bigger versions of the PIC like the pin compatible 16F688 that I use for a lot of my projects.  Some of the newer PICs also have a hardware I2C interface so most of the related software routines would be greatly reduced or eliminated.

The I2C routines are the same as those I wrote for the LCD project but a lot of the other LCD-specific code was not needed for the LED module.  I added a lookup table that converts single packed ASCII characters to the required LED segments.  I also added a second test routine that shows how you can make non-ASCII displays by turning on the right segments.  The data bit associations for the segments are shown in the header of the software source code.  The eighth bit in the segment bytes is reserved for turning on the colon that resides between digits 2 and 3 on the module.  In my tests it appeared that all four characters had to include a 1 in the eighth bit in order for the colon to light.

I added a line of code to the end of the “i2cwaitack”routine to try and recover if the slave does not acknowledge the data transfer.  If the slave fails to acknowledge a transfer then the software will be reset by enabling the Watch Dog Timer (WDT).  Newer PIC chips have a software reset command that can be used instead.  An alternative for some I2C applications would be to simply make a call to “i2cstop” and then continue where the code left off.  That’s it for this post.  Check out my other electronics projects at boomerrules.com.

I2C LED

Rootin’, Tootin’, Shootin’ Game

When I lived in Orange County, California two of the biggest employers of college kids were Disneyland and Knott’s Berry Farm.  Because I had electronics training from the military I was able to get a job in the Knott’s shooting gallery instead of having to wear a funny costume.  The rifles used high voltage flash tubes with focusing lenses and the targets used photo cells.  The target counter circuits used germanium transistors set up as flip-flops.  The transistors were becoming harder to find so someone had tried replacing them with silicon ones.  Unfortunately, they found out that the fast switching times of the silicon transistors made them much more susceptible to noise.  That meant that a single hit on the target would ripple through the counters and light all of the lamps at once.  The lesson here is that sometimes slow is good.

Recently I was thinking about those days and decided to see if I could design a simple shooting game for my grandkids.  The game detailed here pits two players against each other to see who can get to five hits first.  I also decided to use a cheap red laser diode as the heart of the gun.  You could use laser pointers if you want but the circuit I include for the gun ensures that you get a single shot instead of a steady on beam.

Light Sensor Modules

Light Sensor Module

At first I was going to just use photo transistors for the sensor circuits but then I discovered the light sensor modules shown above.  I bought a pack of 10 for next to nothing from a China supplier.  The modules do use a photo transistor but they run the sensor voltage into an LM393 comparator so it provides a digital output as well as an analog one.  A potentiometer onboard can be adjusted to set the trip level of the comparator.  It also includes a power on LED and an LED that lights when the comparator switches the digital output.  That makes it easier to adjust the proper level.

Target Hardware

Target

The bulk of the hardware consists of 10 LEDs and 10 resistors.  I used standard 5mm bright white LEDs for indicators 1-4 and a slow flashing LED for the 5th indicator.  The switch is normally open momentary contact and is used to reset the game.  The PIC microcontroller is a standard one that I’ve used in other projects.  As you can see in the pictures, I built the LED modules separately in order to make it easier to locate them in a target.

Target Layout

Target Top

Gun Hardware

Laser Gun

The basic hardware and schematic for the laser gun is shown above.  I built mine into plastic toy airsoft guns.  The barrel tube for the pellets is almost the perfect size for the laser diode modules and I was able to fit a battery holder for two AAA batteries in the opening for the magazine.  There are plenty of cheap laser diode modules out there and basically they differ only in the value of the current limiting resistor mounted onboard.  That resistor determines the voltage rating of the laser module.  I use two AAA batteries so I picked 3 volt lasers.  The switch is a single pole, double throw micro switch.  The capacitor is used to force a single burst of light with every pull of the trigger.  In one position of the switch the capacitor charges up and in the other position it discharges through the laser.

 Software

Like all of my PIC projects, the software is written in assembly language.  What makes this project a bit unusual is that the Main routine does nothing because all of the action takes place in the interrupt handler.  The PIC has a feature called interrupt-on-change which, in older PICs, generates interrupts on any positive to negative or negative to positive transition on an I/O pin.  This particular PIC allows the software to set the interrupt source to be either the positive edge, negative edge, or both edges.  The light sensor module will generate both edges on a transition so this feature is quite handy.  In this case, the software waits until the sensor output switches back high (off) before the interrupt is generated.

When a sensor interrupt is received, the software temporarily disables that input and sets a timer.  In effect, the timer acts like a debounce circuit for a switch.  At the 8-MHz clock selected for the PIC and the setup for the timer, the total timeout is about 130ms.  When the timer finishes, it also generates an interrupt.  At that point, the sensor input is re-enabled.  Each sensor input has its own dedicated timer so there is no conflict between players.

Each sensor interrupt will also light one of the LEDs for that player.  Instead of a counter, the software uses a variable that has one bit set.  That bit gets left shifted with each interrupt and is then OR’ed into the output port to light the next LED.  When the last LED is lit, the interrupt handler disables further interrupts and that effectively locks out the other player.  The reset switch is connected to the MCLR input of the PIC and the configuration bits are set to allow that function.  When reset is pressed, the software will reinitialize and clear the LEDs.  That’s it for this post.  Check out my other electronics projects.

Shooting Game SW