Skip to main content

Case 08: IR Remote Control Car

Introduction

Control Cutebot to drive by remote control.

Programming Preparation

Please refer to:Preparing Programming Environment

Infrared remote control key value table

keyreturn valuekeyreturn valuekeyreturn value
Power11
MENU12
+13UP14Return15
Left16OK17Right18
-19Down2000
112233
445566
778899

Sample code

from cutebot import *

# Create a sample for Cutebot category
cutebot = Cutebot()

# While true, keep detecting the values received by the IR receiver
# Control the route of the Cutebot based on the received value
while True:
Ir = cutebot.get_ir_value()
if Ir == 14:
cutebot.set_speed(50, 50)
if Ir == 16:
cutebot.set_speed(-30, 30)
if Ir == 17:
cutebot.set_speed(0, 0)
if Ir == 18:
cutebot.set_speed(30, -30)
if Ir == 20:
cutebot.set_speed(-50, -50)

Code details

  1. Import the modules that we need for the program: cutebot module contains the classes and functions that operate on the Cutebot smart car.
from cutebot import *
  1. Create a sample for Cutebot category.
cutebot = Cutebot()
  1. While true, keep detecting the values received by the IR receiver.Control the route of the Cutebot based on the received value.
while True:
Ir = cutebot.get_ir_value()
if Ir == 14:
cutebot.set_speed(50, 50)
if Ir == 16:
cutebot.set_speed(-30, 30)
if Ir == 17:
cutebot.set_speed(0, 0)
if Ir == 18:
cutebot.set_speed(30, -30)
if Ir == 20:
cutebot.set_speed(-50, -50)

Results

After turning on the power, the Cutebot is controlled by IR remote control to drive.

Exploration

Is it possible to control more functions of the Cutebot by IR remote control?