Introduction

An infrared (IR) sensor a proximity sensor, or a ‘nearness’ sensor that senses whether there is an object near it or not. If it detects an object, the sensor will turn ON; if not, it will remain OFF.

An IR sensor has two small LED indicators – one for power, which is ON the entire time the sensor is ON; the other is the Signal LED which detects the object. The signal LED has two states or situations:

  • ON (Active) when it detects an object
  • OFF (Inactive) when it doesn’t detect any object

How to calibrate an IR Sensor

Calibrating the sensor is essentially is making sure that the LED turns ON when it detects the object, and turns OFF when it doesn’t. That’s it.

Follow the steps below to calibrate the sensor:

  1. Place an object at least 15cm away from the robot. If the signal LED is OFF, the sensor is working properly. Otherwise gently turn the potentiometer (that tiny blue cube with a screw in it) with a screw driver in the anti-clockwise direction such that the LED turns OFF.
  2. Similarly place an object about 5cm from the sensor. If the signal LED is ON, then it is working properly. Otherwise turn the potentiometer in the clockwise direction such that the LED turns ON.
  3. Repeat the above two steps till the signal LED works as is should in both cases.

How to interface the IR Sensor

Example: Detecting Black and White

Wiring

Follow the steps below to connect the IR sensor to evive:

  1. Take a red male-to-female jumper wire; connect the female end of the wire to the VCC pin of the IR sensor. Take the male end and connect it to the 5V pin in the top-left corner of evive.
  2. Next, take a black male-to-female jumper wire and connect its female end to the GND pin of the IR sensor; take the male end and connect it to the GND pin in the top-left corner evive, below the 5V pin.
  3. Take an orange male-to-female jumper wire and connect its female end to the OUT pin of the sensor; take the male end and connect to digital pin 2, present below the breadboard under the magic lid.

Scratch Script

Follow the steps below to write the script:

evive Tips and Tricks
If you’re working with evive in Scratch mode for the first time, or have uploaded the Arduino firmware previously, first upload the Scratch fimware; you can find the procedure to do the same here
  1. Connect evive to your laptop/PC, and select the appropriate port.
  2. Open mBlock; if already open and working on a project, save that project. Then, click on New.
  3. Go to the Events palette and drag and drop the when ‘flag’ clicked block.
  4. From the Control palette, drag and drop the forever block below the when ‘flag’ clicked block.

Below is the complete script:

Interface IR Script

Click on the green flag to run the script.

Click on the red octagon, next to the green flag to stop the script.

This Helped
This didn't help
Close Menu
×
×

Cart

STEMpedia Starter Package is now on Indiegogo!
Get 41% OFF with Super Early Bird discounts!
x