In this lesson, we will show you how to program tracking sensor with blocks. When tracking sensor detected white color, LED will turn on, otherwise LED will turn off.
The OSOYOO IR Track Sensor is essentially a combination of IR LED and IR detector which can be used to detect black and white colors. It works by sending a beam of IR light from IR LED toward the surface. The IR detector will get the reflection signal from surface and judge if the surface is white or black color.
Firstly, please plug Osoyoo Magic I/O shield into UNO board as following:
Step 1) If you haven’t install mBlock software in your PC, please read Lesson 1, download and install the software.
Step 2) Run the mBlock PC software by double click the lovely Panda icon. Drag and Drop osoyoo_uno_mext file(downloaded in Step 1) to mBlock software as following:
Now you will see a new device firmware in mBlock, see following picture:
Now mBlock software and OSOYOO_UNO device firmware have been successfully installed in our PC!
Now we will show you how to use blocks to turn above idea into reality.
Step 1: Click Control, then Drag and drop Forever block to programming area as following:
Step 2: Click Events, add when Arduino Uno starts up block to the top:
Step 3: Click Control, add if else then block inside forever block:
Step 4: Click Sensor, add IR tracking Sensor Pin block inside if condition area , then change button pin to No.2:
Step 5: Click Light category, add LED pin 13 HIGH block inside if and else block ,
change LED pin to No. 8, change upper LED value to LOW:
Now we have completed the block programming. The final blocks look like following:
Upload the program to Arduino
1)you need click the Connect button in the bottom of the mBlock software, you will see a USB window pop up,
2) select Show all connectable device check box , then a device drop-down menu will show up,
3) select your Arduino port from device drop-down menu
4) click Connect button to connect your PC to Arduino
5)After you PC is connected to Arduino UNO board, please click Upload button in the bottom of your software, then the code will be uploaded to Arduino UNO board:
Test the program:
Put a white paper close to the IR tracking sensor, the LED in D8 will turn on. Remove the white paper, then LED will turn off.
How to Adjust the sensitivity:
There is a sensitivity screw on each IR tracking sensor, you can use a screw driver to adjust sensitivity. The best status is that: When the module gets on a black line, it output high and the corresponding LED stays off and when sensor is over white area, the LED will turn on. Check following video:
DownLoad Url osoyoo.com