agsdix-fas fa-child

Lamp with switch

In this activity, you will learn how to turn on a lamp with a switch.

info outline icon Basic Activity; Conditionals; Main Loop.

What are we going to do?

Are you a teacher?

Lesson Plan

Courses

  • Grades 3-12
  • 3rd Grade – 12th Grade Courses

Materials

  • Cellphone, tablet, or computer
  • Internet connection

Description

In this activity, students can have an introductory experience with Protobject, learning about visual programming and computer science in a safe and playful way using a device.

Educational Objectives

  • Understand the concepts of “conditional” and “sequence.”
  • Create a technological object (prototype) using a device.
  • Identify relationships between technology and the world around them.
  • Evaluate personal and peer work in individual or team projects.
  • Engage in dialogue and reflection on improvement ideas.

Introduction (10 minutes)

Welcome the students to the class and briefly introduce the day’s activity: “Today we will learn how to turn on a lamp using a switch with Protobject.”

We will start the class by providing technical knowledge to students for meaningful learning of the practical activity.

To open the class, we can begin with a question:

Has anyone heard of programming “conditionals” before?

With this knowledge, we will add more than one condition to the program and see what happens if one condition is met, but another is not. We will also see what happens if none are met. We can instruct the program on what to do if none of the conditions are met!

Explain that we can have many nested conditions (one after another) that will be checked in the order we program them.

Explain the following example:

“You’re going to the supermarket to buy rice, and there are brands A, B, and C in that order of preference. If there’s no type A rice, you buy type B, and if there’s none of that, you buy type C. If there’s none of them, you don’t buy rice.”

The above example corresponds to an everyday scenario where we make decisions based on the fulfillment or non-fulfillment of certain actions or statements.

Finally, to initiate the prototyping process and make them feel like protagonists of their learning, ask them:

Do you want to learn how to turn on a lamp with your cellphone?

Development (20-30 minutes)

Connect our device to the Protobject platform; this will allow us to control the LED lights on the cellphone screen with programming commands and turn them on under certain conditions.

To connect your mobile device to the Protobject platform, generate a QR code by clicking on ADD DEVICE and then LAMP.

Finally, scan the QR code with your cellphone.

Explain that if you don’t have a mobile device or tablet to connect, you can click on DO NOT HAVE A MOBILE DEVICE?

Remember to experiment with it yourself before asking the students to experiment with Protobject. This way, you can anticipate any questions that may arise from the students. You can also review the commented code if you have any doubts.

Great! Let’s turn on our LED lamp!

Explain that each block indicates an action.

With the if/do/else block, we provide a condition to the lamp, and if it’s not met, another action is executed.

To test the prototype, instruct the students to click on the activation button. The LED lamp should turn on and off with the switch!

Congratulations, you’ve tested your first prototype!

Conclusion (5-10 minutes)

Now that you’ve turned on a lamp with Protobject, challenge your students with a question:

What would happen if we didn’t add the last line in the programming block?

What would happen if we didn’t enable SimpleButton?

The challenge involves playing music along with the light. For this, we can add a PlaySound component… With a button, we can activate both!

Check out the solution to this challenge.

agsdix-fas fa-book-reader

Learn

Have you heard of conditionals in programming?

In the previous activity, we learned about simple conditionals: if, then.

In this activity, we will add more than one condition to the program: if, then, else.

The concept of “if, then, else” is a logical structure used in programming to make decisions and perform different actions based on the conditions that are met.

In simple terms, you could think of it as an instruction that says, “if something happens, then do this; otherwise, do something else.”

If the button is pressed, turn on the light; otherwise, turn it off.

For example, if you want to turn on a light in a house when a switch is activated, the structure would be: “if the switch is active, then turn on the light; otherwise, turn off the light.”

This means that if it’s detected that the switch is active, the action of turning on the light will be executed. But if it’s not detected that the switch is active, the action of turning off the light will be executed.

And how do we constantly check if the switch is active?

Sound familiar? With the main loop!

Make

Let’s create a prototype that allows us to turn on a light by pressing a button.

The first step is to add two smartphones, the first one to (1) simulate a button, and the second one to (2) simulate a light.

1

Press Add Device and select Lamp.

2

Press DevicesAdd Device and select Switch.

3

Remember that if you don’t have smartphones to scan the QR codes, you can press QR to open the components on the same computer.

plus square icon

Tip: In Protobject, you can add more components on the same smartphone by pressing the SCAN button as many times as you need.

Code composition

Click on question circle icon to open the comments that explain the code.
agsdi-bulb-options

Reflect

Now that you’ve learned about the conditionals if, then, else:

In what other scenarios could these conditionals be used?

plus square icon

Challenge: Modify this light with a switch by adding music that plays when the light is turned on.

 

Hint: Use the SoundPlayer device.

In the next activity, we will explore an alternative to the main loop.