Projects

Kid's Basics: Sensors & Servos

Rob Bell, Mike Hansell and Kayla Gourlay

Issue 13, July 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

Turning learning into child’s play!

BUILD TIME: 2 Hours
DIFFICULTY RATING: BEGINNER

Welcome to a very special project, that’s designed for kids (with a little guidance from someone older). Using a few fun sensors and servo motors, this project aims to welcome even the newest beginner into the world of Arduino.

We’re assuming very little (or zero) electronics knowledge, and so will try to walk through everything carefully, in order to ensure your success. Basic computer skills are assumed (as is access to a computer, with internet connection, to use the software). If you have trouble following any of the software installation steps, then you may like to seek further assistance from a family member or friend. There are a few too many potential challenges for us to detail every possibility here.

The projects provided here are all progressive, directly following on from the preceding build. You can skip ahead, but this article is written expecting sequential build construction, so you may miss out on some explanations and tips along the way, if you do.

Craft materials & TOOLS Required:
1 × Computer Running Windows, Mac, or Linux
1 × Pair of Scissors / Artwork Knife
1 × Glue Stick
6 × A4 Sheets of Cardboard (Thick)
1 × Pack Blu-Tack / Tape etc.
Markers, Pencils or Crayons (if using outlined versions for colouring)
Electronics PARTS Required:JaycarAltronicsCore Electronics
1 × Arduino UNO or EquivalentXC4410Z6240018-UNO-R3
1 × SG90 Servo MotorYM2758Z6392SER0043
1 × Ultrasonic ModuleXC4442Z6322CE05112
1 × PIR ModuleXC4444Z6382SS113990020
1 × Mixed Jumper WiresWC6027P1017-
1 × Small Prototyping BreadboardPB8820P1002CE05102

Electronics PARTS Required:

You will also need a USB cable compatible with your Arduino UNO, which may or may not be supplied with the Arduino UNO itself. Power for these projects is provided from your computer. No additional power is required.

SOFTWARE PREREQUISITES

You will need to have an Arduino UNO (or similar), and the Arduino IDE installed on your computer. You can download it for free, from www.arduino.cc/en/Main/Software. Follow the prompts to install it. This is where we will load code, and compile it onto the Arduino.

With your Arduino connected to your computer via USB, go to Tools › Board and ensure Arduino / Genuino UNO is selected, or the appropriate board for what you are using.

software

Then also select Tools › Port and click on the one that shows USB. The precise wording will depend on your operating system.

port selection

In order to load code onto your Arduino, open the Arduino IDE once installed.

Go to File › Open and select the file noted in the article (Each file is within a folder of the same name).

COLOURING & PREPARATION

You will notice that there are printable parts. These can be printed on any home printer on an A4 sheet. While these are not critically essential, it helps make the builds more fun than simply something moving without any context.

We have provided coloured, and non-coloured illustrations for the projects. This is to allow you to either add-on the fun of colouring the interactive scenes, or simply get on with the interactive portion. The choice is yours.

For each build, you’ll need to bond the backing card and interactive elements to some cardboard. This will help provide structural integrity to the overall project. The paper itself is too flexible and will simply bend. The cardboard should be thick enough to hold itself up, but not so thick you cannot easily cut it with scissors.

build one

Build 1:

Servo Motor

This build introduces servo motors. Usually referred to as simply a “servo”, they provide predictable and repeatable movement. There are different types of servo motors, but these ones are simple low-cost units, which have a rotational range of 180°. We can send a command to a servo from our Arduino to tell it to go to a specific angle.

For this build, we’ll use a stage scene, and your choice of a guitarist or ballet dancer. We’re going to use the servo to make the figure move a little within the scene.

CONSTRUCTION

STEP 1:

step 1

Mount the scene to your cardboard, as well as your chosen character. We’ll use the guitarist for our example.

STEP 2:

step 2

Cut out your chosen character.

STEP 3:

step 3

Cut a small hole where indicated on the scene artwork, and rip away any excess paper (take care not to tear the main scene).

STEP 4:

step 4

Mount the servo motor to the back of the scene, so that the gear pokes through the scene. Again we can use tape, Blu-Tack, or any other removable adhesive since we will reuse the servo motor.

STEP 5:

step 5

Mount the servo horn to the back of the character using tape, Blu-Tack, or anything else you have on hand. Glue can be used, however we want to reuse the servo horn, so it’s not recommended.

STEP 6:

step 6

Push the character onto the servo motor, taking care to align the servo horn so it pushes firmly onto the servo. You may need to support the servo motor when doing so.

STEP 7:

step 7

Complete the wiring as shown in the diagram. Occasionally colours will vary, however most servo motors are consistent in their wire colour usage.

Note: Where your wires go is important; the colour of wire you use is not. Different wiring packs will have different colours so don’t worry about variation in colour, as long as they’re going to the right place.

Well done! You’re now ready to make it work!

THE CODE

We have provided “kids_basics_build_1.ino” in the digital resources. Open this file in your Arduino IDE, and click “Upload”. This will load it into your Arduino UNO. If you receive errors doing so, ensure you followed the board setup steps on the first page under “Software prerequisites”. This will eliminate the majority of issues you may have, if you’re not familiar with the Arduino software.

Note: As soon as you click UPLOAD and the process has finished (only takes a few seconds), the servo motor should spring to life.

SUMMARY

We’re not going to go into too much depth about how this code does what it does. It’s fairly straight forward, but we’re also not trying to teach you how to code right now either.

Essentially we just tell the servo motor to go back and forth, continuously, forever. It will keep doing this until you turn off the Arduino.

Congratulations! You have just successfully built your first circuit using an Arduino and a servo motor.

build 2

Build 2:

Passive Infrared Detectors

Building on what we just learned about servo motors, we’re going to add a passive infrared detector (PIR) into the system. These are just like the ones you’ll find in alarm systems. They detect movement using infrared light, which is invisible to the naked eye. They can’t tell the difference between fast or slow moving objects, but simply say “hey, we detect some movement”. But that’s all we need to do for now.

In the first build, we really just made the servo motor go back and forth. In this build we’ll use the PIR into the system.

By doing this, we can start the servo movement only when motion is detected. It will run for a few seconds, then stop. After a few seconds, if you start moving again, the PIR will pick up the movement and the servo motor will move again for a period.

CONSTRUCTION

STEP 1:

step 1

Mount your chosen scene to the cardboard. The soccer player and dinosaur have different mounting points for the electronics, but are otherwise interchangeable. We’ll use the soccer player for our example.

STEP 2:

description

Cut out your chosen character. Cut the two holes in your scene and trim excess paper. These are for our two interactive elements.

STEP 3:

step 3

Mount the servo to the back of the scene by pushing the gear head through, and fasten in place using tape or Blu-Tack.

STEP 4:

step 4

Mount the servo horn to the back of the character using tape or Blu-Tack. Positioning it approximately as shown in the photos, will help achieve the overall effect.

STEP 5:

step 5

Mount the PIR from the back of the scene. Orientation doesn’t really matter, however having the pins on the back facing the bottom of the scene may assist with wiring.

STEP 6:

step 6

Push the dinosaur tail or soccer player’s leg onto the servo motor, taking care to align the servo horn so it pushes firmly on to the servo. You may need to support the servo motor when doing so.

STEP 7:

step 7

Complete the wiring as shown in the diagram. Occasionally colours will vary, however most servo motors are consistent in their wire colour usage.

Note: Where your wires go is important; the colour of wire you use is not. Different wiring packs will have different colours, so don’t worry about variation in colour as long as they’re going to the right place.

Great stuff! You’re now ready to make it work!

fritzing

THE CODE

We have provided “kids_basics_build_2.ino” in the digital resources. Open this file in your Arduino IDE, and click “Upload”. This will load it into your Arduino UNO. If you receive errors doing so, ensure you followed the board setup steps on the first page under “Software prerequisites”. This will eliminate the majority of issues you may have, if you’re not familiar with the Arduino software.

This code expands upon the first build, to read the status of the PIR. If no motion is detected, the servo motor will not be activated. The status of the PIR is checked after each sequence to ensure it is still triggered.

Depending on how much movement is going on when you upload, your servo motor may spring to life instantly. If it doesn’t, then make some motion! You should see the servo fire up for a few seconds, then stop again.

final

SUMMARY

This pattern will repeat as long as you like. You can also experiment seeing what distance the PIR will work from, to detect you.

This setup demonstrates how we can trigger actions based on physical movement in a room.

build 3

Build 3:

Ultrasonic Sensors

In this third build, we’re going to add a new sensor: the ultrasonic sensor. “Ultrasonic” means “sound waves with a frequency above the upper limit of human hearing”. These sensors send out an ultrasonic sound wave, then listen to the “echo” from objects in the environment.

Since we know the speed of sound, (343m per second), we can fairly accurately determine how near or far an object is. For instance, if the echo takes 1 second to come back to us, we can safely assume it’s 171.5m away (since it has to travel there and back, all distances are halved). In reality, we’re working in fractions of a second, as we’re more likely to be measuring 1m to 2m.

Of course it’s worth noting, that an ultrasonic sensor can’t really discern between different objects. Most of the time it will pick up the nearest object and use that for any calculations.

CONSTRUCTION

STEP 1:

step 1

Mount your chosen scene to the cardboard. There is a scene and moving element for both the unicorn and the dog. We’ll use the dog for our example.

STEP 2:

step 2

Cut out the moving part required for your scene, and each of the marked holes on your scene (there are four in total), trimming away any excess paper.

STEP 3:

step 3

Mount the servo to the back of the scene by pushing the gear head through, and fasten in place using tape or Blu-Tack.

STEP 4:

step 4

Mount the servo horn to the back of the moving part using tape or Blu-Tack. Positioning it approximately as shown in the photos, will help with the overall effect (but you can adjust later).

STEP 5:

step 5

Mount the PIR from the back of the scene. Orientation doesn’t really matter, however having the pins on the back facing the bottom of the scene may assist with wiring.

STEP 6:

step 6

Mount the ultrasonic sensor from the back of the scene. As with the PIR, orientation doesn’t really matter, however having the pins pointing down can assist with wiring.

STEP 7:

step 7

Push the moving part on to the front of the servo motor.

STEP 8:

step 8

Complete the wiring as shown in the diagram. Occasionally colours will vary, however most servo motors are consistent in their wire colour usage.

fritzing
Note: Where your wires go is important; the colour of wire you use is not. Different wiring packs will have different colours, so don’t worry about variation in colour as long as they’re going to the right place.

THE CODE

We have provided “kids_basics_build_3.ino” in the digital resources. Open this file in your Arduino IDE, and click “Upload”. This will load it into your Arduino UNO. If you receive errors doing so, ensure you followed the board setup steps on the first page under “Software prerequisites”. This will eliminate the majority of issues you may have if, you’re not familiar with the Arduino software.

This code expands upon the second build, to also utilise the ultrasonic sensor to vary the rate of the servo motor. We still use the PIR to engage the servo, however the ultrasonic sensor determines how fast it moves. Just as an excited dog will often become more excited, the closer you come!

SUMMARY

Here we have combined two different sensors, to cause variable changes to the servo motor.

Not only do we stop and start based on the detection of movement by the PIR, but the rate of movement is now affected by the reading from the ultrasonic sensor. The closer you get, the faster it moves. Awesome!

WHERE TO FROM HERE?

You have now experienced the fundamentals of inputs and outputs using an Arduino microcontroller. If you enjoyed this process, it’s time to expand your knowledge.

There are a range of starter packs and educational tools on the market that will help you continue on your Arduino journey.