How to Interface Ultrasonic Sensor with evive in PictoBlox

About This Tutorial
This tutorial discusses what are ultrasonic sensors, and how to interface them with evive in PictoBlox with the help of a sample program in Stage mode.
Tutorial Info

Components Required


An ultrasonic sensor is a device that detects an object and measures the distance to it. It measures the distance by emitting ultrasound and receiving the wave that the object reflects. By recording the time elapsed between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sensor and the object.

HC-SR04 Ultrasonic Sensor Module

The HC-SR04 ultrasonic sensor uses sonar to measure the distance to an object. It emits ultrasound at 40 000 Hz which travels through the air and if there is an object or obstacle in its path the wave will bounce back to the module.

The HC-SR04 Ultrasonic Module has 4 pins:

  • VCC
  • Trig
  • Echo
  • Ground (GND)

The Ground (GND) and the VCC pins of the module must be connected to the Ground and the 5V pins on evive respectively and the Trig and Echo pins to any 2 Digital I/O pins.

Interfacing Ultrasonic Sensor

Activity: Displaying the Distance Measured on the TFT Screen


Follow the steps below to connect the Ultrasonic sensor to evive:

  1. Take the four male-to-female jumper wires and connect their female ends to the 4 pins of the sensor.
  2. Take the free male end of the wire connected to the VCC pin and connect it to the 5V pin on evive.
  3. Connect the free male end of the wire connected to the Trig pin and connect it to Digital I/O pin 2.
  4. Connect the free male end of the wire connected to the Echo pin and connect it to Digital I/O pin 3.
  5. Take the free male of the wire connected to the GND pin and connect it to the GND pin on evive.

Below is the circuit diagram:



evive Notes Icon
When working with evive on PictoBlox for the very first time, or if you’ve previously uploaded another code to evive, you must upload the firmware in order to upload new code to it. You can find the procedure for the same HERE.

Follow the steps below to write the script:

  1. Connect evive to your computer and open PictoBlox; if already open and working on a project, save that project. Then, click on New.
  2. Go to the toolbar and click on the Board menu. Then select evive as your board. Pictoblox Board Selection
  3. Next, click on the Connect menu and from the fly-out menu, select the Port to which evive is connected e.g. COMXX or ttyXX.Once you select the port, the icon beside the Connect tab will become connected.Connect-Disconnect Icon
  4. Go to the Events palette and drag and drop the when flag clicked block.
  5. Next, go to the Display palette and drag and drop the fill screen with () color block. You can change the background color if you want to by clicking on the color and moving the sliders in the drop-down menu.Selecting Background Colour
  6. From the Control palette, drag and drop the forever block below the fill screen with () color block.
  7. Go to the Display palette and drag and drop the set cursor at () () block inside the forever block.
  8. Then, drag and drop the write () block below the set cursor at () () block.
  9. Go to the Operators palette and drag and drop the join () () block inside the space of the write () block. In the first space of the join () () block, write ‘Distance = ‘  and in the second space drag and drop another join () () block.
  10. From the same palette, drag and drop the round () block in the first space of the second join () () block.
  11. Now, to read the distance with the help of the ultrasonic sensor, you need to add a new palette/extension from the extension library. Click on the purple button in the bottom-left corner of the window and add the Sensors extension. Now from this extension, drag and drop the get ultrasonic sensor distance (cm) | trig () , echo () block inside the round () block.join blocks
  12. Next, go to the Looks palette and drag and drop the say () for () secs block below the write () block. Then, repeat steps through 10.

Below is the complete script:

Interfacing Ultrasonic Sensor with evive in PictoBlox

Click on the green flag to run the script.

Click on the red octagon, next to the green flag to stop the script.


It this tutorial, you learned how to interface an Ultrasonic sensor with evive using PictoBlox.

Hope you had fun! 🙂

Share this Tutorial
Share on facebook
Share on twitter
Share on google
Share on pinterest
Share on reddit
Share on print
Related Projects & Tutorials
PictoBlox – Stage Mode
In this tutorial, you learned about PictoBlox's Stage mode and how to control hardware in real-time using a USB cable or over Bluetooth. 
PictoBlox – Upload Mode
In this tutorial, you'll see what is PictoBlox's Upload mode and how to use it to control our hardware wirelessly, i.e. without being connected to computer.
Interfacing Dabble with evive
In this tutorial, we learned how to control actuators or send commands to them wirelessly via a Smartphone using Dabble.
All articles loaded
No more articles to load
Featured Projects
All articles loaded
No more articles to load

Leave a Reply

Close Menu


Get an extra 10% OFF + FREE shipping worldwide on orders above $100.