I have a breadboard Arduino; made with ATMega328PU and a UART connector using a CT2102 breakout board. With the help of this site I created a simple IR sensor, now the problem is that in the Serial Monitor I'm getting a constant value of 1023. Even on removing the receiver (photodiode), the value's starts dropping like a capacitor discharges, and then stabilizes at some value (around 260-300).

When everything was working correctly, the value dropped to a sudden zero on removing the receiver, but now it isn't.

The "robot" was working perfectly and was reading the values correctly, but suddenly, the values dropped; we checked it and the Serial Monitor showed the same values. To check if the connections are working, I removed a wire from the Analog Pin of the Breadboard-Duino, and the values started to drop: like a periodic function.

The following code was used:

int pd=2;                      //Photodiode to digital pin 2
int buzz=13;                   //piezo buzzer to digital pin 13  
int senRead=0;                 //Readings from sensor to analog pin 0  or A0
int limit=850 / 4;                 //Threshold range of an obstacle  
void setup()    
  digitalWrite(pd,HIGH);       //supply 5 volts to photodiode  
  digitalWrite(buzz,LOW);      //set the buzzer in off mode (initial condition)  
  Serial.begin(9600);          //setting serial monitor at a default baund rate of 9600  
void loop()  
  int val=analogRead(senRead) / 4;  //variable to store values from the photodiode  
  Serial.println(val);          // prints the values from the sensor in serial monitor  
  if(val <= limit)              //If obstacle is nearer than the Threshold range  
   digitalWrite(buzz,HIGH);     // Buzzer will be in ON state  
  else if(val > limit)          //If obstacle is not in Threshold range  
   digitalWrite(buzz,LOW);      //Buzzer will be in OFF state  

Any help will be appreciated.


The phototransistor/diode is a standard 2pin component which came with the IR sensor.


  • This is most likely a problem with the connection of the sensor. What sensor is it? How is it wired? Please show some schematics or good clear photos, as well as links to data sheets.
    – Majenko
    Nov 3, 2014 at 13:37
  • Majenko, I did check the connections thrice; checked every component two times, but still no luck! :'(
    – weirdpanda
    Nov 4, 2014 at 10:39
  • 1
    I'm getting a constant value of 1023 - you won't be getting that because you divide the reading by 4. You should get a maximum of 255. Please post the code you are actually using. Also measure the voltages going into A0 with a multimeter, to confirm they vary as something passes between the transmitter and receiver.
    – Nick Gammon
    Aug 1, 2015 at 1:37

3 Answers 3


In your initialisation where you declare each variable and 'connecting' them to a pin you make a mistake. Now you say that senRead is a digital pin instead of a analog pin. Change the value to A0 so you will get

int senRead = A0;

Also in your void Setup() you forget to declare your analog pin as an input. Add a pinMode command that sets senRead as an input.

If this doesn't fix your problem then it is probably hardware related. Check the connections on your breadboard will most of the times solve alot of problems.

  • 1
    "Also in your void Setup() you forget to declare your analog pin as an input." - doesn't make any difference for analogRead(), only digitalRead().
    – Majenko
    Nov 3, 2014 at 13:36
  • 1
    analogRead(0) and analogRead(A0) both read analog pin 0.
    – Majenko
    Nov 3, 2014 at 13:36
  • Indeed! Thanks for the tip, but alas! Its not working. I tried it, and am getting the same sort of values.
    – user3102854
    Nov 3, 2014 at 13:40
  • ok. adding a picture of how you wired your circuit would be appreciated. Also datasheets / a partlist can help.
    – T J
    Nov 3, 2014 at 14:04
  • Done! @TJ check it now!
    – user3102854
    Nov 3, 2014 at 14:33

I guess your ir emitter is blown.Test it with a multimeter.Apply 5v from Arduino and check the voltage between two pins or just use phone's camera.If multimeter shows anything more than 3v or it just plainly shows applied voltage the led failed or it is open.If it is not,then use phone camera and watch the led through the camera. You should see a blue light emitting from it( if it's working).


If the circuit worked perfectly, as is, and suddenly stopped working, without changing any hardware configuration, it must be a hardware related problem.

Assuming your Arduino Uno is functioning properly and the pins behave accordingly (you can test blink.ino on the pin in doubt), it's either the IR sensor went bad or a the IR LED stopped working properly. Test each component individually. For the IR sensor, you could use any remote control to emit IR light on it and see if values change.

Another way to test bad pins are to switch from A0 to A1 and from PB2 to PB3 or similar.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.