DIY: Shutter tester


Simple Arduino based shutter tester.

Elements:
  • Arduino Nano
  • LCD 16x2 with I2C interface
  • laser diode module (pointer) 5V
  • photo-transistor and resistor


Button (NO) is optional - program goes into measure mode after 5 seconds of working light barrier.
Resistor added to photo-transistor should set correct levels with ambient and laser light - I used 22kOhm.

Things  to improve: Photo-transistor is connected directly do ATmega Port, so low state is detected when voltage drops below ~0.3*Vcc, and high when it goes over ~0.6*Vcc. For shorter times it will measure longer "open" period. So times shorter than 1/60s are not reliable.








The 3D printed casing (use two M5 screws and nuts):
https://www.thingiverse.com/thing:4219139


Arduino program:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

const int inPin = 2;   //PIN D2 for light sensor
const int keyPin = 3;  //PIN D3 for optional key

long int  tStart, tStop, tM, tS10;
float     tS;

LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Set the LCD I2C address

void setup() {
  Serial.begin(9600); //debug
  pinMode(inPin, INPUT);
  pinMode(keyPin, INPUT_PULLUP);
  //I2C for LCD
  Wire.begin();
  lcd.begin(16,2);
  //lcd.setBacklightPin(3,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Shutter tester");
  delay(1000);
}

void loop() {
  lcd.clear(); lcd.print("Set barrier");
  while( digitalRead(keyPin)==LOW ) {}
  tStart=millis();
  while( digitalRead(keyPin)==HIGH && ( (tStart+5000)>millis() ) ) //wait for key or 5s of working light barrier
  {
    delay(500);
    if (digitalRead(inPin)==HIGH) { lcd.setCursor(0,1); lcd.print("--"); tStart=millis(); }
      else { lcd.setCursor(0,1); lcd.print("OK"); }
  }
  lcd.clear(); lcd.print("Ready");
  delay(1000);
  while( digitalRead(keyPin)==LOW ) {} //clr key
  while ( digitalRead(inPin)==LOW ) {} //wait to put shutter in barrier
  lcd.clear(); lcd.print("Measure");
  while( digitalRead(keyPin)==HIGH )
  {
    //when light beam break then start light measure
    if (digitalRead(inPin)==LOW)
    {
      tStart=micros();
      while ( digitalRead(inPin)==LOW ) {}
      tStop=micros();
      tM=tStop-tStart;
      lcd.setCursor(0,1); lcd.print("                "); lcd.setCursor(0,1); 
      if ( tM<800000 ) { lcd.print(tM/1000); lcd.print("ms"); } //display time in [ms]
      if ( tM>=800000 ) //if 0.8s then display only time
      {
        tS10=tM/10000; tS=tS10/100.0;
        lcd.print(tS); lcd.print("s");
      }
      else //display shutter value 1/x
      {
        tS10=100000000/tM; tS=tS10/100.0;
        lcd.setCursor(7,1); lcd.print("1/"); lcd.print(tS);
      }
      delay(500);
    }
  }
}

Comments

Popular Posts