DEV Community

El Bruno for Microsoft Azure

Posted on • Originally published at elbruno.com on

6 1

#ESP32CAM – WebServer taking photos 📸 every N seconds #Arduino

Hi !

Still learning with the ESP32 CAM board.

In today’s post the scenario is simple:

  • Init the camera
  • Init the local File System
  • Take a photo every 5 seconds and store it in memory
  • Creates an endpoint named [/photo] to return the last saved photo

As the previous sample, I’ll write this using Visual Studio Code and PlatformIO project, using the AI Thinker ESP-32CAM board.

Demo here is tricky, but hey, a selfie is always a good excuse.

selfie with the esp32 cam

As usual, the full sample code is in the demo repository.

Let’s review some noted from the code:

  • The setup and loop are the key codes for this demo.
  • In the setup, init wifi, fs, and camera
  • As a visual clue, I turn on the flash 1 second after each one
  • In the loop, the camera takes a photo every 5 seconds

void setup()
{
  // Serial port for debugging purposes
  Serial.begin(9600);

  // initialize digital pin ledPin as an output
  pinMode(FLASH_GPIO_NUM, OUTPUT);

  // connect to wifi
  initAndConnectWifi();
  flashOnForNSeconds(1);

  // init fs and camera
  initFS();
  initCamera();
  flashOnForNSeconds(1);

  // init and start server
  server.on("/photo", HTTP_GET, [](AsyncWebServerRequest *request)
            { request->send(SPIFFS, FILE_PHOTO, "image/jpg", false); });
  server.begin();
}

void loop()
{
  capturePhotoSaveSpiffs();
  delay(5000);
}

Enter fullscreen mode Exit fullscreen mode

Next steps will include learning Edge Impulse and Computer Vision in this device !

Full code available in my ESP32 Cam Demo repository.

Happy coding!

Greetings

El Bruno

More posts in my blog ElBruno.com.


Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs