IR sensor

Description

What is the IR sensor?

IR sensor is an electronic sensor that emit and detecte infrared radiation. 

How does it work?

IR Sensors work by using a specific light sensor to detect a select light wavelength. By using an LED which produces light at the same wavelength as what the sensor is looking for, you can look at the intensity of the received light. 
When an object is close to the sensor, the light from the LED bounces off the object and into the light sensor.Since the sensor works by looking for reflected light, it is possible to have a sensor that can return the value of the reflected light. This type of sensor can then be used to measure how "bright" the object is. This is useful for tasks like line tracking.

IR sensor components

 

  • Distance adjustment potentiometer is used to change the detection distance which range between 2 - 40 cm
  • Frequency adjustment potentiometer is used to change the carrier frequency of the infrared signal. Avoid using it unless there is interference
  • The jumper is used to enable the sensor. So if the enable pin is not connected, the jumper must be installed.  
  • To use the enable (EN) pin. Jumper cap must be removed. Set it as low (0) to enable the sensor and high (1) to disable it.

How to connect it?

Setting up IR sensor connection to Arduino is very simple. Beside VCC and GND pin, the sensor has two pins that should be connected to two of the digital pins on Junkbot board.

  • VCC --> 5V
  • GND --> ground
  • OUT --> to any digital pin (6 or 8 if you’re using 4 pin connector)
  •  EN --> to any digital pin ( 7 or 8 )

How to program it ?

 Enabling  the sensor is done by setting the digital pin connected to the EN pin as low (low --> enable, high --> disable) and attach it to any event from your choice. In order to display the IR sensor reading, Junkbot Sprite can do that using the “say” block inside a forever loop. Then set it to read the digital pin value connected to the IR sensor.    
Here is an example code: