Control two lamps connected to the ESP32 board via WIFI

ESP32 28-11-23
268 0

Tutorial plan

1- The ESP32 board and WIFI

2- What is the web server for the ESP32 card ?

3- Role of boot.py and main.py files in ESP32 board

4- The components needed to use two lamps with the ESP32

5- Mounting the ESP32 card with two lamps and two relays

6- Programming the ESP32 board with Micropython to turn on two lamps 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.

What is the web server for the ESP32 card ?

The web server for the ESP32 card refers to a program or functionality within the ESP32 microcontroller that enables it to handle HTTP requests, allowing it to function as an embedded web server.

This means that the ESP32 microcontroller can be programmed to act as a server, receiving requests (such as accessing a web page or sending data) from a web browser or any other HTTP client and responding to these requests accordingly.

By using libraries such as WiFi.h and WebServer.h in the Arduino development environment, you can configure and manage the web server on the ESP32 board. This capability enables the creation of IoT (Internet of Things) applications where the ESP32 board can be controlled or communicate with other devices via a web browser, mobile app, or any other HTTP client.

Role of boot.py and main.py files in ESP32 board

In an ESP32 board running MicroPython, the boot.py> and main.py files serve specific roles in the boot process and the execution of user code. Here's a brief explanation of each file:

1-boot.py:

- Role: The boot.py file is executed at boot time, specifically during the MicroPython boot sequence. It contains code that is executed immediately after the ESP32 board is powered on or reset.

- Typical Usage:

Setting up configuration options like Wi-Fi credentials.

Initializing hardware or peripherals that should be available as soon as the board starts.

Customizing the boot process, such as setting up specific logging or system-wide settings.

When the ESP32 boots, it first executes the boot.py file. After the boot.py execution, the ESP32 then proceeds to execute the main.py file, if it exists.

2- main.py:

- Role: The main.py file contains the main user code or application logic that you want the ESP32 to run. It is executed after the boot.py during the boot process. If the main.py file is present, it will be executed automatically on boot. If the main.py file does not exist, the board will still boot normally.

- Typical Usage:

Implementing your project's functionality, which could include tasks such as reading sensors, controlling actuators, communicating with other devices, or running a web server.

Structuring your MicroPython code and organizing it into functions, classes, and modules.

Implementing your custom application logic.

The components needed to control two lamps by ESP32 card

To control two lamps 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.

Two Relays Modules:

Two relays

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.

Two Lamps (220V):

The two lamps  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 two lamps and two relays

To control two lamps using a ESP32 board, you will need to use two relays modules 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 two lamps :

1- Safety First: Ensure the two lamps are disconnected from any power source before proceeding.

2- Connect the first 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 (-) to the ESP32's GND.

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

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

- Connect the phase wire of the lamp's 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.

4- Connect the second Relay to the ESP32:

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

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

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

5- Connect the second Lamp and the power supply to the Relay:

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

- Connect the phase wire of the power supply 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 two lamps and two relays

Mounting the ESP32 card with two lamps and two relays

Programming the ESP32 board with Micropython to turn on two lamps via Wifi

To light two lamps 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 two relays to two  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 two relays wich should turn on the two lamps):

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

6. 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 two lamps 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