Sonoff Basic (ESP8266): Your First Smart Home Device
The Sonoff Basic is an affordable Wi-Fi enabled smart switch that brings IoT capabilities to any appliance, powered by the versatile ESP8266 microcontroller.
The Sonoff Basic, released around 2016, is a foundational device in the maker community for its low cost and Wi-Fi connectivity. It's essentially a small PCB featuring an ESP8266 System-on-Chip (SoC) and a relay, designed to control mains-powered devices remotely. Its primary function is to act as a smart switch, allowing users to turn lights, fans, or other appliances on and off via a smartphone app or a custom-built interface.
At the heart of the Sonoff Basic is the Espressif ESP8266EX chip. This powerful and highly integrated SoC includes a Tensilica L106 Diamond 32-bit RISC microcontroller core, Wi-Fi connectivity (802.11 b/g/n), and a host of peripherals. The ESP8266 was revolutionary for its time, offering Wi-Fi capabilities at a price point that democratized IoT development for hobbyists and professionals alike. The Sonoff Basic leverages this chip's power to provide a robust and feature-rich platform for smart home projects.
Positioned as an entry-level smart home device, the Sonoff Basic is part of a broader ecosystem of Sonoff products, but it stands out as one of the most accessible and hackable. Its popularity stems from its affordability, the widespread availability of the ESP8266, and the vast community support for programming it. This makes it an excellent choice for students, makers, and embedded engineers looking to experiment with IoT, home automation, and custom control systems without a significant financial investment.
The Sonoff Basic is particularly well-suited for makers who want to dive into the world of connected devices. Its simple relay control is intuitive, and the ESP8266 offers enough flexibility for more advanced projects. Whether you're looking to automate a simple lamp, build a custom weather station that reports to the cloud, or integrate it into a larger home automation system like Home Assistant, the Sonoff Basic provides a solid and cost-effective starting point.
Watch
Related video, embedded from YouTube.
Specifications
| Microcontroller / SoC | Espressif ESP8266EX |
| Architecture | Tensilica L106 Diamond 32-bit RISC |
| Clock speed | Typically 80 MHz (can be boosted to 160 MHz) |
| Flash / Storage | 4 MB (onboard module, e.g., W25Q32) |
| RAM / SRAM | 64 KB SRAM (internal to ESP8266EX) |
| Operating voltage | 3.3V (for ESP8266 module) |
| Digital I/O pins | Up to 17 (exposed on module, fewer on Sonoff PCB) |
| Analog / ADC | 1x 10-bit ADC (exposed on module, typically used for voltage sensing) |
| PWM | Yes (software-based) |
| Connectivity | Wi-Fi 802.11 b/g/n (2.4 GHz) |
| USB | None (requires external programmer) |
| Power input | 5V DC via Micro-USB or mains voltage (via screw terminals for relay) |
| Dimensions | Approx. 88 x 38 x 23 mm (PCB only) |
Pinout & pin functions
| Pin | Function |
|---|---|
| 3V3 | 3.3V power output (from onboard regulator) |
| GND | Ground |
| GPIO15 | General purpose input/output, used for boot mode control (low during boot) |
| GPIO14 | General purpose input/output |
| GPIO12 | General purpose input/output |
| GPIO13 | General purpose input/output |
| GPIO0 | General purpose input/output, used for boot mode control (low during boot for flashing) |
| GPIO2 | General purpose input/output, used for boot mode control (high during boot) |
| GPIO2 (Relay Control) | Internal pin connected to the relay control circuit |
| GPIO2 (Button Input) | Internal pin connected to the onboard button |
| ADC0 | Analog-to-Digital Converter input (0-3.3V range) |
| GPIO2 (LED Indicator) | Internal pin connected to the onboard status LED |
| TX | UART Transmit (for programming/debugging) |
| RX | UART Receive (for programming/debugging) |
| SCL | I2C Clock (if module supports it, not typically broken out on Sonoff Basic) |
| SDA | I2C Data (if module supports it, not typically broken out on Sonoff Basic) |
| MISO | SPI Master In, Slave Out (if module supports it, not typically broken out on Sonoff Basic) |
| MOSI | SPI Master Out, Slave In (if module supports it, not typically broken out on Sonoff Basic) |
| SCK | SPI Serial Clock (if module supports it, not typically broken out on Sonoff Basic) |
| CS | SPI Chip Select (if module supports it, not typically broken out on Sonoff Basic) |
| Relay Input | Terminal for mains input power |
| Relay Output | Terminal for mains output power to device |
| Neutral | Terminal for mains neutral connection |
| Live | Terminal for mains live connection |
Wiring & circuit basics
Powering the Sonoff Basic requires careful consideration, especially when dealing with mains voltage. The board can be powered via a 5V DC input, typically through a Micro-USB port or directly to the 5V and GND pins on the PCB. This 5V is then regulated down to 3.3V for the ESP8266 module. When connecting external components, always use the 3.3V and GND pins. Avoid connecting 5V logic directly to the ESP8266's GPIO pins, as this can damage the chip; use level shifters if necessary.
The Sonoff Basic's primary function is controlling a relay, which switches mains voltage (110-240V AC). This is a critical safety point. Always disconnect mains power before wiring the relay terminals. The relay has three terminals: Common (COM), Normally Open (NO), and Normally Closed (NC). For most smart switch applications, you'll connect mains Live to COM and the appliance's Live input to NO, so the relay acts as a switch in the Live line. Ensure all mains connections are secure and insulated.
A simple example circuit is controlling an LED. Connect the anode of an LED to a 3.3V pin (e.g., 3V3) and the cathode to a current-limiting resistor (e.g., 330 ohms). Then, connect the other end of the resistor to a GPIO pin (e.g., GPIO12). When the GPIO pin is HIGH (3.3V), current flows, and the LED lights up. To control the LED with the relay, you would wire the LED circuit in series with the mains power to the relay terminals, effectively switching the power to the LED when the relay activates.
Programming & getting started
The Sonoff Basic is most commonly programmed using the Arduino IDE with the ESP8266 board support package installed. This allows you to write C++ code using the familiar Arduino API. To upload code, you'll typically need an external USB-to-TTL serial adapter (like an FTDI or CH340 based module). Connect the adapter's TX to the Sonoff's RX, RX to TX, GND to GND, and importantly, hold the onboard button (connected to GPIO0) down while powering the board with 5V to enter bootloader mode. Release the button once the upload starts.
Alternatively, you can use MicroPython or CircuitPython for a Python-based development experience, or the Espressif IoT Development Framework (ESP-IDF) for more advanced, native development. PlatformIO, an extension for Visual Studio Code, is also a popular choice, supporting multiple frameworks and providing excellent build and debugging capabilities. For your first program, a simple 'Blink' sketch to toggle the onboard LED or a sketch to control the relay via Wi-Fi would be a great starting point.