Created by Breandan P O'Shaughnessy
Status: Active
4431bbbf2c471b516d26143dfdb84782?s=30

Android App and Firmware Step 7 of 7

My android app takes care of all the hard work of creating a mobile device interface for this sketch.  To begin you need to download the free version of Toothfairy here, or if you like it you can download the paid version for a dollar.  You will now need to download the arduino library here.

Install the arduino library the normal way, by unzipping, and copying to the libraries folder of your arduino install.

You will now need the sketch for the intervalometer.  Copy this source code into your arduino environment in a new sketch.  You will want to unplug the HC-06 module from the breadboard when you are uploading, since it interferes with the use of the serial port.

#include <BlueDentist.h>

#define AFinterval 10000
#define AFPin 11
#define shutterPin 12
#define baudRate 9600

unsigned long lastAFMillis = 0;
unsigned long lastShutterMillis = 0;
long timer = 0;


BlueDentist *myBD;
BDNumField *interval;
BDBTN *shutter;

void snapPhoto()
{
  digitalWrite(shutterPin, HIGH);
  delay(100);
  digitalWrite(shutterPin,LOW);
  }
void runAF()
{
  digitalWrite(AFPin, HIGH);
  delay(100);
  digitalWrite(AFPin, LOW);
  }
void keepAwake()
{
    if(millis()-lastAFMillis > AFinterval)
  {
    runAF();
    lastAFMillis = millis();
    }
  }
 
void timeLapse()
{
  if(millis()-lastShutterMillis > timer)
  {
    snapPhoto();
    lastAFMillis = millis();
    lastShutterMillis = millis();
    }
  }

void setup() {
  // put your setup code here, to run once:
  pinMode(AFPin, OUTPUT);
  pinMode(shutterPin, OUTPUT);
  digitalWrite(AFPin, LOW);
  digitalWrite(shutterPin, LOW);

  myBD = new BlueDentist(9600);
  interval = new BDNumField("int");
  shutter = new BDBTN("snap");
  myBD->add(interval);
  myBD->add(shutter);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  myBD->run();
  if(shutter->getPresses() >0)
  {
    snapPhoto();
    shutter->reset();
    }
  keepAwake();
  timer = interval->getVal();
  timer *= 1000;
  if(timer > 0)
    timeLapse();
    
 // Serial.print("testing");
 
}

Functions:

  • snapPhoto() just writes high to the shutter release pin, then waits 100 ms and sets it low again
  • runAF() does the same for the autofocus pin
  • keepAwake() checks if nothing has happened for 10 seconds, if so it triggers AF just to keep the camera awake
  • timeLapse() checks if the interval between photos has passed, and if so calls snapPhoto()
  • setup() contains all the code for our bluetooth interface setup, and sets the pinModes for the two output pins
  • loop() checks if the shutter button on the android app has been pressed, and if so shoots a photo, then it calls keepAwake().  It then grabs the current interval from the android app, and if it's not set to 0 it calls timeLapse().  Finally it also runs myBD->run() which is the service function for the bluetooth interface, to keep it updated.