Skip to content

Smart control of garden lighting with ESP8266

    Smart Control of Garden Lighting with ESP8266

    In a world where home automation is becoming increasingly accessible, it is now possible to automate outdoor lighting at low cost using Wi-Fi microcontrollers. This project presents the design of an intelligent system capable of remotely controlling, via a smartphone, four 30 W LED floodlights located at the four corners of a garden of approximately 100 m². The system is controlled via a private Wi-Fi network, without Internet dependency, using a NodeMCU ESP8266 module. Each floodlight, powered by 220 V, is independently controlled by a 10 A relay, ensuring a comfortable safety margin (30 W corresponds to 0.14 A). The integration of 2N3904 transistors between the microcontroller and the relays ensures reliable activation and prevents unintended switching during power-up. This solution combines simplicity, performance, and affordability, with a total hardware cost of under 20 euros.

    Smart garden lighting control with ESP8266 and relay

    What is the NodeMCU ESP8266?

    The NodeMCU ESP8266 by Lolin is a development board based on the ESP8266 microcontroller, specially designed to facilitate the creation of connected IoT (Internet of Things) projects. This board integrates a powerful Wi-Fi module capable of easily connecting to wireless networks, making it a popular choice for home automation applications, telemetry, and many other projects requiring Internet connectivity.

    What makes the NodeMCU unique is its simplified development environment. It originally uses the Lua language but is also compatible with the Arduino IDE, making it accessible to both beginners and experienced developers. Its typical flash memory is 4 MB, and it offers 10 programmable I/O pins, allowing the connection of various sensors, relays, or other electronic components.

    In terms of size, the Lolin NodeMCU is compact, measuring about 50 mm by 25 mm, which facilitates integration into embedded projects or rapid prototypes. It is usually powered with 3.3 V, with an integrated regulator allowing input voltages between 5 V and 12 V without issue. Furthermore, it has low power consumption, averaging around 70 mA in Wi-Fi mode, ideal for battery-powered applications.

    Finally, the NodeMCU ESP8266 community is very active, offering numerous libraries, tutorials, and resources. This board, often priced below 10 euros, is an excellent balance between cost, performance, and ease of use for anyone looking to develop connected devices or automate tasks via Wi-Fi.

    Project Objective

    The main goal of this project is to design a simple yet effective setup allowing control of four 30W LED floodlights independently using a smartphone connected to a local Wi-Fi network. For example, a user can turn on only the entrance floodlight or the one in the garden without affecting the others, optimizing power consumption and increasing flexibility. Remote wireless control via Wi-Fi—a common feature of modules like the NodeMCU ESP8266 (see Espressif Systems, 2020)—simplifies installation by avoiding additional cabling and allows convenient management from any web browser. The intuitive web interface developed offers quick handling, even for non-technical users, which is essential in modern home automation (source: IEEE IoT Journal, 2019). Finally, the system is designed to be secure and stable, using robust Wi-Fi protocols to prevent unauthorized access—an essential aspect of today’s connected systems.

    Smart garden lighting control with ESP8266 and relay

    Components Used

    Lighting project used components

    Wiring Diagram

    Each GPIO output from the ESP8266 is connected to the base of a 2N3904 NPN transistor, which acts as an electronic switch. When a GPIO pin goes high, it biases the transistor, allowing current to flow to the corresponding relay module input. The relay module, powered by 5 V, then activates its contact to control the 220 V AC-powered LED floodlight. This system ensures isolation between the logic part (3.3 V) and the power section (220 V), ensuring safety and reliability. A fifth transistor in the setup plays a key role in preventing relay activation at ESP8266 startup. It temporarily blocks the signal to the control transistors during power-on, thus preventing accidental floodlight activation often caused by GPIO pin instability at boot.

    Smart garden lighting control schematic

    Local Wi-Fi Network Operation

    The ESP8266 is configured in Wi-Fi access point mode with the SSID name “Ecl-jardin”. It thus creates a standalone local network, with no need for a router or Internet connection. Once connected to this network from a smartphone, the user can access an intuitive control interface. Simply open a web browser and enter the local IP address 192.168.4.1, then press “Enter”. The displayed interface allows individual control of each LED floodlight or simultaneous switching of all lights with a single click. This setup offers convenient management from anywhere within the house covered by the ESP8266’s Wi-Fi signal, which can reach about 50 meters in open space.

    Local Wi-Fi network operation

    Optimizing Wi-Fi Signal Range in ESP8266 Project

    The range of this setup using the NodeMCU ESP8266 depends largely on the strength of the Wi-Fi signal, which can be adjusted using the WiFi.setOutputPower() function. By default, this project uses 18 dBm (around 63 mW), allowing for 20–30 meters indoors and up to 100 meters outdoors without obstacles. To improve this range, it is possible to increase this value to the module’s maximum allowed power, 20.5 dBm (about 112 mW), by changing the line to WiFi.setOutputPower(20.5). This slightly extends the range without adding extra hardware. Additional solutions include using a directional external antenna to focus the signal on a specific area or deploying a Wi-Fi repeater like the TP-Link RE305 to relay the signal. For more complex applications or larger areas, a Wi-Fi mesh network or using ESP32 modules with external antennas—or even LoRa modules if a real-time web interface is not required—can be considered.

    Web Interface Control

    Simplified HTML structure of the interface:

    • Individual ON/OFF buttons for each light.
    • Global controls: Turn all lights on or off.
    • Status indicator: Colored circles (yellow = on, gray = off).
    • Safety mode: Global system enable/disable.

    smartphone
    smartphone-2

    Example of browser-sent commands:

    Example of commands

    Summary Table of Used GPIOs

    Used GPIOs

    Power Supply for the Control Circuit

    The control circuit, mainly consisting of the NodeMCU ESP8266 microcontroller and a 4-relay module, has a maximum consumption of about 400 mA at 5 volts when operating at full load (all relays activated). To ensure stable and reliable operation, it is strongly recommended to use a power supply capable of delivering at least 1 amp at 5V. This safety margin helps avoid several critical issues such as voltage drops that could cause unintended microcontroller resets, power supply overheating, and random system malfunctions—especially erratic relay activation. In embedded electronics, an undersized power supply is often a major source of hard-to-diagnose failures. For real-world applications, using a well-regulated 5V/1A power source (e.g., a buck converter or quality 5V USB wall adapter) ensures system stability, even under fluctuating load or temperature conditions.

    Power Consumption and Compatibility

    Each LED floodlight consumes 30 W at a voltage of 220 V, giving a total power of 4 × 30 W = 120 W for the entire setup. The total current drawn is approximately 0.55 A (120 W / 220 V), a very low value compared to the maximum capacity of the relays used, which can each switch up to 10 A, or 2200 W per relay. This provides a comfortable safety margin and allows for the use of more powerful floodlights. In theory, each relay can control a floodlight of up to 2200 W, but to ensure safe usage and extend component lifespan, it is recommended not to exceed 1000 W per channel. This system is therefore perfectly suited for outdoor domestic lighting, even with more powerful floodlights.

    Uploading the Program to the ESP8266: Detailed Steps

    To install the program, you must use the Arduino IDE or any compatible environment (such as PlatformIO). Simply open the source code in the editor, then connect the ESP8266 (NodeMCU) module to your computer using a micro-USB cable. Before uploading, make sure you have selected the correct board type “NodeMCU 1.0 (ESP-12E Module)” from the Tools > Board menu, as well as the correct COM port for your module under Tools > Port. Once these settings are in place, click the Upload button. The code will be compiled and then transferred to the ESP8266, which will automatically start the control system once the upload is complete.

    Code to Upload

    Download link: https://www.zonetronik.com/wp-content/uploads/2025/05/Programme-projet-controle-intelligent-eclairage-de-jardin.zip

    Safe Indoor and Outdoor System Installation

    To install this system in a house or garden, it is essential to follow electrical safety, waterproofing, and heat dissipation guidelines. If you choose to place the control circuit outdoors, the NodeMCU board, its 5V power supply, and the 4-relay module must be enclosed in a waterproof box (at least IP65 rated), with enough internal space to allow good airflow around the components. These parts can emit significant heat, especially the power supply and relays during prolonged operation. It is recommended to use a passively ventilated box (with water-protected vents) or place it in the shade to avoid overheating. The cables connecting the four LED floodlights should be securely fastened, with suitable outdoor sheaths (ICTA or TPC type), ensuring good insulation. For safety, a 30 mA residual current circuit breaker is highly recommended at the power source to protect the system from overcurrent and leakage. Lastly, all electrical connections should be secure, screwed, and housed in waterproof junction boxes to ensure long-term reliability, even in outdoor conditions.

    Key Benefits and Reliability of the Lamp Control Project via ESP8266

    This project offers a major advantage by allowing control of up to 4 lamps of 30W each, for a total power of 120W, via a local Wi-Fi network without requiring an Internet connection. This autonomy ensures enhanced safety and controlled power consumption, with a maximum current of about 0.55 A at 220V. The web interface, accessible from any smartphone or computer connected to the network, enables simple and quick lamp management. Additionally, the system uses relays capable of handling up to 10 A, providing high reliability and a comfortable safety margin. Adaptable and cost-effective, this project is a practical and modular solution for personal home automation.


    Don't lag behind the latest technological trends!
    This is default text for notification bar