IR SENSOR

 TOUCH ME NOT !!!

So, let's build a basic program to manipulate IR sensors using our loving ARDUINO UNO.  


                                                         


Lets us first understand something about ADC (Analog to Digital conversion). Our main purpose of Embedded systems is to collect data from the real world,  the sensors play a vital role here.

A simple diagram shows the ADC conversion...

 

So if we want a detailed blog on that pls refer to the ADC page of our blog...

Let's see the code and analyze it.


int IR = 2; // connect ir sensor to arduino pin 2

int LED = 13; // conect Led to arduino pin 13


void setup() 

    {

      pinMode (IR, INPUT); // sensor pin INPUT

      pinMode (LED, OUTPUT); // Led pin OUTPUT

    }

void loop()

    {

      while(1)

        {

          int statusSensor = digitalRead (IR);

          if (statusSensor == 1)

                {

                digitalWrite(LED, HIGH);

                delay(100);

                }

      else

              {

              digitalWrite(LED, LOW); 

              delay(100);

              }

  }



After reading the code, if you are unable to make the connection then go to the pervious topics and read them.





Comments