Jump toUpdate content
Building a Connected IoT Photobooth
The ESP32 is a low-cost, low-power system-on-a-chip microcontroller with integrated WiFi and dual-mode Bluetooth. A Tensilica Xtensa LX6 microprocessor provides the computing power of the ESP32. Its small footprint and low power requirements make it ideal for Internet of Things (IoT) applications.
In this tutorial, we use the camera module available for the ESP32 to build an IoT Photobooth. It allows us to take photos, publish them on a
SMILE topic using IoT Hub and store our photos in an Object Storage bucket.
- The ESP32-CAM module
- An OV2640 camera module
- An optional antenna with connectors (Note: ESP32 provides an on-board antenna, but an external antenna can improve WiFi coverage.)
Make sure you connect the camera module to the ESP32 module before continuing with this tutorial.
Launch the Arduino IDE on your local computer.
Open the Arduino preferences by clicking on Arduino > Preferences
Add the ESP32 board by adding the following board manager URL to the IDE:
https://dl.espressif.com/dl/package_esp32_index.json. Confirm by clicking OK:
Open the Board Manager by clicking on Tools > Board: ”…” (the board name may differ on your computer) > Boards Manager:
Type esp32 in the search bar to locate the package including the official Espressif boards. Click Install to download and install them. In this tutorial, we use Version 1.0.5.
Select the ESP32-CAM by clicking on Tools > Board: ”…” > ESP32 Arduino > AI Thinker ESP32-CAM:
Go to the IoT Hub section in your Scaleway console. Click Create a Hub to launch the Hub creation wizard:
Choose the Free SHARED Plan and enter your Hub’s details:
Click Create and add a device to deploy your Hub in a few seconds.
In this tutorial, we add two distinct devices: The camera itself, our ESP32-CAM hardware, and a software called “MQTT Explorer”, which we use to trigger the camera and to view the payloads that are going through our Hub.
Enter a name for the first device, in our case,
camera. For this tutorial, we allow insecure connections to make it easier. In a production environment you should always deny insecure connections for security reasons. Click Add a Device to your Hub to add the device:
Click Add a new Device and repeat the steps above for the second device, called
Click Close once the device is added. Your Hub should now have two devices:
MQTT Explorer is a lightweight MQTT client, available for Windows, macOS, and most Linux distributions. It provides a structured overview of your MQTT topics and simplifies working with devices/services on your broker. If you have not installed MQTT-Explorer yet, download it from the official website.
Launch MQTT-Explorer on your local computer and fill in the following connection information:
The Device ID can be found on the overview tab when clicking on a device (see below).
Create an Object Storage bucket to store your pictures in. Click on Object Storage in the side-menu, then Create a Bucket:
Name your bucket and chose a region in which your data will be stored:
Click on Create a bucket to complete the bucket-creation process.
IoT Routes allow your IoT Hub to forward messages to non-MQTT destinations. In this project, we use the Object Storage Route, which enables us to communicate with the bucket created in the previous step.
Go back to the IoT Hub section of the Scaleway console, select your Hub and click on Routes:
Create a new route with the following parameters:
- Route Type: Scaleway Object Storage
- Region: Select the region corresponding to the region of your bucket
- Bucket: Select your bucket from the drop-down list
- Storage options: Per message
Click Add a new Route to save the form and to create the new route.
As the cloud environment is set up, we load our program on the ESP32-CAM module. Either start with the
CameraWebServer example sketch, modifying the code according to your needs, or open the
SCW_Photobooth sketch in this GitHub repository.
This tutorial uses the
SCW_Photobooth.ino sketch, ready to support MQTT connections.
Go to the Arduino IDE and open the
SCW_Photobooth.inosketch, available in the
SCW_Photoboothfolder of the repository.
Set your WiFi configuration and edit one variable to make it working (the
mqttUsermust be your Scaleway Device ID):
const char* ssid = "your-ssid";
const char* password = "your-passord";
bool useMQTT = true;
const char* mqttServer = "iot.fr-par.scw.cloud";
const char* HostName = "Photobooth_Scaleway";
const char* mqttUser = "your-device-id";
const char* mqttPassword = "";
const char* topic_PHOTO = "SMILE";
const char* topic_PUBLISH = "PICTURE";
const char* topic_FLASH = "FLASH";
const int MAX_PAYLOAD = 60000; // Maximum payload size to be sent using MQTT (in Bytes)
PubSubClientlibrary in the Sketch by clicking on Sketch > Include Library > Add .ZIP library. You find the library in the
librariesfolder of the repository.
Connect your ESP32-CAM board to a USB port of your compter to power it up. Select the USB port from the Tools > Port menu and upload the sketch by clicking on the Play button.
Open the serial console by clicking on Tools > Serial Monitor. Once the code is uploaded your device will restart and boot the new code. Your device is ready once you will see a message like the following example:
Starting web server on port: '80'
Starting stream server on port: '81'
Camera Ready! Use 'http://192.168.43.23' to connect
Attempting MQTT connection...connectedNote:
The device’s IP configuration uses DHCP. Your local WiFi requires a running DHCP server.
On the MQTT Explorer client, you can send an empty payload under the
SMILEtopic. Click on
PUBLISH, and your camera will take a picture and publish it under the
To see your pictures, go back to your Object Storage bucket in the Scaleway console. You should see your bucket populate more and more as you take new photos.
CameraWebServer sketch also provides a web interface to take pictures and change settings. In this tutorial, we use a slightly modified
app_httpd.cpp code to also send the picture when captured using the web interface.
To open the web interface, copy/paste the local IP provided by the Serial console in your web browser:
Click on Get still at the bottom left corner. Once taken, the picture will be published under the PICTURE MQTT topic and then forwarded to your Object Storage bucket!
You can observe the upload from the serial console:
Picture sent ? : 1
JPG: 4022B 28ms
Below is some further reading if you’d like to take a deep dive into the subject:
- Upload Code to ESP32-CAM AI-Thinker using ESP32-CAM-MB USB Programmer (easiest way)
- More advanced code that can be easily modified (including the html part)
- ESP32 CAM Face Recognition With MQTT Support
Credits to Louis Moreau, who initially wrote this tutorial. All sources are available on his public GitHub account.