MakerLab
ESP32Sonoff Basic (ESP8266)

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.

Sonoff Basic (ESP8266)

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 / SoCEspressif ESP8266EX
ArchitectureTensilica L106 Diamond 32-bit RISC
Clock speedTypically 80 MHz (can be boosted to 160 MHz)
Flash / Storage4 MB (onboard module, e.g., W25Q32)
RAM / SRAM64 KB SRAM (internal to ESP8266EX)
Operating voltage3.3V (for ESP8266 module)
Digital I/O pinsUp to 17 (exposed on module, fewer on Sonoff PCB)
Analog / ADC1x 10-bit ADC (exposed on module, typically used for voltage sensing)
PWMYes (software-based)
ConnectivityWi-Fi 802.11 b/g/n (2.4 GHz)
USBNone (requires external programmer)
Power input5V DC via Micro-USB or mains voltage (via screw terminals for relay)
DimensionsApprox. 88 x 38 x 23 mm (PCB only)

Pinout & pin functions

PinFunction
3V33.3V power output (from onboard regulator)
GNDGround
GPIO15General purpose input/output, used for boot mode control (low during boot)
GPIO14General purpose input/output
GPIO12General purpose input/output
GPIO13General purpose input/output
GPIO0General purpose input/output, used for boot mode control (low during boot for flashing)
GPIO2General 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
ADC0Analog-to-Digital Converter input (0-3.3V range)
GPIO2 (LED Indicator)Internal pin connected to the onboard status LED
TXUART Transmit (for programming/debugging)
RXUART Receive (for programming/debugging)
SCLI2C Clock (if module supports it, not typically broken out on Sonoff Basic)
SDAI2C Data (if module supports it, not typically broken out on Sonoff Basic)
MISOSPI Master In, Slave Out (if module supports it, not typically broken out on Sonoff Basic)
MOSISPI Master Out, Slave In (if module supports it, not typically broken out on Sonoff Basic)
SCKSPI Serial Clock (if module supports it, not typically broken out on Sonoff Basic)
CSSPI Chip Select (if module supports it, not typically broken out on Sonoff Basic)
Relay InputTerminal for mains input power
Relay OutputTerminal for mains output power to device
NeutralTerminal for mains neutral connection
LiveTerminal 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.

Project ideas

Smart PlugControl any mains-powered device (lamp, fan, coffee maker) remotely via Wi-Fi. Uses the onboard relay and Wi-Fi connectivity. Learns basic IoT principles and relay control.
Automated Plant Watering SystemUse a soil moisture sensor (connected to ADC0) and Wi-Fi to water plants only when needed. Integrates sensors and relay control for a practical home automation project.
DIY Smart Light SwitchReplace a traditional light switch with the Sonoff Basic to enable Wi-Fi control. Involves safely wiring mains voltage and understanding the relay's function.
Home Automation Hub IntegrationIntegrate the Sonoff Basic into platforms like Home Assistant or OpenHAB using MQTT. Learns about network protocols and building a connected home ecosystem.
Garage Door OpenerUse the relay to trigger a garage door opener mechanism. Requires careful wiring and understanding of momentary switch signals, plus robust Wi-Fi control.
Remote Temperature and Humidity MonitorConnect a DHT11/DHT22 sensor to a GPIO pin and transmit readings over Wi-Fi. Teaches sensor interfacing, data transmission, and cloud logging.

Buying tips & gotchas

When purchasing a Sonoff Basic, be aware of numerous clones and variants. Look for genuine ITEAD products. Ensure the ESP8266 module has sufficient flash memory (4MB is standard) for your firmware. The main pitfall is miswiring mains voltage; always prioritize safety. Accessories like a USB-to-TTL serial adapter, jumper wires, and a suitable enclosure are essential. For advanced users, consider modules with more GPIO pins or different relay ratings if the basic model doesn't meet your needs.