Hi,
im making an IR breakbeam detector for my Arduino stopwatch. I have a 38kHz crystak oscilator and ne555 timer to modulate it (On breadboard). On the receiver part i have connected TSOP34838 IR receiver and his output to Arduino pin2 setup as interrupt pin. The question is that i want the stopwatch to be (relativelly) prescise, so on the 555 i need to use higher frequency. But to what extend? i looked up a datasheet for the receiver and played with it for a fer hours and discovered that in some cases its nor really reliable. I wrote a simle code to tell me if the brakbeam was cut. The timer is used to trigger the "Cut", but if the pulse from a IR sensor comes first, it will reset it. But im not having much luck getting it to work, does somebody have an experince with it? Thanks a lot
bool state = false;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT);
attachInterrupt(digitalPinToInterrupt(2), blinka, RISING);
// TIMER 1 for interrupt frequency 600.0150003750093 Hz: (This was copied from an online generator for saving me some time for now)
cli(); // stop interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
TCNT1 = 0; // initialize counter value to 0
// set compare match register for 600.0150003750093 Hz increments
OCR1A = 23528; // = 16000000 / (1 * 600.0150003750093) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12, CS11 and CS10 bits for 1 prescaler
TCCR1B |= (0 << CS12) | (0 << CS11) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei(); // allow interrupts
}
void loop() {
// put your main code here, to run repeatedly:
}
void blinka()
{
TCNT1 = 0;
state = false;
digitalWrite(13,0);
}
ISR(TIMER1_COMPA_vect){
if (state == false)
{
Serial.println("CUT");
}
digitalWrite(13,1);
state = true;
}