Created
January 19, 2016 07:20
-
-
Save TinajaLabs/1ec972f0b0565df85b44 to your computer and use it in GitHub Desktop.
Scan slides with DSLR and slide projector using arduino and some relays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code uses an Arduino Uno to control a slide scanner and a DSLR to make it easier to digitize slides. | |
I got these relays on Amazon for about $3 each. They take 5VDC, Gnd, and a low | |
voltage to close the normally open relay. http://www.amazon.com/gp/product/B00G9TQH8U | |
Features: | |
This relay module is 5V active low. | |
It is a 1-channel relay interface board, which can be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM, PLC, etc. | |
It is also able to control various appliances and other equipments with large current. | |
Relay output maximum contact is AC250V 10A and DC30V 10A. | |
Standard interface can be directly connected with microcontrollers. | |
The working status indicator light is conducive to the safe use. | |
Widely used for all MCU control, industrial sector, PLC control, smart home control. | |
With opto-isolator, more stable and reliable. | |
Specifications: | |
Working voltage: 5V | |
Channel: 1 channel | |
Item size: 5.6 * 1.7 * 1.7cm / 2.2 * 0.67 * 0.67in | |
Package weight: 18g / 0.63oz | |
Package includes: | |
1 * 1 Channel Relay Module | |
-- | |
ChrisJ, 2016.01.17 | |
*/ | |
int slideCount = 0; // the current count of slides imaged | |
int trayCount = 140; // the size of the slide tray | |
volatile boolean runningState = false; //Set the default running state, FALSE = no action, TRUE = scan running | |
const int runLedPin = 13; // Set pin for LED that marks if scan is running | |
volatile const int button = 3; | |
volatile const int bounceDelay = 5; //Time in usec to wait for debounce action | |
const int relayProj = 7; // the pin used for the projector relay | |
const int ledProj = 11; // the pin used to indicate we're running the projector code | |
const int trigSlide = 250; // time in msec defining how long relay should be activated to go to next slide | |
const int slideDrop = 1500; // time in msec to wait for slide to move into place | |
const int betweenSlides = 12000; // time delay between shutter release and next slide action | |
const int relayCam = 8; // | |
const int ledCam = 12; | |
const int trigShutter = 250; // time in msec defining how long relay should be activated to go to next slide | |
const int shutterTime = 1500; // time in msec to wait for slide to move into place | |
// Status LED vars | |
long cycleCount = 0; // Keep track of cycles in loop | |
int cycleDivider = 10000; // After how many cycles the status LED will change | |
boolean ledStatus = false; // LED will be off to start with | |
void setup() { | |
Serial.begin(9600); | |
pinMode(button, INPUT); | |
pinMode(runLedPin, OUTPUT); //Set pin for indicator LED | |
pinMode(ledProj, OUTPUT); | |
pinMode(ledCam, OUTPUT); | |
pinMode(relayProj, OUTPUT); | |
pinMode(relayCam, OUTPUT); | |
attachInterrupt(1, startPause, RISING); //Enable interrupt for start/pause button | |
digitalWrite(relayProj, HIGH); | |
digitalWrite(relayCam, HIGH); | |
} | |
void loop() { | |
if (runningState) { | |
digitalWrite(runLedPin, runningState); // Status LED permanently lit duirng scan | |
advanceSlide(); | |
delay(500); | |
takeImage(); | |
slideCount += 1; | |
Serial.print("Captured slide: "); | |
Serial.print(slideCount); | |
Serial.print(" waiting for "); | |
Serial.print(betweenSlides); | |
Serial.println("ms..."); | |
if (slideCount > trayCount) { | |
runningState = false; | |
} | |
if (runningState) delay(betweenSlides); // if still running, wait for x msec before proceeding to next slide | |
} else { | |
blinkLED(runLedPin); // blink the status LED to indicate we are ready | |
} | |
} | |
void advanceSlide() { | |
digitalWrite(ledProj, HIGH); // turn the LED on (HIGH is the voltage level) | |
Serial.println("triggering slide"); | |
digitalWrite(relayProj, LOW); | |
delay(trigSlide); | |
digitalWrite(relayProj, HIGH); | |
delay(slideDrop); | |
digitalWrite(ledProj, LOW); // turn the LED off (HIGH is the voltage level) | |
} | |
void takeImage() { | |
digitalWrite(ledCam, HIGH); // turn the LED on (HIGH is the voltage level) | |
Serial.println("triggering shutter"); | |
digitalWrite(relayCam, LOW); | |
delay(trigShutter); | |
digitalWrite(relayCam, HIGH); | |
delay(shutterTime); | |
digitalWrite(ledCam, LOW); // turn the LED off (HIGH is the voltage level) | |
} | |
// Start/pause button press interrupt ISR - changes the running state | |
void startPause(){ | |
int j; | |
for (j=0; j<bounceDelay; j++) delayMicroseconds(1000); //button was pressed, now wait for a little bit to check state again (aka soft debounce) | |
if (digitalRead(button)==HIGH) runningState = !runningState; // if still pressed, then change runningstatus | |
} | |
// Blink ready | |
void blinkLED(int ledPin) { | |
cycleCount++; // increment cycle count on each loop | |
if (cycleCount % cycleDivider == 0) { // change LED status every so many cycles | |
ledStatus = !ledStatus; // change LED status | |
digitalWrite(runLedPin, ledStatus); // Turn LED on or off every X cycles | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment