Why my IR system does not work!

Hi guys! I need to biuld a system based on the break of an IR beam. I have tried several codes and different IR sensors and emitters, but no one works. This is the code I used:

const int InfraredSensorPin = 4;//Connect the signal pin to the digital pin 4 const int Led_IR = 7; //pin to the IR led const int LED =13; //pin to an LED to report the beam break.

void setup() { Serial.begin(9600); Serial.println("Start!"); pinMode(InfraredSensorPin,INPUT); pinMode(LED,OUTPUT); pinMode (Led_IR, OUTPUT); digitalWrite(LED,LOW); digitalWrite (Led_IR, HIGH); //emitter is always on. }

void loop() { if(digitalRead(InfraredSensorPin) == LOW) digitalWrite(LED,HIGH); else digitalWrite(LED,LOW); Serial.print("Infrared Switch Status:"); Serial.println(digitalRead(InfraredSensorPin),BIN); delay(50); // end

the circuit is the following:

please help me! I donĀ“t know what I'm doing wrong. It appears that the sensor is always LOW.

Your code is incomplete, so cannot compile, so cannot be said to work or not work.

sorry! I forgot the "}", but it still doesn't work. Here we go:

const int InfraredSensorPin = 4;//Connect the signal pin to the digital pin 4 const int Led_IR = 7; //pin to the IR led const int LED =13; //pin to an LED to report the beam break.

void setup() { Serial.begin(9600); Serial.println("Start!"); pinMode(InfraredSensorPin,INPUT); pinMode(LED,OUTPUT); pinMode (Led_IR, OUTPUT); digitalWrite(LED,LOW); digitalWrite (Led_IR, HIGH); //emitter is always on. }

void loop() { if(digitalRead(InfraredSensorPin) == LOW) digitalWrite(LED,HIGH); else digitalWrite(LED,LOW); Serial.print("Infrared Switch Status:"); Serial.println(digitalRead(InfraredSensorPin),BIN); delay(50); }

you would probably need to post a link to the data sheet of the sensor. you are using.

On the face of it, it looks like a proximity sensor which will give a signal when something moves near the sensor.

This would not be the same as breaking a beam.

Also, many of these sensors have a very short range.

To help people to help you, you will probably need to provide more detail about how you intend to use this.

Enable the pull-up resistor on pin 4 http://www.gammon.com.au/forum/?id=11955 http://www.thebox.myzen.co.uk/Tutorial/Inputs.html