A IR phototransistor (the one that looks like a led) could be read as either a digital or analog signal --and would of course, need a pullup resistor etc.
A 38khz sensor (3-pin, used with remote controls) is read as a digital input and requires some “decoding” when/as the signal is received.
From my recent experience From my recent experience with analog pins on the Arduino UNO; you won’t need the pinMode() function which is used with digital pins if you are reading an analog ir photocell. If it is digital then you’d keep the pinMode(); and use digital read. There are also some libraries/code available eg: http://arduino.cc/playground/Code/InfraredReceivers
It would be helpful if you/we knew exactly what part you were using and how you planned to wire it.
Or if you are looking for one you could check the data sheet. Most suppliers have data sheets posted With more detailed information; sometimes even example wiring (though probably not for an Arduino).
This is an analog one, most common called Sharp and should work with your code:
Another kind are the digital receivers/transceivers:
Transceiver:
its sending a signal and gives you a HIGH when it gets the signal back to the receiver. Normally you can adjust the range with a small screw...lets say 50cm. If in 50cm something blocks the beam it will get refelected back to the transceiver and trigger the HIGH signal.
Receiver:
Those are codes to a certain frequency. Most of the time 38 or 56kHz and just looking for a IR signal which is modulated in these frequency. If it sees the IR signal it will give you a HIGH on the output.
if you just want to read the sensor val i got the code
int sensorpin = 0; // analog pin used to connect the sharp sensor pin 0 analog int val = 0; // variable to store the values from sensor(initially zero) voidsetup() { Serial.begin(9600); // starts the serial monitor }
voidloop() { val = analogRead(sensorpin); // reads the value of the sharp sensor Serial.println(val); // prints the value of the sensor to the serial monitor }
Mukund22kar. As once Geir Anderson told you to not copy&paste code or content from other websites to LMR without adding a reference to the creators. Always make a distinction between content from you and content from other people. You should not make copyright infringements.
The code-snippet you present here may come from there.
Keep in mind that you are a very talented person. No need to adorn yourself with borrowed plumes.
Ok, so I took the liberty of going to the googles for you. I googled “arduino IR…” at which time the autofill gave me an option called “Arduino IR Tutorial”. I clicked it.
Which one do you have? The Sharp spits out a lot of numbers for the analog readings. The others should only give you a HIGH (1) or LOW (0). Make sure your DIGITAL sensor is connected to a DIGITAL input…or analog to analog…