Feeds:
Posts
Comments

Archive for the ‘Part 6 Programming the Arduino’ Category

Programming is fairly new to me, I’ve done some PHP stuff at work but it’s all self-taught; fortunately there is lots of information about Arduino code on the internet.

Here is the program that I used for my Arduino, this will basically drop a single droplet and hopefully capture a crown. The timing used in this program will only work for my setup, you will need to tweak the delays for your own setup!

I have 2 switches on my box one switch is latchable and the other is momentary, the latchable switch has to be on for the Arduino program to run; also there is test mode so when the latchable switch is off and the momentary switch is pressed for 5 seconds the solenoid with open and allowing a stream of water through, this is to aid focusing!

Since starting this blog and trying out the camera controller for water drop photography I’ve decided to ditch the motion sensor, I’m not sure that it’s required when using a solenoid valve to drop the water; so there wont be any reference to the sensor in the core of the program. I have still built the circuit as I feel that it would be useful in other areas of photography.

I’ve programmed the Arduino the way that I want it to work; it’s entirely upto you how you want to do things and there isn’t a right or wrong way
You can copy the code below and paste it into the Arduino programming interface.

 

//Camera Controller
//By Daniel Borg
//20th June 2011

// These constants won't change:
const int startPin = A0; //Pin that the start button os attached to
const int sensorPin = A1; //Pin that the sensor is attached to
const int solenoidSwitch = A2; //Pin that the solenoid switch is connected to
const int ledPin = 13; //Pin that the LED is attached to
const int cameraPin = 12; //Camera Trigger output
const int flashPin = 11; //Flash gun output
const int laserPin = 10;  //Laser Pointer output
const int solenoidPin = 9; //Solenoid output
const int threshold = 40; //An arbitrary threshold level that's in the range of the analog input
const int testSensorValue = 1000; //For testing

void setup() {
  Serial.begin(9600);  //Open serial port for testing
  pinMode(ledPin, OUTPUT); // Initialize the LED pin as an output
  pinMode(cameraPin, OUTPUT); // Initialize Camera Trigger as an output
  pinMode(flashPin, OUTPUT); // Initialize Flash Trigger as an output
  pinMode(laserPin, OUTPUT); // Initialize Laser Pointer as an output
  pinMode(solenoidPin, OUTPUT); //Intialize Solenoid as an output
}

//Check start button state
int startPinValue() {
   if (analogRead(startPin) > threshold){ //read the state of the start button
     return HIGH; //If start button pressed
   } else if (analogRead(startPin)  threshold){
    return HIGH; //If solenoid switch is pressed
  } else if (analogRead(solenoidSwitch) < threshold){
      return LOW; //If solenoid switch hasn't been pressed
  }
}

//Put the system into test mode, this will open the solenoid to aid focusing.
void testMode ()
 {
   for (int x=0; x  threshold){ //check if the solenoid switch is still being pressed
     Serial.println(x);
     } else {
       break;
     }
     if (x == 1000){
       digitalWrite(ledPin, HIGH);
       digitalWrite (solenoidPin, HIGH); //Activte the solenoid
       delay(5000); //Wait for 5 seconds
       digitalWrite(ledPin, LOW);
       digitalWrite(solenoidPin, LOW); //Deactivate the solenoid
       break;
     } else {
       continue;
     }
   }
 }

void loop() {

 int startPinState = startPinValue(); //Get start button state
 int solenoidSwitchState = solenoidSwitchValue();

 if (startPinState == HIGH) { //If the start button has been pressed

   if (solenoidSwitchState == HIGH){ //If solenoid switch has been pressed
     digitalWrite(cameraPin, HIGH); //Open camera shutter
     delay(500); //Wait for 500 milli seconds
     digitalWrite(ledPin, HIGH); //For test purposes
     digitalWrite(solenoidPin, HIGH); //Activte the solenoid
     delay(30); //Wait for 30 milli seconds
     digitalWrite(solenoidPin, LOW); //Deactivate the solenoid
     delay(20); //Wait for 20 milli seconds
     digitalWrite(ledPin, LOW); //For test purposes

      delay (420); //wait for 420 milli seconds
      digitalWrite(ledPin, HIGH); //For test purposes
      digitalWrite(flashPin, HIGH); //Turn flash gun on
      delay (200); //Wait for 200 milli seconds
      digitalWrite(ledPin, LOW); //For test purposes
      digitalWrite(flashPin, LOW); //Turn flash gun off
      digitalWrite(cameraPin, LOW); //Close camera shutter
      delay(1000); //Wait for 1 second
   } else if (solenoidSwitchState == LOW) { //If solenoid switch hasn't been pressed
     digitalWrite(solenoidPin, LOW); //Deactivate the solenoid
   }

    } if (startPinState == LOW && solenoidSwitchState == LOW) { //if the start button and solenoid button are released
        digitalWrite(ledPin, LOW); //For test purposes
        digitalWrite(cameraPin, LOW); //Close camera shutter
        digitalWrite(flashPin, LOW); //Turn flash gun off
        digitalWrite(solenoidPin, LOW); //Deactivate the solenoid
        delay(1000); //Wait for 1 second
    } else if (startPinState == LOW && solenoidSwitchState == HIGH) { //If the start button is off and the solenoid switch has been pressed
       testMode();
    }
}
Advertisements

Read Full Post »