+21622886281
ESP32

Connected bulb based on ESP32 controlled by Smartphone via Bluetooth

The ESP32 is a microcontroller that features Bluetooth connectivity. It can be used in a robot to provide wireless communication and control. To use the ESP32 in a robot, you will need to connect it to the robot’s hardware, such as motors, sensors, and other components. This can typically be done using wires. The ESP32 can then be programmed to control the robot’s movement and behavior using Bluetooth commands sent from a separate device, such as a smartphone or computer.

An ESP32 microcontroller can be used to control a light bulb over Bluetooth by using a relay to switch the power to the bulb on and off. The ESP32 can be programmed to listen for Bluetooth commands and use its digital output pin to control the relay.

Here is an example of how you might set up the ESP32 to control a light bulb over Bluetooth:

  1. Connect the light bulb to the relay according to the manufacturer’s instructions.
  2. Connect the relay’s control input to a digital output pin on the ESP32.
  3. Use the ESP32‘s Bluetooth library to set up a Bluetooth connection with another device, such as a smartphone.
  4. Write a program that listens for Bluetooth commands and turns the light bulb on or off by controlling the relay using the ESP32‘s digital output pin.
  5. Upload the program to the ESP32 and test it by sending the appropriate commands from the Bluetooth device to turn the light bulb on or off.

Purpose of this tutorial:

A connected bulb corresponds to a bulb that can be controlled remotely from a smartphone or tablet via the wifi or bluetooth network.

The connected bulb is equipped with an electronic card programmed to communicate with a smartphone or tablet.

The objective of this tutorial is to light a lamp connected to the ESP32 board by a Smartphone via bluetooth.

This is why we will create two programs: a mobile application with App Inventor for the smartphone and a micropython program for the ESP32 card.

Necessary components

ESP32 card

An ESP32 card is a physical device that includes an ESP32 microcontroller and associated components, such as memory and input/output (I/O) pins. These cards are typically designed to be easily integrated into a project or prototype, and can be plugged into a breadboard or other prototyping platform.

ESP32 cards are often used in Internet of Things (IoT) projects, as the ESP32 microcontroller has built-in WiFi and Bluetooth capabilities, making it well suited for connecting to the internet and communicating with other devices wirelessly. These cards may also include additional features such as sensors, OLED displays, or other components that can be used in a project.

Relay

Relay is an electromechanical device that is used to switch electrical circuits on and off. It consists of a coil of wire and a movable armature that is controlled by the coil. When an electrical current is applied to the coil, it creates a magnetic field that causes the armature to move and make or break a connection in the electrical circuit.

In a robot, a relay can be used to control high-power devices such as motors or lights. For example, a relay could be used to turn a motor on or off, or to switch a light on or off. The relay can be controlled by a microcontroller or other electronic device, which sends a signal to the relay‘s coil to activate it.

an ordinary 220V lamp

A 220V lamp is a type of light bulb that operates at a voltage of 220 volts. The voltage rating of a lamp is an important factor to consider when choosing a light bulb for a particular application. It determines the amount of electrical current that the lamp can safely handle and the type of electrical circuit that it can be used in. For example, a 220V lamp would not be suitable for use in a 120V household electrical circuit, as it would require a higher voltage to operate properly. In order to use a 220V lamp, you would need to have a circuit that is capable of supplying that amount of voltage.

test plate

A test plate is a type of device used in robotics to test the functionality and performance of various components or systems. It is typically a physical platform or structure that is designed to hold and support various test items or devices, such as sensors, actuators, motors, or other types of mechanical or electrical components. Test plates can be used to simulate different environments or conditions, such as temperature, humidity, vibration, or other factors, in order to evaluate the performance of the components or systems being tested. They can also be used to perform a variety of diagnostic or diagnostic tests, such as stress testing, endurance testing, or other types of evaluations.

connecting wires

Wires are used to transmit electrical signals and power to various components such as motors, sensors, and microcontrollers. It’s important to properly route and secure the wires to prevent tangles and damage. There are several methods for doing this, including using cable ties, clamps, and wire looms. It’s also a good idea to use different colors or labeling to identify the different wires and their functions. When connecting wires in a robot, it’s important to follow proper safety procedures, such as using the correct wire stripper and connectors, and wearing protective equipment such as gloves and safety glasses.

Assembly

To carry out the assembly it is necessary to connect:

  • the (-) pin of the relay to the GND pin of the ESP32 board

  • the (+) pin of the relay to the 3.3V pin of the ESP32 board

  • the (S) pin of the relay to the GPIO23 pin of the ESP32 board

  • the (ON) pin of the relay to one of the lamp terminals

  • the (COM) pin of the relay to the electrical source

  • the other terminal of the lamp to the electrical source

Micropython program:

Here is the micropython program that allows you to connect the ESP32 card to the smartphone and remotely control a light bulb:

If the ESP32 board receives the value ‘1’ from the Smartphone, it lights the lamp.

If the ESP32 board receives the value ‘0’ from the Smartphone, it turns off the lamp.

 

You have to import these libraries :ble_uart_peripheral.py and ble_advertising.py.

– you must use the following firmware : esp32-20210902-v1.17.bin

Creating the application with AppInventor:

We will create a mobile application named ‘esp32_allumer_lampe’ with App Inventor which allows you to connect the smartphone to the ESP32 board and remotely turn on an ordinary lamp.

We therefore suggest that you create the design of the application, with the following visual : 

Programming with App Inventor

To program the application, App Inventor offers us to use the Blocks space which allows you to create a program in the form of a block diagram. Very easy to use but requires some programming logic.

Here is the program of the application made in the Blocks space of the App Inventor:

Remark:

After installing the mobile application on your Smartphone, you must follow these steps to connect to the ESP32 card you must:

  1. Click on the ‘scan’ button

  2. After finding the Micro:bit card, Click on the ‘Stop’ button

  3. Press the name of the ESP32 board

  4. Finally click on the ‘connect’ button

Download project Download Application




0 commentaire


Leave a comment

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

Scroll to Top