IR-controlled Robot | Maqueen Plus V2 Getting started Tutorial 11

1 2344 Easy

The invention of remote controllers allows people to operate devices from a certain distance, which brings a lot of convenience to our daily life. IR remote controller is the most commonly used one. In this chapter, we will use an IR remote controller with our Maqueen Plus V2 to make an "IR-controlled Robot".
 

Goal

1. Learn how to use function block

2. Learn how to use IR remote controller to control motor

Electronic Component

Command Learning

Hands-on Practice

We will use an IR remote controller to operate our Maqueen Plus V2, so we have to get the key value first. The decimal number of each key on the remote controller is shown below.

Step 1 Create a New Project

1. Input https://makecode.microbit.org/ into your browser to enter the MakeCode editor.

2. Click "new project" to enter the MakeCode programming interface.

3. Add the Maqueen Plus V2 library: https://github.com/DFRobot/pxt-DFRobot_MaqueenPlus_v20

Step 2 Programming

1. Drag the IR receive block to the editing section.

2. After we dragged the IR receive block to the editing section, there will be a variable named "message" appearing in the variable command section for storing the key value of the IR remote controller.

3. Create a function and name it "Move forward".

4. Create functions "Move backward", "Turn left" and "Turn right" in the same way above. The customized function will be shown in the editing section and the command block section.

5. How can we use the keys 2, 4, 6, and 8 on the IR remote controller to operate our Maqueen Plus V2 car? Let's draw a flowchart to analyze this question:

6. The flowchart above shows that we have to press the related key first, and then judge if the key value meets the condition. When the key value "message=17", call the function "Move forward"; when "message=20", call "turn left"; when "message=22", call "turn right"; when "message=25", call "move backward".The above program is just a framework

7. The above program is just a framework. Detailed operations need to be implemented in the functions. For example, press key 2, and the car moves forward. How to achieve that? Well, it's easy, just add a motor control block inside the move forward function.

            As long as we have a clear logic, the realization of the program will be not so hard. Try completing the program!

8. The complete program is shown below.

9. Name your project "IR-controlled robot" and save it.

Step 3 Download Program

Step 4 Effect Display

After completing all the above steps, use the IR remote controller to operate our Maqueen Plus V2!

Think & Explore

We may find that once we enabled the Maqueen Plus V2 to move, it won't stop until we turn off its power switch, which could be inconvenient for us to operate.

Now here is a task for you: use the red button on the remote controller to make Maqueen Plus V2 stop.

Tip: create a function to stop the motor!

 

Click Buy micro:Maqueen Plus V2 (Ni MH Rechargeable Battery) - an Advanced STEM Education Robot for micro:bit - DFRobot

Click Buy micro:Maqueen Plus V2 (18650 Battery) - an Advanced STEM Education Robot for micro:bit - DFRobot

Engage in learning the next Robot project:Motion Sensing Robot

Engage in learning the previous Robot project :  Tour of Crossroad

License
All Rights
Reserved
licensBg
1