1

I build photo gate, to detect throwing ball. It works fine when delay time in main loop for max 40 milliseconds. Problems start when I delay every loop only for 20 milliseconds, now my LED which indicates if something broke path between IR led and IR receiver, blinks occasionally, if I set delay for 10 milliseconds and turn on, then LED is off for 2 seconds, then start blinking very fast and is ON for rest time, until I break IR path. I think some physics is going on here which I don't understand.

I also would like to ask if it is possible to narrow IR wave path to be more like laser (going strait into one direction) and how I can control sensitivity of IR detection

This is schematic enter image description here

IR transmiter IR reciever

Code:

//define pins. I used pins 4 and 5
#define irLedPin 4 // IR Led on this pin
#define irSensorPin 5 // IR sensor on this pin
#define buzzerPin 2 // buzzer on this pin
int irRead(int readPin, int triggerPin); //function prototype
void setup()
{
 pinMode(irSensorPin, INPUT);
 pinMode(irLedPin, OUTPUT);
 pinMode(buzzerPin, OUTPUT);
 Serial.begin(9600); 
 // prints title with ending line break 
 Serial.println("Program Starting"); 
 // wait for the long string to be sent 
 delay(100); 
}
void loop()
{ 
 bool isOn = irRead(irSensorPin, irLedPin);
 //Serial.println(isOn); //display the results
 if(isOn == true)
 {
 digitalWrite(buzzerPin, HIGH);
 }
 else
 {
 digitalWrite(buzzerPin, LOW);
 }
 delay(10); 
}
int irRead(int readPin, int triggerPin)
{
 int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds
 int cycles = 23; //26 microseconds * 23 is more or less 600 us
 int i;
 for (i=0; i <=cycles; i++)
 {
 digitalWrite(triggerPin, HIGH); 
 delayMicroseconds(halfPeriod);
 digitalWrite(triggerPin, LOW); 
 delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead 
 }
 return digitalRead(readPin);
}
VE7JRO
2,51519 gold badges27 silver badges29 bronze badges
asked Nov 5, 2015 at 22:09
4
  • You can get IR laser diodes if you want a beam. Commented Nov 5, 2015 at 22:26
  • Or you can use red laser beam and use that as a IR source. Commented Nov 6, 2015 at 7:54
  • @Avamander, wow that's strange, I just checked and it works, but how? my red laser has 570 nm and IR reciver 950nm and it works, how ? Commented Nov 6, 2015 at 18:18
  • The laser has close enough wavelength, the same thing works with red LEDs too. Commented Nov 6, 2015 at 18:37

1 Answer 1

3

While you are doing a delay() you can't be doing anything else - that includes looking to see if the beam has been broken by the ball.

You must not use delay() in your sketch, instead use millis() as in the BlinkWithoutDelay example sketch in the IDE's File -> Examples menu.

Also how you are dealing with your IR system is incorrect. You are first generating a brief square wave and then afterwards you are looking to see what was received. Instead you need to be generating the square wave and at the same time see if that square wave is being received. Normally that is achieved by using one of the PWM outputs of the Arduino set to the right frequency to generate a constant waveform which the receiver then senses all the time.

answered Nov 5, 2015 at 22:48

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.