Turn on a lamp connected to the ESP32 board via WIFI

ESP32 26-11-23
240 0

Tutorial plan

1- The ESP32 board and WIFI

2- The components needed to use a lamp with the ESP32

3- Mounting the ESP32 with a lamp and a relay

4- Programming the ESP32 board with Micropython to turn on a lamp via Wifi

 

 

The ESP32 board and WIFI

The ESP32 is a versatile microcontroller board that is well-known for its built-in Wi-Fi capabilities. Here's an overview of the ESP32 board and its Wi-Fi features:

1- ESP32 Microcontroller:

- The ESP32 is a microcontroller board based on the ESP32 chip, which is developed by Espressif Systems.

- It features a dual-core Xtensa LX6 CPU, which allows for multitasking and processing tasks efficiently.

- The ESP32 includes various built-in peripherals, including GPIO pins, ADCs, DACs, UART, SPI, I2C, and more, making it suitable for a wide range of IoT (Internet of Things) and embedded projects.

2- Wi-Fi Connectivity:

- One of the standout features of the ESP32 is its integrated Wi-Fi capabilities. It supports 2.4 GHz Wi-Fi 802.11 b/g/n, which enables it to connect to wireless networks and the internet.

- The Wi-Fi stack on the ESP32 allows it to act as both a station (client) that can connect to existing Wi-Fi networks and an access point (AP) that can create its own Wi-Fi network for other devices to connect to.

- The ESP32 supports secure Wi-Fi connections using protocols like WPA/WPA2 and even more advanced security features.

3- Applications:

The combination of the ESP32's processing power and built-in Wi-Fi makes it ideal for a wide range of applications, including:

- IoT devices: Sensors and actuators can be connected to the ESP32, which can then transmit data to the cloud or a local server via Wi-Fi.

- Home automation: ESP32 boards can be used to control smart home devices, monitor energy usage, and more.

- Wi-Fi-connected gadgets: You can build Wi-Fi-connected gadgets like weather stations, smart doorbells, and Wi-Fi-controlled robots.

- Internet-connected displays: ESP32 can be used to create web servers, IoT dashboards, and even simple web-based games.

4- Programming:

- The ESP32 can be programmed using various development environments, including the Arduino IDE, PlatformIO, and the Espressif IDF (IoT Development Framework).

- A rich ecosystem of libraries and resources is available for ESP32 development, making it easier to build Wi-Fi-enabled projects.

5- Power Consumption:

The ESP32 is relatively power-efficient, especially when compared to more power-hungry Wi-Fi modules. It offers power-saving features, making it suitable for battery-operated IoT devices.

In summary, the ESP32 board is a popular choice for IoT and embedded projects that require Wi-Fi connectivity. Its combination of a powerful microcontroller, integrated Wi-Fi capabilities, and extensive development support has made it a go-to platform for building a wide range of Wi-Fi-enabled devices and applications.

The components needed to control a lamp by ESP32 card

To control a lamp using the ESP32 board, you will need the following components:

ESP32 Board:

ESP32 card

The ESP32 is a microcontroller board that features built-in WiFi and Bluetooth capabilities. It can be programmed and used to control the lamp.

Relay Module:

You'll need a relay module that is compatible with the ESP32 card and can switch the high-voltage lamp. Ensure it's rated for the voltage and current required for your lamp.

Lamp (220V):

The lamp you want to control, which is rated for 220V. Ensure it's in working condition and safe to use.

Power Supply for the Lamp:

You'll need a power source for the lamp, typically a 220V AC power supply.

Wiring:

Various wires and cables for connecting the components in your circuit.

Breadboard:

Breadboard

A breadboard is a prototyping board that allows you to build circuits without soldering. It provides a convenient way to connect the components together.

Jumper Wires:

Jumper Wires

You'll need jumper wires to make connections between the ESP32 card, lamp, relay, and breadboard. Ensure you have male-to-male jumper wires or a mix of male-to-male and male-to-female wires, depending on your specific needs.

Mounting the ESP32 card with a lamp and a relay

To control a lamp using a ESP32 board, you will need to use a relay module to safely interface the low-voltage ESP32 card with the high-voltage lamp. Here are the step-by-step instructions to set up the ESP32 with a lamp:

1- Safety First: Ensure the lamp is disconnected from any power source before proceeding.

2- Connect the Relay to the ESP32:

- Connect the relay's control pin (S) to pin 23 of ESP32 board.

- Connect the pin (+) of relay to pin 3.3V of ESP32 board.

- Connect the relay's ground pin (GND) to the ESP32's GND.

3- Connect the Lamp and the power supply to the Relay:

- Connect one of the power supply's wires to the relay's common (COM) terminal.

- Connect the phase wire of the the lamp to the normally open (NO) terminal of the relay.

- Connect the neutral wire of the power supply directly to the neutral wire of the lamp.

Mounting the ESP32 card with a lamp and a relay

Mounting the ESP32 card with a lamp and a relay

Programming the ESP32 board with Micropython to turn on a lamp via Wifi

To light a lamp connected to an ESP32 board via Wi-Fi using MicroPython and separate boot.py and main.py scripts, follow these steps:

1. Hardware Setup: Connect the relay to one of the GPIO pins on your ESP32.

2. Flash MicroPython: Ensure you have MicroPython firmware flashed onto your ESP32, and that it has Wi-Fi support enabled.

3. boot.py Script: Create a boot.py script (this script runs on boot and initializes Wi-Fi):

4. main.py Script: Create a main.py script (this script will run after boot.py and control the relay who turn on the lamp):

5. Customize GPIO Pin: Replace relay_pin with the GPIO pin number where your lamp is connected. In the example, it's set to GPIO pin 23.

6. Upload Scripts: Upload both the boot.py and main.py scripts to your ESP32 using a tool like ampy or WebREPL.

7. Power On the ESP32: Power on your ESP32, and it should connect to your Wi-Fi network (as configured in boot.py) and start toggling the relay connected to the specified GPIO pin according to the logic in main.py.

This setup will automatically connect your ESP32 to Wi-Fi on boot and run the lamp control code in main.py. Make sure to replace 'Your_WiFi_SSID' and 'Your_WiFi_Password' with your actual Wi-Fi credentials.

0 comment

Leave a comment

Veuillez noter s'il vous plaît*

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Purpose of this website

Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.

Contact details

Zaouiet Kontech-Jemmel-Monastir-Tunisia

+216 92 886 231

medaliprof@gmail.com

Pictures of the articles

Robotic site created by MedAli-Teacher info