Lesson 33: Automatically Take Photos with Smartphone Camera


Written by Jonathan Sim

You can find this lesson and more in the Arduino IDE (File -> Examples -> Andee). If you are unable to find them, you will need to install the Andee Library for Arduino IDE.

Works on iOS and Android
In this lesson, I'll show you how to get the Annikken Andee x Arduino to trigger your smartphone to take a photo!

I'll use a button to demonstrate the feature, but you can also use a sensor to trigger it too!


Top of the Code

#include <SPI.h>
#include <Andee.h>

// We'll just create a display box to give us updates, and a button
// to trigger the camera.
AndeeHelper displaybox;
AndeeHelper button;
AndeeHelper camera; // This object will handle the smartphone camera


void setup()
  Andee.begin();  // Setup communication between Annikken Andee and Arduino
  Andee.clear();  // Clear the screen of any previous displays
  setInitialData(); // Define object types and their appearance


void setInitialData()
  // Let's draw the button!
  displaybox.setId(0); // Don't forget to assign a unique ID number
  displaybox.setType(DATA_OUT); // Defines object as a display box
  displaybox.setTitle("Andee Controlled Camera");
  displaybox.setData("Camera Ready");

  button.setTitle("Take Photo Now");

  // Smartphone Camera Properties /////////////////////////////
  camera.setType(CAMERA); // Set object as a camera
  // You can choose which camera you want to use:
  // - DEFAULT  : default camera
  // - FRONT    : front-facing camera
  // - REAR     : rear-facing camera
  // Set whether you wish to enable auto focus before each shot
  // Options available:
  // - ON
  // - OFF
  camera.setAutoFocus(ON); // Options: true or false
  // Set whether you wish to enable flash at each shot
  // Options available:
  // - ON
  // - OFF
  // - AUTO
  // Set photo filename prefix. Subsequent photos will
  // have a number appended at the end.
  // If file overwrite is enabled, the same file will be replaced
  // everytime a new photograph is taken. If disabled, a new photo
  // will be generated and stored on the phone.
  // Options available:
  // - ON
  // - OFF
  // Choose storage location to store your photos. The Andee app 
  // will create a folder in that location called, "Annikken_Andee"
  // Options available:
  // - DEFAULT : Save in the default photo location on your phone.
  //             If you have set your default photo location as SD Card,
  //             photos taken will be stored on your SD card.
  // - SDCARD  : Save in external SD Card.


void loop()
  // You can substitute the button press with a sensor condition instead
  if( button.isPressed() )
    displaybox.setData("Taking Photo");
    camera.takePhoto(); // Call smartphone camera to take photo
    // Give the smartphone time to complete action. It will take
    // the camera at least 2 seconds to complete the entire
    // photo-taking process. This process may take even longer
    // on slower phones.
    // If the phone is still not ready, wait another 2 seconds more
    // before checking again.
    while( !camera.takePhotoResultReady() )
    // camera.getLastTakePhotoResult() will produce an error code
    // at the end of the process.
    if(camera.getLastTakePhotoResult() == 0)
      displaybox.setData("Photo Successfully Taken!");
      while(true); // Freeze and do not allow user to do anything else
  delay(500); // Always leave a short delay for Bluetooth communication
  displaybox.setData("Camera Ready"); // Reset displaybox message
comments powered by Disqus