Arduino Controlled Greeter

Make a servo-powered greeter with Arduino!


Setup and Supplies

In this project, you’re going to be using an Arduino and micro servo motor to create a waving popsicle stick arm. You’re going to make the basic ‘skeleton’ which can then be extended into several other fun projects! This fun and flexible Arduino project introduces several important Arduino concepts while still offering a high level of customization and modification.

project sample-400px1

Build time:

Approximately 45-50 minutes

Skills needed:

  • Basic computer skills
  • Basic programming knowledge – this can be developed through the activity!
  • Basic understanding of electronics – this can be developed through the activity!

Tools:

  • Computer
  • Arduino IDE – the programming environment for Arduino
  • Arduino Uno board – the board used for this project
  • Micro servo motor
  • Popsicle stick – this is the motor ‘arm’
  • Basic crafting materials – there are many integration options for these materials

[hr]

How to Create a Servo-Powered Arm Using Arduino

bcpl_-_iot_-_step_2-400px6

Step 1: Download the Arduino IDE

Navigate to the Arduino download page and select the download for whichever OS you’re running. You can also access this page by going to the Arduino homepage and selecting the Download tab.

bcpl_-_iot_-_arduino_step_2-400px1

Step 2: Open the Arduino IDE

Once you’ve downloaded and installed the Arduino IDE, go ahead and open it up. The icon is a light blue circle with a white infinity in the middle. If it’s your first time opening the IDE, it may take a moment to open. If you get a message about creating a new network connectiong, go ahead and click “Allow.”

bcpl_-_iot_-_line_numbers-400px3

Step 3: Turn on line numbers (Optional)

If your sketch already show line numbers, you can skip to Step 4. If not, you can turn them on by following these steps:

  • Click on Arduino in the menu at the top of the IDE.
  • Click on the Preferences sub-menu to open the IDE preferences.
  • Make sure that “Display line numbers” is selected.
  • Click the ‘Ok’ button in the bottom right to save.

bcpl_-_iot_-_gist-400px1

Step 4: Get the project code

For this project, you’re jumping in and modifying some existing code. Don’t worry if you don’t understand all of the code. You’ll gradually increase your understanding of Arduino programming by experimenting with code that already exists. The code file for this project has lots of helpful comments that you can read that explain several of the key concepts that are used.

Navigate to this link to access the project code:

BCPL Workshop: Servo Sketch gist on GitHub

bcpl_-_iot_-_gist_copy-400px1

Step 5: Copy the entire gist code

Gist is a great way to share code with your learners. For this project, go ahead and copy the entirety of the code (lines 1 – 41).

To copy, use CMD + C on a Mac, or Ctrl + C on Windows.

Note: Don’t close the browser window incase you need to repeat this process!

bcpl_-_iot_-_arduino_new_1-400px1

bcpl_-_iot_-_arduino_new_2-400px2

Step 6: Create a new Arduino sketch

Open the Arduino IDE and create a new sketch. To do this, click on the File menu and then select New. Once you’ve done this, a new sketch will pop up. After this new sketch appears, you can close the previous sketch.

bcpl_-_iot_-_pasted_code_sketch-400px4

Step 7: Paste the code into the new sketch

Once you’ve created the new sketch, paste the entire copied code into the sketch. You should replace everything- don’t leave the original setup and loop functions or the code won’t work. Check that your code matches the image before proceeding.

As a quick check, line 6 of your sketch should read: “#include //This is necessary when working with servos. It includes the servo library.”

Arduino_Connection_To_Computer-small-400px1

Step 8: Connect the Arduino to your computer

Connect the Arduino to your computer via USB. You’ll see some lights on your Arduino begin to glow. If you see these, your Arduino is now being powered by your computer’s USB! If you don’t see any lights on the Arduino, try unplugging it and reconnecting.

Arduino_Board_Selector-small-400px1

Arduino_Port_Selector-small-400px2

bcpl_workshop_-_iot_-_upload-400px1

Step 9: Uploading the sketch to the Arduino

Once your board is connected, you need to upload the sketch to the board. First, you need to check to make sure that the board and port is detected by the IDE. To do this, follow these steps:

  • Click the Tools menu in the IDE and scroll down to the Boards: submenu. Make sure that it says Board: Arduino/Genuino Uno. If it doesn’t, hover over the Board entry and choose “Arduino/Genuino Uno” from the menu.
  • Next, make sure that your port is correct. There are a few different options. Usually, the IDE will auto-detect the board and set this. If this is the case, it’ll have the Arduino/Genuino Uno listed in the popup menu linked to Ports. If you don’t see this, hover over Ports and select the board that is linked to your USB port.
  • If you don’t see any board on the USB port, close the IDE and unplug the Arduino. Plug it back in and re-open the IDE.

Once the board and port are set, go ahead and click the Upload button at the top right of the IDE. It looks like an arrow. After you click this the sketch will begin to upload to the board. This process sometimes takes a minute or two. You’ll see it say “Done uploading” at the bottom of the IDE when this completes.

bcpl workshop - iot - servo 1

bcpl workshop - iot -  servo 2

Step 10: Assembling the servo

The next step is to do the wiring for the servo motor. For this project, you’re going to attach the servo directly to the Arduino board. The first thing you need to do is to examine the wires that are attached to the servo. There are 3 wires bundled together and they are brown, red, and orange.

For this particular servo, here is the polarity:

  • Brown: Ground
  • Red: Power (5V)
  • Orange: Signal/data

If your servo doesn’t have the hinge attached, find the single-arm hinge and just pop it onto the top of the servo. It snaps into place with minimal effort.

Use 3 jumper wires and attach them to the end of the servo wire bundle. The jumper wire color doesn’t matter, but it’s common to use black for your ground and red for power. Just remember which color jumper you attach to each servo wire.

bcpl workshop - iot - servo 4

Step 11: Attaching the ‘arm’

Before attaching the servo to the Arduino, you’ll want to build out the popsicle stick ‘arm.’ You may need to make some adjustments to the exact positioning of the popsicle stick based on your project, but it’s generally easier to attach it at this point.

Tape the popsicle stick to the servo hinge. The servo in this example uses a single-armed hinge. If you only have the full servo hinges (double sided) you can just cut off one side of the arm.

However you choose to align and tape the popsicle stick is up to you. You may need to adjust it throughout your project. You’ll definitely need to tape it in such a way that the servo lies completely on it’s back, as in the image. Otherwise your servo will not be sturdy.

bcpl workshop - iot - arduino

bcpl_-_igd_-_arduino_closeup-400px1

Step 12: Connecting the servo to the Arduino

Now that your servo arm is ready to go, you need to connect it to the Arduino. To make things easier, it’s beneficial to unplug your Arduino from the USB so that you can easily maneuver the board while working.

  • First, refresh yourself on the polarity of the servo. Remember which jumper wires you attached to the servo wires. Remember that brown: ground, red: power, orange: data/signal.
  • Connect the jumper wire attached to the brown servo wire to the GND pin on the Arduino.
  • Connect the jumper wire attached to the red servo wire to the 5V pin on the Arduino. The GND and 5V pins are next to each other on the Arduino board.
  • Finally, connect the jumper wire attached to the orange servo wire to pin 9 on the Arduino.

The pin that connects to the signal/data on the servo must match the pin that’s used in the sketch’s code. If you want to change the pin, you need to also modify it in the code on line 14 in the void setup():

bcpl_workshop_-_iot_-_loop_modify-400px1

Step 13: Modify the code!

The modifications that you make depend on what you want to do for your project. This guide is for the basic servo ‘waving arm’ that can be used and integrated into several projects.

The code comments contain some suggestions for places to modify, but here are some starting points:

In the void loop() function, you can change the speed, starting position, and end position of the servo. If you want to do this, find the for loops on lines 19 and 31. The first one is for the forward motion of the servo and the second one is for the return motion. Experiment with modifying these positions and the delay values! Use the commented code as a reference point.

project sample-400px1

Project Ideas

Now that you’ve created the base servo arm, you can do a variety of different things. In this example, a paper hand has been added to the popsicle stick to create a ‘waving arm.’ Once you understand the connection between the servo motion and the Arduino code, you can experiment with changing the values to fine-tune your project.

Some other ideas are to make a ‘stick puppet’ where you draw build a face onto the servo. Have fun and keep experimenting!

[hr]

Learn more