Motor control with ESP32-CAM module

In this tutorial, we will explore how to control a DC motor using the ESP32-CAM module. The DC motor is connected via a 5V relay, and the relay is controlled using a 2N2222 transistor and a 1kΩ resistor connected to GPIO16 of the ESP32-CAM. This project is a simple yet effective way to integrate motor control into your ESP32-CAM projects.

Components Needed

  • ESP32-CAM module
  • DC motor
  • 5V relay
  • 2N2222 NPN transistor
  • 1kΩ resistor
  • Breadboard and connecting wires

Circuit Diagram

The circuit setup is straightforward:

  1. Connect the DC motor to the 5V relay.
  2. Connect the relay control pin to the collector of the 2N2222 transistor.
  3. Connect the emitter of the transistor to the ground.
  4. Connect the base of the transistor to GPIO16 of the ESP32-CAM through a 1kΩ resistor.

See the circuit diagram of connecting a dc motor with esp32-cam module, relay and transistor.

Motor control with ESP32-CAM module

 

Code for Motor Control

Here is the Arduino code to control the motor:

const int motorControlPin = 16;

void setup(){
    pinMode(motorControlPin, OUTPUT);
}

void loop(){
    digitalWrite(motorControlPin, HIGH);
    delay(1000);
    digitalWrite(motorControlPin, LOW);
    delay(1000);
}

How It Works

The ESP32-CAM module controls the relay via GPIO16. When GPIO16 is set HIGH, the relay is activated, powering the DC motor. When GPIO16 is LOW, the relay is deactivated, and the motor stops. The code toggles the motor state every second, demonstrating a simple on/off control mechanism.

Further Reading

For more detailed tutorials on related topics, you can check out these posts on my blog:

These resources will provide you with more insights into motor control and other Arduino projects.

Conclusion

Controlling a DC motor with an ESP32-CAM module is simple and efficient. By using a relay and a transistor, you can easily integrate motor control into your ESP32-CAM projects. Whether you are building a surveillance system with the ESP32-CAM or any other project, adding motor control can significantly enhance its capabilities.

 

Post a Comment

Previous Post Next Post