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

Popular posts from this blog

4 Stage Timer With DS3231RTC Module.

Interfacing KY038 sound sensor with Raspberry pi Pico

Interfacing MQ2 Gas & Smoke Sensor With Raspberry Pi Pico