ElectroBlocks/C2/Servo-Motor/English

From Script | Spoken-Tutorial
Revision as of 16:56, 1 October 2025 by Nirmala Venkat (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Visual Cue Narration
Slide 1 Welcome to the Spoken Tutorial on Servo Motor using Electroblocks.
Slide 2:

Learning Objectives

In this tutorial, we will learn to,
  • Build a set of blocks to create a Servo motor experiment
  • Check the output of the experiment using the simulator
Slide 3:

System requirement

To record this tutorial, I am using
  • Ubuntu Linux OS version 22.04
  • Google Chrome Browser

A working internet connection to use the Electroblocks.

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 using the Chrome browser.
Only narration Let us open a new blank project.
Show Circuit Diagram.png

Point to the servo motor and then to the button

This is the circuit diagram of servo motor experiment.

The servo motor will rotate in a specified angle when the button is pressed.

Let us build this circuit using ElectroBlocks.

Slide:5

Required section

  • Logic
  • Button
  • Variables
  • Loops
  • Servo
  • Time
We will need the following sections for this experiment.
Switch back to the Electroblocks interface.
Keep the loop block in the middle area (compulsory)

Click on the Logic sectionDrag and drop the block in working area

Place the if-then block in the loop section.

Click on the Logic section.

Select the if-then block.

Drag and place it inside the loop block.

Click the Sensors section and point to lis

Select the Button setup block and drag it in the working area.

Point to pin 2

Click on the Sensors section and select the Button.

Select the Button setup block and drag it to the working area.

Note that by default the button is connected to pin 2 of the Arduino.

Select the button is pressed block and Place this block in the if section of the if-then block Go to the Button section.

Drag and place the button is pressed block in the if section of the if-then block.

Only narration

Click on the Loops option.

Click on the loop with i block

Drag and place this block in the then section of the if then block.

Click on the Loops section.

Drag and place the loop with block in the then section of if then block.

The loop with block creates a loop with a from value, to value and increment value.

Let us change the from value as 40 and to value as 140.

By default the increment value is 1. Let us change to 10.

This loop setup runs from 40 to 140, incrementing the I variable by 10 each time.

Only narration

Click on the Add-ons option

Click on the Servo option.

Next we will add a servo motor block.

Click on the Add-ons section and click on the Servo.

Drag and place the Rotate servo block in the do section of the loop with block.

Only narration

Point to servo and push button block

Click on the dropdown arrow in the Rotate servo block and change the pin number to pin 5

Point to the blocks and the circuit diagram

You will see both the Rotate servo and button setup block will turn to grey.

Also, you will not see a circuit in the simulation screen.

This is an error.

It occurs because both the servo motor and push button are connected to pin 2 of the Arduino.

To resolve this error, we will assign a different pin number to the servo motor.

Click on the dropdown arrow in the Rotate servo block and change the pin number to pin 5 . Now, all the blocks appear in normal condition, with the updated circuit diagram.

Point to rotate servo number block We can see the default degree as 50 which indicates the servo motor rotates to 50 degrees.

Let us set the limit between 40 to 140 degrees.

For that we need to use a variable i which we defined in the loop with block.

Remove the Rotate Servo number block

Click on the Variable option on the left-hand side of the screen.

Select the i block and drag it into the working area.

Place the i block inside the Rotate Servo block.

Only narration

First, delete the degrees block value by selecting the block and press the delete key.

Click on the Variable section and Select the i block.

Place the i block next to the degrees section of the Rotate servo block.

It sets the variable i for the loop with block to work.

Now the servo motor rotates from 40° to 140° when the push button is pressed.

Click on the Time section

drag and drop the Wait for 0.2 seconds block and place it below the Rotate servo block.

The delay block is required to ensure the servo motor rotates smoothly.

Click on the Time section.

Drag and drop the Wait for 0.2 seconds block and place it below the Rotate servo block.

Only narration

Right click on the loop with i block.

Select the duplicate option.

Place this block below the loop with the i block.

Point to 140 to 40

We need the servo motor to rotate in the opposite direction when it reaches 140 degrees.

We will duplicate the entire loop with block and change the values from 140 to 40 degrees.

Right click on the loop with block and select the duplicate option.

Place this block below the loop with block.

Change the from and to values as 140 and 40.

Now we have created the blocks required for this experiment.

Only Narration.

Click on Code Icon.

Zoom and show the code.

We will see the arduino code generated by electroblocks.

Click on the Code icon.

The code includes self-explanatory comments for better understanding.

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

Point to simulation window. When the push button is pressed, the servo motor rotates from 40 to 140 degrees.

We can see the i value displayed above the servo motor.

Notice that once it reaches 140-degrees, it will start to rotate in the reverse direction.

The XML file of this experiment is provided in the code files for your reference.
Slide:5

Summary

This brings us to the end of this tutorial.

Let us summarize.

Slide:6

Assignment:

As an assignment, please do the following
  • Change the parameters to rotate the servo motor from 0° to 180° and rotate back to 0°.
Slide 7:

Thank you

Thank you for joining.

Contributors and Content Editors

Madhurig, Nirmala Venkat