Monday, July 29, 2013

New light detector circuit

Prototyping the new light circuit on breadboard. Everything is working well so far.
Circuit detail (Transistor is wrong type but the correct footprint for the PCB)

Output in dim light is about 0.13V going up to just over 1V with an inspection lamp close to the transistor.

Photo Transistor
Low Power Op-Amp
This circuit will form the second PCB in a two stack design. Interconnects will be via pin headers (0.1") and power will be from a CR2032 3V coin cell battery.

The prototype PCB will be mostly SMD tech with the photo transistor and pin headers being through-hole.

Bit of code that just works...

/*
StormTrigger V3 30-07-2013
 */
#define FASTADC 1
// defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

#define LIGHT 0
#define OUT_FOCUS 2
#define OUT_SHUTTER 3
#define LED 13
int trigVal = 0;

void setup() {

#if FASTADC
  // set prescale to 16
  sbi(ADCSRA,ADPS2) ;
  cbi(ADCSRA,ADPS1) ;
  sbi(ADCSRA,ADPS0) ;
#endif
  pinMode(OUT_FOCUS, OUTPUT);
  pinMode(OUT_SHUTTER, OUTPUT);
  pinMode(LED, OUTPUT);
  PORTD = B01010000;
  // calibrate sensor to just above ambient reading
  int ambVal = analogRead(LIGHT);
  trigVal = ambVal + 40;
}
void loop() {
  //read light level
  int lightVal = analogRead(LIGHT);
  //compare light reading to trigger value
  if (lightVal >= trigVal)
  {
    //trigger camera
    PORTD = B00101100;
    delay(15);
    PORTD = B01010000;
    digitalWrite(LED, HIGH);
    delay(30);
    digitalWrite(LED, LOW);
  }

}

No comments:

Post a Comment