Using the Remote

How to use Sparki with it's remote.

SparkiDuino
Easy

Lessons You Should Know

Introduction

Sparki’s comes with an Infrared Remote Control, which works with Sparki’s Infrared Remote Receiver.

This lesson will cover how the remote works, how to test it out, how to program your own code for the remote, and an example that fully uses the remote to turn Sparki into a remote-controlled robot (it’s default program when it comes out of the box.

How it Works

Each button on the remote sends a certain code to Sparki, which it can receive with its infrared remote receiver. The codes each button on the remote sends is listed below:

Remote Cleared

The code the remote sends is a rapidly blinking infrared light. It’s an invisible flashlight that blinks really, really fast (38,000 times a second) in different patterns, depending on which button is pressed. By measuring the amount of time between each flashing, Sparki can tell if each burst is meant to be a 1 or a 0, known as bits::

Signal Diagram

Sparki counts these flashes until 32bits have been counted, then turns this into a number. Specifically, Sparki uses the NEC infrared code protocol

Using the Remote

With the basic Sparki code in place, you can measure an infrared sensor by using this command:

This command returns the last code that was sent to Sparki. It returns this number in the form of an integer. If there has not been a code sent since the last time Sparki ran this command, it will send back a -1.SparkiDuino already has code examples for you to use: File > Examples > Remote

In order for the remote to be able to talk to the robot, the remote needs to have an unobstructed line of sight to the infrared receiver. This is because anything in between the remote and Sparki will block the infrared light that the remote is emitting. We can’t see them, but there are a bunch of infrared photons that come out of the remote whenever you press one of the buttons. While it isn’t important that the robot is facing towards you, the infrared signal probably won’t talk to the robot through a table, for example.

Testing the Remote

Here’s a basic code example. The purpose is to show the IR code that Sparki is recieving from the remote. We’ll ready the IR code from the remote, then display it on the LCD. This code is useful if you’re not sure if the remote working, or just as a starting place for your own remote code.

Controlling Sparki

We can expand on that program to include almost all of Sparki’s visible functions. Below is example code that takes the codes, and does an action for each code. This is also the code that comes pre-programmed on Sparki.

Remember when having Sparki move: it needs fresh batteries, it’s On/Off Switch ‘On’, and to be watched to prevent it from falling off edges.



After uploading this code (or before you’ve ever uploaded any code before – this is the code that comes with Sparki), you can now use the buttons to do the following:/

The top buttons of the remote are laid out to control the Sparki’s direction of movement and grippers. Try using the different arrow buttons to see what happens with your robot. Remember, the stop button stops the movement of both the robot and the grippers in case Sparki starts to get away from you.

sparki remote movement04

Here is how the number commands work:

1: RGB LED turns red.

sparki rgb red 02

2: RGB LED turns green.

sparki rgb green

3: RGB LED turns blue.

sparki rgb blue

4: Sparki turns the rangefinder to the left(using Sparki’s servo).

sparki remote move center

5: Sparki turns the rangefinder to the center (using Sparki’s servo).

sparki remote move center

6: Sparki turns the rangefinder to the right (using Sparki’s servo).

sparki remote move right

7: Stop the included program (autonomous room navigation).

8: Run the included program (autonomous room navigation).

9: Buzzer ring.

sparki remote buzzer

The +, 0 and – buttons do not do anything:

sparki remote do nothing