INTERFACE Proximity sensor with arduino
//Arduino and IR Proximity sensor + pushbutton
int pbutton=8;
int led=3;
int val=0;
int ledon=0;
int pushed=0;
void setup()
{
Serial.begin(9600);
pinMode(pbutton, INPUT_PULLUP);// Connect one point of Pushbutton to D8 Pin of Arduino and other point to GND of Arduino.
pinMode(led, OUTPUT);
}
void loop()
{
val=digitalRead(pbutton);
if(val==HIGH && ledon==LOW)
{
pushed=1-pushed;
delay(100);
}
ledon=val;
if(pushed==HIGH)
{
Serial.println("led on");
digitalWrite(led, LOW);
}
else
{
Serial.println("led off");
digitalWrite(led, HIGH);
}
}
Comments
Post a Comment