Hi, i m trying to read an digital input from a sensor , infrared.
int ledPin = 13; // LED connected to digital pin 13
int inPin = 12; // pushbutton connected to digital pin 7
int val = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin 13 as output
pinMode(inPin, INPUT); // sets the digital pin 7 as input
Serial.begin(9600);
}
void loop()
{
val = digitalRead(inPin); // read the input pin
Serial.print(val);
digitalWrite(ledPin, val); // sets the LED to the button's value
}
the problem is that when i start the arduino board, let s say i get value 0. If i put my hand in front of the sensor i get value 1. Then it just remains 1. Again if i restart the board with my hand in front of the sensor i get 1, if i take it away i get 0 and remains 0 forever. Please help!