+21622886281
DC Motor ESP32

Control a fan using the ESP32 card

An ESP32 microcontroller can be used to control a fan by sending a signal to a relay or a transistor, which can then switch the power on and off to the fan. The ESP32 can be programmed to control the fan based on temperature or humidity readings from a sensor such as a thermistor, DHT11, or DS18B20.

To control a fan with an ESP32, you will need to connect the ESP32 to a relay or a transistor, which in turn will be connected to the fan. The relay or transistor can be connected to a digital pin on the ESP32, which can be programmed to send a signal to the relay or transistor, turning the fan on or off.

Additionally, the ESP32 can be connected to other devices such as a thermostat, a touch screen, or a mobile application to provide a user interface to control the fan. The ESP32 can also be connected to a Wi-Fi network to send and receive data, or to communicate with other devices using various protocols such as HTTP, MQTT, or Bluetooth.

Purpose of this tutorial:

In this tutorial we will control a fan by the ESP32 card:

1- When the push button is pressed, the fan turns

2- When the push button is released, the fan stops.

Necessary components

ESP32

The ESP32 is a low-cost, low-power microcontroller with built-in Wi-Fi and Bluetooth capabilities. It is a popular choice for IoT projects and is commonly used for a variety of applications such as home automation, wireless control, and sensor data logging. The ESP32 features a dual-core processor, a rich set of peripherals, and support for a wide range of protocols. It can be programmed using the Arduino IDE and various other programming languages such as C, C++, and MicroPython.

Additionally, the ESP32 has a wide range of features including:

  • A high-performance processor with a clock speed of up to 240 MHz
  • Support for various types of wireless connectivity such as Wi-Fi, Bluetooth, and Bluetooth Low Energy (BLE)
  • Multiple communication interfaces such as I2C, SPI, UART, and I2S
  • A large number of GPIO pins to connect to external devices and sensors
  • A built-in security module for secure communication

The ESP32 is often used in projects where a low-cost, low-power device with Wi-Fi and Bluetooth capabilities is needed, and it is commonly used with other sensors and devices to build IoT projects, home automation systems, wireless control systems, and data logging systems.

5V fan

A 5V fan is a type of cooling fan that operates at 5 volts DC, it is commonly used in computers, electronics, and other devices that generate heat. These fans are designed to remove heat from electronic components, thus helping to keep them cool and functioning properly.

5V fans can come in different sizes, shapes, and designs, depending on their intended application. They can have different airflow rates, noise levels, and life expectancies. They typically are connected to the power source using a 3-pin or a 4-pin connector, the latter can also include a tachometer signal wire, to provide speed feedback to the controlling device.

5V fans are typically controlled using a PWM (pulse-width modulation) signal, which allows to control the speed of the fan rather than just turning it on and off. This feature can help to reduce noise and improve energy efficiency.

When using a 5V fan, it’s important to ensure that the fan is properly connected and powered, that it is compatible with the device or application it will be used in, and that the system is compliant with local laws and regulations. Additionally, it’s important to ensure that the system is properly maintained to ensure proper operation and to prevent breakdowns. It’s also important to consider the environmental impact of the cooling system and the energy efficiency.

Relay

A relay is an electrically operated switch that can be used to control a 5V fan in combination with an ESP32 microcontroller. A relay allows the ESP32 to control a device that operates at a different voltage or current level than the ESP32.

A relay typically has a coil that is energized by an electric current, and a set of normally open or normally closed contacts. When the coil is energized, it creates a magnetic field that causes the contacts to move, either opening or closing a circuit.

To control a 5V fan with a relay and an ESP32, the relay‘s coil can be connected to a digital pin on the ESP32 and the fan can be connected to the normally open or normally closed contacts of the relay. The ESP32 can be programmed to send a signal to the relay‘s coil, causing the contacts to move and turning the fan on or off.

Pushbutton

A pushbutton, also known as a switch or button, is a type of input device that is used to activate a circuit or signal. Pushbuttons are typically used to control electronic devices or to provide input to a computer or microcontroller.

Pushbuttons typically consist of a button that can be pressed, and a mechanism that activates a switch when the button is pressed. The switch can be a simple mechanical contact, or it can be an electronic switch such as a transistor or a microcontroller pin.

4 batteries of 1.5V

1.5V batteries are primary batteries that produce a nominal voltage of 1.5 volts when fully charged. These batteries are commonly used in small electronic devices such as remote controls, flashlights, and portable radios.

Connecting wires

Connecting wires refers to the process of physically connecting wires or cables to a device or circuit in order to establish an electrical connection. This can be done by using various connectors such as plugs, sockets, or terminal blocks. The wires are typically color-coded to indicate their function, such as red for power, black for ground, and yellow for signals.

Test plate 

A test plate is a type of circuit board that is used to test electronic components. It typically consists of a flat board made of a non-conductive material, such as plastic or fiberglass, with a number of holes or pads that are used to connect electronic components. The test plate allows you to connect electronic components and test them easily.

Mounting

As for the assembly, we can connect

  For relay:

  • pin S to pin D21 of the ESP32 board

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

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

  • the ON pin to the (+) terminal of the 4 batteries

For fan:

  • the first terminal to the COM pin of the relay

  • the second terminal to the GND terminal of the ESP32 board

For the push button:

  • the first D23 pin terminal of the ESP32 board

  • the second terminal to the GND terminal of the ESP32 board

Micropython program

Here is the program that allows you to control a fan by the ESP32 card




0 commentaire


Leave a comment

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

Scroll to Top