Interface Sensors with Arduino using PictoBlox

Turn LED ON using IR Sensor
About This Tutorial
In this tutorial, we will understand what IR sensor is, calibrate it, and finally control Uno’s Pin 13 LED using the IR Sensor.
Tutorial Info

Components Required

ImageComponentQuantityAvailable in Kit
Arduino Uno1
PictoBlox1
IR Sensor1
USB A-B Cable1
Male to Female Jumper Cable 20cm3

Introduction

Sensors, as the name suggests senses the surrounding weather and either records it or indicates it. There are a number of sensors that detects different surrounding factors like proximity, light, temperature, humidity, noise, and much more. 

Today, we are going to see how can we integrate sensors i.e an IR sensor to Arduino projects using PictoBlox, our graphical programming software. An infrared (IR) sensor a proximity sensor, or a ‘nearness’ sensor that senses whether there is an object near to 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 shows the status of the detection. The signal LED has two states or situations:

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

Let’s begin!

Interfacing the IR Sensor

Firstly, connect the IR Sensor to Uno.

  • Connect the sensor’s VCC pin to Uno’s 5V pin using a red male-to-female jumper cable.
  • Next, connect the sensor’s ground pin to Uno’s ground pin using a black male-to-female jumper cable.
  • Then, connect the sensor’s out pin to Uno’s digital pin 2 using a green male-to-female jumper cable.IR + Uno

Connect Uno to your computer with the help of a USB cable.

  • Click on the Board button in the toolbar and select Arduino Uno from the drop-down menu.
  • Then, click on the Connect button and select the appropriate port. Uploading

Calibrating the IR Sensor

If the LED turns ON when you bring your hand near to the IR Sensor and turns OFF when you take your hand away, indicates that the IR Sensor is working properly. What if the LED does not turn ON or OFF when necessary. Then, its the time when you need to calibrate your IR Sensor.

Follow the steps given below:

  1. Keep your hand at some distance from the Sensor approximately 15cm. If the LED is OFF, then you need not do anything. Otherwise, turn the potentiometer using a screwdriver in the anti-clockwise direction until the LED turns OFF.
  2. Similarly, keep your hand close to the IR Sensor approximately 5cm. If the LED is ON, the sensor is perfectly calibrated. Otherwise, turn the potentiometer in the clockwise till the LED turns ON.
  3. Repeat the above two steps until your IR works perfectly fine.Calibrate the IR Sensor

Testing the IR Sensor

We will make our sprite Tobi, say out loud the sensor reading. As we are writing the test code, we won’t be uploading it to Uno. Thus, we will be working in Stage ModeIt lets you interact with the sensor in real-time or without uploading the code. 

  1. First, drag and drop the when flag clicked block from the Events palette.
  2. Then, drag and drop the forever block from the Control palette.
  3. Next, from the Looks palette, drag and drop the say block inside the forever block.say block
  4. To check whether the IR sensor is ON or not, we’re going to use the read digital sensor block from the Sensors palette. There are blocks to other sensors, like the ultrasonic sensor, as well.read digital sensor block
  5. Drag and drop the read digital sensor block inside the space of the say block and select IR from the drop-down menu.read sensor reading in say
  6. Now, to work with Uno in Stage mode, we first need to upload a Firmware to it. For that, click on the Upload Firmware button above the stage.
  7. Once the firmware is uploaded(next), click on the green flag above the stage and take your hand close to the sensor.Upload Firrmware

Its signal LED will turn ON and Tobi will say ‘zero’It will turn OFF when you take your hand away. Meanwhile, Tobi will say ‘one’. This means the sensor is working properly.Testing

Activity: Control Pin 13 LED of Uno

In this activity, we will control the Pin 13 LED of Uno by the signals received from the IR Sensor. The pin 13 LED should turn ON when we bring our hand close to the IR Sensor. Similar, it should turn OFF when we take our hand away. Let’s start writing the script for the same.

  1. Since we’re going to upload the code to Uno, we need the When Arduino Uno starts up hat blockSo, remove the when flag clicked block and drag and drop the When Arduino Uno starts up hat block above the script.
  2. Now,  the LED should turn ON when the sensor detects an object; otherwise, it should turn OFF. For this, we’ll use the if-else block. Go to the Control palette and drag and drop it inside the forever block.if-else block
  3. Drag and drop the read digital sensor block inside the hexagonal space of the if-else block and select IR form the drop-down menu.
  4. Next, drag and drop set digital pin () output block below the if arm of the if-else block. And set the output to LOW.
  5. Duplicate this block and drop it below the else arm. Then, set the output to HIGH. set output to high

Our script is complete! Let’s upload it to Uno.final script for pin 13 LED and sensor

Switch to Upload mode by toggling this button. Click on the Upload Code button to upload the code. Uploading

Uno’s Pin 13 LED turns ON when you bring your hand close to the IR sensor and it turns OFF as you take your hand away.Turn Arduino Pin 13 LED using IR Sensor

evive Explore
Explore: Try interfacing other sensors to Uno and see how they behave.

Project

You can try making a small project where you can turn ON the normal LED by connecting it to Uno via the reading of IR Sensor. We have created a small house and have attached an IR Sensor and an LED to it. The LED turns ON when the object comes near the IR sensor and immediately turns OFF when no object is detected. Turn LED ON using IR Sensor

Conclusion

In this tutorial, we saw how we can interface an IR sensor to Uno using PictoBlox.

Hope you had fun! 🙂

Share this Tutorial
Share on facebook
Facebook
Share on twitter
Twitter
Share on google
Google+
Share on pinterest
Pinterest
Share on reddit
Reddit
Share on print
Print
Related Projects & Tutorials
Blink Arudino Pin13 LED
Program Arduino Board with PictoBlox
This tutorial discusses how to interface Arduino Uno to PictoBlox and also understand the UI and modes of PictoBlox, and will see how to make Uno's pin 13 LED blink.
All articles loaded
No more articles to load
Featured Projects
All articles loaded
No more articles to load

This Post Has One Comment

Leave a Reply

Close Menu
×

Cart