Example Code for Arduino-Take Photos

Last revision 2026/01/26

This article is a comprehensive guide on using an Arduino setup with FireBeetle ESP32 and a camera module to capture photos, providing step-by-step instructions, hardware/software preparation, and sample code.

Hardware Preparation

Software Preparation

Other Preparation Work

  1. This media board only supports FireBeetle ESP32 main board at present, for other main boards do not equipped with IIS interface.
  2. The flat ribbon cable of camera is relatively easy-to-break, please be careful and light in connection. The camera shot must be opposite to the SD card slot.
  3. Do not support video shooting and transmission.
  1. Due to the limitation of ESP32 processing performance, it only supports 320x240 QVGA resolution for now.
  2. And the network transmission picture only supports GRAYSCALE photo, the next version will supports colorful image.
  3. Fixed focus, no need to adjust.
  4. Tutorial to get a photo:
  • Click to download the software tool in need.
  • Open the software tool.
    DFR0498-Take a photo1
  • Run the program and open the serial port to check IP address.
    DFR0498-Take a photo2
  • Input IP address. (PC and ESP32 main board should be in a same network segment), click start to take a photo in a real time.
    DFR0498-Take a photo3

Download programs as below to ESP32 main control board and plug a SD Card.

Sample Code

Press the button to take a photo, saving as photo1.bmp. Press the button again to take another photo, saving as photo2.bmp. Please pay attention that you can keep pressing button to take photo, but it will cover photo1 and photo2 in turn.

/*!
 * @file DFRobot_IIS.h
 * @brief DFRobot's IIS Camera Module
 * @n IIS Module for take photo and save BMP file in SD card
 *    Insert sd card
 *    Call the function by pressing user key to take photo
 *    This Module will take photo and save as photo1.bmp,photo2.bmp by pressing user key
 */

#include <Wire.h>
#include "DFRobot_IIS.h"

DFRobot_IIS iis;
const int buttonPin = 16;
int i=0;
const char* SSID    ="yourSSID";
const char* PASSWORD="SSID password";
void setup(){
    Serial.begin(115200);
    pinMode(buttonPin, INPUT);
    iis.SDCardInit();                                //SD card init
    iis.init(CAMERA);                                //Init Camera mode
    iis.connectNet(SSID,PASSWORD);                   //Connect wifi
    iis.setFramesize(QVGA);                          //Set photo size QVGA:320x240
    iis.setPixformat(GRAYSCALE);                     //Set pixelformat GRAYSCALE
    iis.sendPhoto();                                 //Send photo to net
    delay(100);
    Serial.println("Ready to take photo");
}

void loop(){
    static unsigned long timepoint = millis();
    static byte count = 0;
    if(millis()-timepoint > 20){
       timepoint = millis();
       if(!digitalRead(buttonPin)&& i == 0){
          Serial.println("take photo1");
          iis.snapshot("/photo1.bmp");               //Take photo and save it as photo1.bmp in SD card
          Serial.println("done");
          i=1;
        }
        if(!digitalRead(buttonPin)&& i == 1){
          Serial.println("take photo2");
          iis.snapshot("/photo2.bmp");               //Take photo and save it as photo2.bmp in SD card
          Serial.println("done");
          i=0;
        }
   }
}

Result

Button triggers taking photo1/photo2 alternately to SD, Serial prints status, WiFi info to be replaced.

Functions

  • Initialize SD card in the beginning.
SDCardInit():
  • Enter CAMERA mode, state its mode (AUDIO / CAMERA) in use when the SD card is initialized.
init(CAMERA):
  • Connect to Wi-Fi, SSID and PASSWORD are the name and the password of Wi-Fi been used.
connectNet(SSID,PASSWORD):
  • Set image frame size and it need to be called in CAMERA mode, supporting QQVGA (160x120) QQVGA2 (128x160) QICF (176x144) HQVGA (240x160) QVGA (320x240).
setFramesize(QVGA):
  • Set pixel format and it need to be called in CAMERA mode, supporting RGB555 (colorful), GRAYSCALE.
iis.setPixformat(GRAYSCALE):
  • Connect to Wi-Fi and transmit CAMERA data to the Internet, the CAMERA shooting (GRAYSCALE) can be checked by referring the tutorial and image as below.
sendPhoto():
  • Function to take a photo: Name the image file (photo1.bmp in SD card at here) to be saved, call the function to take a photo and save.
snapshot("/photo1.bmp"):

Was this article helpful?

TOP