Buy from US Buy from UK Buy from DE Buy from IT Buy from FR Buy from ES Buy from JP

The OSOYOO Magic I/O Shield for Arduino is a powerful board for the beginners. With this Magic board, we can  easily connect various sensors and actuators much easier than before.

In this lesson, we will show how to make an ultrasonic range finder and display the distance on the screen.

If you want to display the results from the HC-SR04 Ultrasonic Sensor on an I2C LCD you can use the following source.

First, please plug Osoyoo Magic I/O shield into OSOYOO Basic Board for Arduino:

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

Ultrasonic Sensor – D7D8

More information about I2C LCD 1602 Display, please see Lesson14.

Notice: Shut off your battery or Unplug your power adapter when upload sketch code to OSOYOO Basic Board for Arduino.

After above operations are completed, connect the OSOYOO Basic Board for Arduino to your computer using the USB cable. The green power LED (labelled PWR) should go on.

Open the Graphical Programming software Mixly, iMixly is not English, you should change the language first:

You can download the code directly, then click “Open” in Mixly to choose the code you download:

Download the Code

Or you can do as following operations:

  1. Click “Control” block;
  2. Drag “Setup” to the blank space;
  3. Click “Monitor” block;
  4. Drag the “setup LCD” under “Setup” block, fit the two blocks;
  5. Click “Variables” block;
  6. Drag the “Declare” block under “Setup LCD” block, fit the two blocks, and edit the parameter to “Declare Dist as float value”.

  1. Click “Variables” block;
  2. Drag the first “dist” to the blank space.
  3. Click “Sensor” block;
  4. Drag the “Ultrasonic ranging” block to fit the “dist” block;
  5. Click “Monitor” block to drag “LCD mylcd clear“to fit the “dist” block;
  6. Click “Monitor” block again to drag “LCD mylcd print line” to fit “LCD mylcd clear” block.

  1. Edit the text of “LCD mylcd print line1″ to “Distance(cm):“;
  2. Right click the text block of “LCD mylcd print line2″ to delete the block;
  3. Click “Variables” block;
  4. Drag the second “dist” block to fit “LCD mylcd print line2″;
  5. Click “Control” block;
  6. Drag “Delay” to fit the “LCD mylcd print line”.

The whole program blocks are as following:

After programming, you can click the “<” button to check the corresponding code on the right bar.

After above operations are completed, do as follows:

  1. Click Save after programming is done.
  2. Select the board type and serial port before uploading. For instause OSOYOO Basic Board for Arduino, just select Arduino/Genuino Uno: if you use a Mega2560, select Arduino/Genuino Mega or Mega2560.
  3. Select the serial device of the OSOYOO Basic Board for Arduino from the COM menu. This is likely to be COM3 or higher (COM1 and COM2 are usually reserved for hardware serial ports). To find out, you can disconnect your OSOYOO Basic Board for Arduino and re-open the menu; the entry that disappears should be the OSOYOO Basic Board for Arduino. Reconnect the board and select that serial port.
  4. Next,upload the code. If the uploading fails, check and correct the code according to the prompts.
  5. Finally, the status will change to ‘Upload success!’.

A few seconds after the upload finishes, move a board close to the sensor or remove it farther. You can see the value displayed on the LCD changes accordingly; it indicates the distance between the board and the ultrasonic sensor.