ad space

ESP32-CAM LED Blink Tutorial

The ESP32-CAM is a versatile and powerful microcontroller with built-in Wi-Fi and Bluetooth capabilities, as well as a camera module. One of the fundamental tasks for any microcontroller is controlling LEDs. LED blink is widely used to test the IO pins of microcontroller boards. In the previous tutorials LED blink with ESP32 dev kit and led blink with Arduino Nano we showed how we can test the ESP32 board and Arduino. In this tutorial, we'll guide you through the steps to make an LED blink using the ESP32-CAM, specifically on the D4 pin.

What You Will Need

  • ESP32-CAM module
  • USB to TTL converter (to program the ESP32-CAM)
  • LED
  • 220-ohm resistor
  • Breadboard and jumper wires
  • Arduino IDE installed on your computer

Setting Up the Hardware

The following shows the circuit diagram of connecting LED to the ESP32-CAM module.

 

ESP32-CAM LED Blink

  1. Connect the LED to the ESP32-CAM:

    • Connect the longer leg (anode) of the LED to a 220-ohm resistor.
    • Connect the other end of the resistor to the D4 pin of the ESP32-CAM.
    • Connect the shorter leg (cathode) of the LED to the GND pin of the ESP32-CAM.
  2. Prepare the ESP32-CAM for Programming:

    • Connect the USB to TTL converter to your ESP32-CAM.
    • Connect the TX pin of the converter to U0RXD (GPIO3) of the ESP32-CAM.
    • Connect the RX pin of the converter to U0TXD (GPIO1) of the ESP32-CAM.
    • Connect the 5V and GND pins of the converter to the 5V and GND pins of the ESP32-CAM, respectively.
    • Connect GPIO0 to GND to put the ESP32-CAM into programming mode.

Writing the Code

Open the Arduino IDE and follow these steps:

  1. Configure the Board:

    • Go to Tools > Board and select ESP32 Wrover Module.
    • Go to Tools > Port and select the COM port your USB to TTL converter is connected to.
  2. Write the LED Blink Code:

#define LED_PIN 4

void setup() {
  // Initialize the LED pin as an output
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  // Turn the LED on
  digitalWrite(LED_PIN, HIGH);
  delay(1000); // Wait for 1 second

  // Turn the LED off
  digitalWrite(LED_PIN, LOW);
  delay(1000); // Wait for 1 second
}

Uploading the Code

  1. Upload the Code:

    • Click the upload button in the Arduino IDE to compile and upload the code to your ESP32-CAM.
    • When you see the Connecting... message in the IDE, press the reset button on the ESP32-CAM to start the upload process.
  2. Disconnect GPIO0:

    • After the code is uploaded, disconnect GPIO0 from GND to run the program.

 The following shows circuit diagram to connect the ESP32-CAM with the USB to TTL converter.

esp32-cam programming USB TTL converter


Testing the LED Blink

Once the code is uploaded and GPIO0 is disconnected from GND, the LED connected to D4 should start blinking. It will turn on for one second and then turn off for one second in a continuous loop.

Troubleshooting

  • No Blinking LED:

    • Ensure all connections are correct.
    • Check if the resistor and LED are properly oriented.
    • Ensure the correct COM port and board are selected in the Arduino IDE.
  • Upload Issues:

    • Make sure GPIO0 is connected to GND during the upload.
    • Press the reset button when you see the Connecting... message.

Conclusion

Congratulations! You have successfully created a basic LED blink program using the ESP32-CAM. This simple project is a great starting point for exploring the capabilities of the ESP32-CAM module. From here, you can move on to more advanced projects such as controlling multiple LEDs, ESP32 PWM with example, interfacing with sensors, or utilizing the camera module for image and How to Video Stream with ESP32-CAM?. Happy coding!

Post a Comment

Previous Post Next Post