Schematic and PCB Design
The kit is designed to be noninvasively mounted over top of an existing household light switch and can be installed with only a screw driver. An Arduino will plug into the PCB along the bottom using only the Analog and power header row. This allows for a very small PCB that also functions as the backbone of the mechanical components of the switch.
Thimble WiFi Light Switch Schematic
Serial Data
The circuit is fairly simple and uses only five of the Arduino's Analog data pins. Two servos can be are driven from pins A1 and A2 respectively, and the RX/TX lines for the ESP are on pins A2/A3.
- An Adruino's serial pins are accessible via digital pins 0 and 1, but using the SoftwareSerial library any pin on an Arduino can be used as an emulated serial pin. This is what allows the Arduino to communicate with the ESP using Serial data, but on pins A2 and A3.
Voltage Regulator
The LD1117 is a 3.3v regulator which can supply current up to 800mA. The three capacitors around it are what is recommended by the datasheet and serve to smooth the power input and output to a steady 3.3v. This is referred to as VCC in the schematic whereas the source voltage from the Arduino is labeled as +5v.
- The reason that the Arduino's 3.3v supply can't be used is because when transmitting the ESP will need up to 170mA of current; most Arduinos have 3.3v regulators that can only supply a maximum of 100mA.
- The larger package version (TO-200) of the LD1117 was used, even though it is somewhat overrated for this application, to avoid confusion between it and the two MOSFETS used for level shifting. Since nearly all TO-92 packages look identical, we figured that having all three parts look identical would only lead to mistakes when assembling the PCB.
Level Shifting
The ESP is a 3.3v device and therefore requires 3.3v serial data; the Arduino Uno can only send serial data at 5v. Connecting the two directly would eventually damage the ESP, so two 2N7000 MOSFETS were used. They were chosen because of their fast switching rate and ability to provide 400mA of current. They are the same model as the surface mount (SOT-23) level shifting MOSFETS found on the WiFi Robot kit.
- The 10kΩ pull up resistors (R3, R5) on the Arduino side pull up the line to 5v and limit the current when the Arduino takes the pin low.
- The resistor array (all 10KΩ) was used to pull up the ESP side of the circuit to 3.3v and limit the current when the ESP took the line low
Resistor Pack
The 10kΩ resistor pack was used manly to show people one example of how combined components can simplify a circuit. In this case one connection to VCC is made and then the three pull up resistors only need one external connection to the circuit.
ESP Pinout
The Light Switch kit contains holes for soldering in a 6 pin female header to breakout the ESP. This is especially useful for flashing the ESP with new firmware. It also has GPIO 0 and 2 available for use if desired.
Pinout of the ESP8266
Reset
The reset button functions as a reset switch for the Arduino and ESP. the 1n138 diode was chosen as a general purpose diode which can protect the ESP reset line from current spikes when pushing the button.
Large Push Button
The 12mm push button is used as a fallback toggle button for the light switch state. It can be pushed at any time to toggle the lights if for some reason the ESP stops working. It can also be repurposed to trigger more complex states if the user desires.
Servos
The PCB features connections for two servos, this is in the case where someone wishes to use their kit to control a double switch plate. Standard 9g servos were used and mount into the PCB because they are fairly inexpensive but are still powerful enough to toggle switches.
Flash New ESP firmware
You don't have to do this to use your ESP, it comes flashed with the correct firmware to use with your Light Switch Kit.
This file includes the necessary programs, binaries, and instructions in order to flash new firmware to the ESP 8266.
Wire Connections
The ESP is "not" 5v tolerant, but many people have been treating it as though it is and have been fine. This is my warning that using a 5v programmer can damage it so be careful!
- Before connecting your FTDI chip to your computer, wire it to the ESP like so:
- FDTI -> ESP
- 3.3v -> VCC
- 3.3v -> CH_PD
- GND -> GND
- GND -> GPIO0 (through a resistor to limit current)
- TX -> RX
- RX -> TX
- When the ESP is powered on while GPIO0 is tied to ground it will start in flash mode and allow you to program it.
Program Settings
- Open ESPFlashDownloadTool_v3.3.4.exe from the /FLASH_DOWNLOAD_TOOLS_V3.3.4_Win/ folder
- Select the COM port of your FTDI chip; in this example COM5
- Set the baud rate to 115200 (this is only the baud rate of the programming, and can be different than your ESP's configured rate if you've previously set it lower)
- Make sure the SpiAutoSet this will allow the programmer to read your ESP for the correct flash, clock, and device id and set the programming settings accordingly.
- Leave all the Download Path Config boxes unchecked and empty.
- Click start in the bottom right and you should see the DETECTED INFO box populate with your ESP's information as well as the MAC address in the bottom window.
- This information is also seen in the terminal window that opens with the program.
Selecting The binary
- For an ESP matching the settings shown in the settings image, we have already created a combined Binary .bin to be used.
- Click the ... to the right of the first box at the top of the program and select the CombinedFiles.bin file from the same folder this readme is in.
- Enter the offset of 0x00000 (that is 0x with five zeros after it)
- Click the checkbox on the left and you should see both boxes on that line turn green. If so that means you are all set.
- If not, then you may have not properly selected the .bin file or it has been moved to a different location since you selected it.
- With you ESP and FTDI chip still powered on and connected from the steps above, click the START button and you should see the progress shown in the terminal window.
- Once the progress reaches 100% your ESP is now programmed.
- The last thing to do is test and set the baud rate of your ESP to work with an Arduino. To verify you can use the ESP_AT_Test.ino to test the AT commands with your ESP.
- Run the sketch and with your serial monitor set to 115200 baud send this AT command:
AT+UART_DEF=9600,8,1,0,0
- Run the sketch and with your serial monitor set to 115200 baud send this AT command:
Selecting Custom Binaries or Updating to a Newer Version
- Included in the \bin folder is a set of binaries for various specifications of ESP8266s. This can be downloaded from the Espressif site by searching ESP8266 Firmware SDK online.
- To program the ESP with a different or newer set of firmware than what is pre-built here make sure you use the following files and offsets:
File | Offset |
---|---|
\bin\boot_v.16.bin | 0x00000 |
\bin\at\512+512\user1.1024.new.2.bin | 0x01000 |
\bin\esp_init_data_default.bin | 0x3fc000 |
\bin\blank.bin | 0x7e000 |
\bin\blank.bin | 0x3fe000 |
(the 512+512 or 1024+1024 folders correspond to your ESP's Flash sizes)
- With these files selected as in the settings.png image, clicking the START button will program your ESP.
- You can also use the CombineBin button to generate a single bin file using the files and offsets above. That is how we made the CombinedFiles.bin from earlier.
Troubleshooting
- Make sure your TX/RX lines are correct, some FTDI programmers label them as the device sees is and therefore should be connected TX->TX and RX->RX
- If the programmer is not recognizing your ESP make sure that GPIO0 is connected to ground BEFORE you power it on.
- Most times (if it's wired correctly) unplugging the whole setup from your computer's USB port and plugging it back in is enough to reset the ESP back into Flashing mode.
- The default baud rate for an ESP is 115200, which can cause issues for Arduino ESP libraries:
- Run this AT command to set your ESP's baud rate to 9600:
AT+UART_DEF=9600,8,1,0,0
- Run this AT command to set your ESP's baud rate to 9600: