ElectroBlocks/C2/Ultrasonic-Sensor/English

From Script | Spoken-Tutorial
Jump to: navigation, search
Visual Cue Narration
Slide 1

Title Slide

Welcome to the Spoken Tutorial on Ultrasonic Sensor using Electroblocks.
Slide 2

Learning Objectives

In this tutorial, we will learn to,
  1. Build a set of blocks for Ultrasonic sensor to detect an object in its range
  2. Check the output of the experiment using the simulator
Slide 3

System Requirements

To record this tutorial, I am using the following setup:
Slide 4

Prerequisite

To follow this tutorial,learner should have a basic knowledge of
  • ElectroBlocks
Type

https://electroblocks.org/

Let us open the ElectroBlocks website in the chrome browser.
Only narration Let us open a new blank project.
Slide 5

Required Sections

  • Logic
  • Motion
  • LED
  • Time
  • Math
We will need the following sections for this experiment.
Switch back to the Electroblocks interface.
Show Circuit Diagram.png This is the circuit diagram of an ultrasonic sensor experiment.

Here, when an object comes in the defined range of the sensor the buzzer is turned ON.

Otherwise the buzzer is turned OFF.

Let us build this circuit using ElectroBlocks.
Keep the loop block in the middle area

Click on the Logic section

Point to if-then-else block

Click on the Logic section.

Drag the if then else block and place inside the loop block.

Narration

Click on the Sensors section

Now we will add an Ultrasonic sensor block.

Click on the Sensors section and click on the Motion.

Select the Setup Ultrasonic Sensor block and drag it in the working area.

Point to the Setup Ultrasonic Sensor block.

Select the Setup Ultrasonic Sensor block and drag it to the working area.

The Setup Ultrasonic Sensor block is used to configure the Ultrasonic sensor in the circuit.

Point toward trigger pin and echo pin.

Point toward trigger pin

Point towards echo pin

In the setup block, the trigger pin and echo pin are used for distance measurement.

Trigger pin emits ultrasonic sound waves.

Echo pin receives the ultrasonic waves reflected from any object in its range.

Point to trigger pin and echo pin Here, the trigger' pin and echo pin are connected to pin 11 and 10 of the Arduino.
Only narration

Point towards the number box Click on the number box and change it to 5.

Point to simulation window

Point to the red rectangular box in front of the sensor.

We can change the distance by clicking on the Distance in Centimetres box.

Click on the box and change the value to 5.

Check the Copy All checkbox.

This setting will set the distance of the object to 5 centimeters for all the 3 loops.

In the simulation window, the 5 cm distance is displayed on the ultrasonic sensor.

Here the object is shown as a red rectangular box in front of the sensor.

Only narration

Click on the logic option

Select the (=) block and drag in the working area.

Place the block in the if section of if then else block.

We need a comparison block.

Click on the logic section.

The third block represents the comparison block.

Drag the comparison block and place it in the if section of the if then else block.

This will compare the distance value of the object from the sensor.

Only narration

Click on the Motion,select distance (cm) block.

Place this block in the first section of the logic block.

Point to dropdown option

Click on the dropdown option and select less than equal to option from the list.

Let us add a distance block.

Click on the Motion.

Drag the distance(cm) block and place this block in the first section of the comparison block.

Click on the drop down option and select less than equal to option from the list.

click on the math option available on the left side on the screen. Next, click on the Math section.

We will add the distance value.

Drag and place the first number block next to the less than equal to option.

Click on the number block and change to 10. Click on the number block and change to 10.

Click on the LED option.

Select the Turn a LED block.

Place the block in the ‘then’ section of the if then else block.

Next let us add a Buzzer to the circuit.

Click on the Add-ons and click on the Passive Buzzer.

Drag and drop the Turn Passive buzzer block to the then section of the if then else block.

By default the Buzzer is ON and connected to pin 9 of the arduino.

Right Click on the Turn a LED block and select the Duplicate option.

Place this new block in the else section of the If then else block.

Click on the dropdown option in the Turn Passive LED block and select the "Off" state.

Right click on the Turn Passive buzzer block and select the Duplicate option.

Place this new block in the else section of the If then else block.

Change the state of the Buzzer to OFF from the drop down option.

Click on the Code icon to view the auto-generated Arduino code for the experiment.

Highlight the code on right side

Click on the Code icon to view the automatically generated Arduino code.

The code includes self-explanatory comments for better understanding.

Click the Home icon and press the Play button to start the simulation.

Zoom and show the simulation area

Highlight hand symbol and pressed word

Click on the Home icon and press the Play button to start the simulation.

We can see the Buzzer is turned ON.

In the block we have specified the distance as 5 centimeters and the range is less than 10 which is true.

Only narration

Point towards Setup Ultrasonic sensor block.

Point towards Distance in the Centimeter box.

Click on the box and change the value to 20

Point towards the simulation window.

Point to square box.drag this square box to the start point of the simulation.

Let us change the distance value and check the simulation output.

In the Setup Ultrasonic sensor block, change the distance to 20 Centimeters.

In the simulation window, note that the object has moved to 20cms.

Let us simulate and see the output again.

Drag the box above the play button to the start position.

Click on the play button

Point to OFF state

Click on the Play button to see the output.

Notice that the Buzzer remains in OFF state as the distance is above 10 cms.

Narration only The XML file of this experiment is provided in the code files for your reference.
Slide 6

Summary

In this tutorial, we learnt about,

  1. Build a set of blocks for Ultrasonic sensor to detect an object in its range
  2. Check the output of experiment using simulator
This brings us to the end of this tutorial.

Let us summarise.

Slide 7

Assignment:

  • Turn ON the Buzzer when the ultrasonic sensor detects a distance equals to 10 cm.
  • Turn OFF the Buzzer if it is not 10 cm.
As an assignment, please do the following.
Slide 8

Thank You

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat