In this lesson, we will learn how to use IR tracking sensor to detect black/white color and send result to an I2C 1602 LCD. Such Black/White detection sensor is widely used for robot car line tracking applications which will be used in our future project.
We will make a framework and install LCD and a IR tracking sensor in the blocks. If IR tracking sensor detect ground color is White, LCD will display “White” , Otherwise LCD will display “Black”.
积木搭建同第8课,把超声波传感器改为循迹传感器
Circuit connection:
Firstly, please plug Osoyoo Magic I/O shield into UNO board as following:
Then connect the modules to the ports of the Magic I/O shield (please move the switch on the board to 5V) with two 4-pin PNP cables as below:
I2C LCD 1602 Display – I2C
IR tracking Sensor – D2
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 Show , make add a LCD prints block inside forever block, change text from “Hello World!” to “Distance:“:
Step 4: Click Control, add an if else block as following:
Step 5: Click Sensor category, add IR tracking sensor block below in if else block condition field,
Step 6: Click Show , make add 2 pcs LCD Setting Clear screen blocks inside if and else block, change line number to 2 and text to Black and White as following:
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 below IR tracking sensor, LCD will display ” White”, Put a black paper or tape under Tracking sensor, then LCD will display “Black”
DownLoad Url osoyoo.com