How to Interface Sensors with Arduino using PictoBlox (Scratch Based Programming Software) | Ep: 02

Welcome back, everyone! In the previous video, we learned how to interface “Arduino Uno with PictoBlox” and wrote a script to control Uno’s “digital pin 13” LED. In this video, we’re going to interface “sensors to Uno using PictoBlox”. First, let’s know what they are. Sensors are extremely useful devices. They independently “detect” what happens in the surrounding environment and either “record” it or “indicate” it. Today, we’re going to write a script to interface an “IR(Proximity) sensor with Uno” and use it to control Uno’s “digital pin 13 LED”. Let’s begin! First, open “PictoBlox”. Then, connect Uno to your computer via a USB cable. Next, click on the “Board” button in the toolbar and select its name from the “drop-down menu”. Then, click on the “Connect” button and select the appropriate “port”. Now, let’s 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 “GND(ground) pin to Uno’s GND pin” using a black male-to-female jumper cable. Then, connect the sensor’s “OUT(Signal) pin to Uno’s digital pin 2” using a green male-to-female jumper cable. Let’s first write a test script for the “IR sensor”. We’ll make “Tobi”, the sprite, say out loud the sensor reading. Since we’re not uploading the test code to Uno, we’ll work in the “Stage mode”. It will let you interact with the sensor in “real-time”. First, drag and drop the “when flag clicked block” from the “Events palette”. Then, drag and drop the “forever block” from the “Control palette”. Next, from the “Looks palette”, drag and drop the “say () block” inside the “forever block”. Drag and drop the “read digital sensor () at () block” inside the space of the “say block” and select “IR” from the drop-down menu. 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. Once the firmware is uploaded, click on the “green flag” above the stage and take your hand “close” to the sensor. 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. If not, you need to “calibrate the sensor”. You can do that by turning the “potentiometer knob” using a screwdriver. Now, let’s move on to the script to control the LED. We’ll modify the test script instead of writing a new one. Since we’re going to upload the code to
Uno, we need the “When Arduino Uno starts up hat block”. So, “remove” the “when flag clicked block and drag and drop the “when Arduino Uno starts up hat block” above the script. Next, remove the “say block”. Now, the logic behind this script is that 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”. Drag and drop the “read digital sensor () at () block” inside the hexagonal space of the “if-else block” and select “IR” form the drop-down menu. Next, drag and drop “set digital pin () output as () block” “below” the “if arm” of the “if-else block”. And set the output to “LOW”. “Duplicate” this block and drop it below the else arm. Then, set the output to “HIGH”. Our script is complete! Let’s upload it to Uno. Switch to “Upload mode” by toggling this button. Click on the “Upload Code” button to upload the code. And we’re done! That’s all for now! In the next video, we’ll see how we can add motion in our projects. If you have any questions regarding this video, let us know in the comment section below and if you liked the video, don’t forget to give it a thumbs up! (and SUBSCRIBE for more educational videos like this)! I’ll see you in the next video. Bubye!


  1. Impulse Tech September 23, 2019 at 6:35 am

    Can you interface ultrasonic and humidity sensor with it using pictoblox

  2. My Techack October 12, 2019 at 5:39 pm

    Well explained!!!

Leave a Comment

Your email address will not be published. Required fields are marked *