Make gifts for people

Don’t make stuff because you want to make money — it will never make you enough money. And don’t make stuff because you want to get famous — because you will never feel famous enough. Make gifts for people — and work hard on making those gifts in the hope that those people will notice and like the gifts.

Maybe they will notice how hard you worked, and maybe they won’t — and if they don’t notice, I know it’s frustrating. But, ultimately, that doesn’t change anything — because your responsibility is not to the people you’re making the gift for, but to the gift itself. [1]

— John Green

Inspiration

ARDUINO STARTER KIT inspired me once more. In Hacking buttons blog post I described how I followed the last project from the kit. This time I’ve made my own twist on an original project and made a gift out of it.

I used Knock Lock project to base mine upon. It consisted of two components: a piezo [2] and a servo motor [3]. The project used the servo to open and close a box as shown below.

ekrIGpd

To decide whether to lock or unlock the box Arduino used the piezo. Arduino could hear and count down knocks. If the number of knocks equaled to specific number Arduino opened the box. Since knocking seems fun but not secure I decided to create a more interesting solution.

Making the gift

Let’s make the gift, shall we? As it goes with all a bit complicated project I needed to split the project into parts.

Testing the servo

Firstly I researched how to use the servo. I quickly assembled a project, which involved it to recall how to use it. Later I removed all the unnecessary parts including capacitors, who needs a smooth motion right?

Unfortunately when trying to glue the yellow part to the actual servo mechanism I destroyed it. Some of the glue must have gotten in the mechanism. Lesson learnt to use a screw next time!

EDkNs7r
Figure 1. Servo, which got destroyed.

In perpendicular position the servo would close the box while in parallel the box could open.

XahOfra
Figure 2. Testing new servo, closed
Rl3XnHZ
Figure 3. Testing new servo, open

Connecting Raspberry and Arduino

Now let’s switch to the harder part of the project.

I used 4 GPIO pins of the Raspberry to send 4 bits of a digit.

To for example send
  • 4 I needed to set the following cables to these voltage levels:

    • yellow → LOW

    • purple → LOW

    • orange → HIGH

    • brown → LOW

  • 9 I needed to set the following cables to these voltage levels:

    • yellow → HIGH

    • purple → LOW

    • orange → LOW

    • brown → HIGH

The fifth green cable acted as a clock to notify the Arduino when to read the voltages.

Arduino waited for 4 digits: 2, 9, 0 and 7 before opening.

Each green LED indicated a correctly sent digit, yellow LED whether the Arduino listens for input or not.

To open the box automatically I created the following python script:

open-box.py
import os
import time

os.system("gpio -1 mode 29 OUT && gpio -1 mode 31 OUT && gpio -1 mode 33 OUT && gpio -1 mode 35 OUT && gpio -1 mode 37 OUT")
os.system("gpio -1 write 37 0")

os.system("gpio -1 write 35 0 && gpio -1 write 33 0 && gpio -1 write 31 1 && gpio -1 write 29 0")
os.system("gpio -1 write 37 1")
os.system("gpio -1 write 37 0")
time.sleep(3);

os.system("gpio -1 write 35 1 && gpio -1 write 33 0 && gpio -1 write 31 0 && gpio -1 write 29 1")
os.system("gpio -1 write 37 1")
os.system("gpio -1 write 37 0")
time.sleep(3);


os.system("gpio -1 write 35 0 && gpio -1 write 33 0 && gpio -1 write 31 0 && gpio -1 write 29 0")
os.system("gpio -1 write 37 1")
os.system("gpio -1 write 37 0")
time.sleep(3);


os.system("gpio -1 write 35 0 && gpio -1 write 33 1 && gpio -1 write 31 1 && gpio -1 write 29 1")
os.system("gpio -1 write 37 1")
os.system("gpio -1 write 37 0")
time.sleep(3);
1DO5x13
Figure 4. Raspberry GPIO pins
tiTr53o
Figure 5. Arduino connected to Raspberry, leds off
dz3VcFw
Figure 6. Arduino connected to Raspberry, leds on
4w8GaNe
Figure 7. Arduino connected to both Raspberry and servo

Battery?

Observant reader might spot disappearance of the battery in the last photo. Well, the initial plan involved powering the arduino using a 9V battery, but it failed.

Arduino booted correctly, and it ran the code just fine, however readings from analogRead looked totally off. I searched the Internet for similar problems and found something called common ground issue. Basically to read voltages from Raspberry correctly, I needed to connect both devices to the same ground. Luckily I managed to use 5V pin from Raspberry to power the Arduino.

Powering the Arduino from Raspberry made both of the devices use the same ground, so I could read the voltages correctly.

Soldering

I used the good old soldering iron to make necessary holes in the box.

I needed the first hole, so the servo could prevent the box from opening. The hole’s breadth roughly equals to the servo’s width. Such measurement enables the servo to freely turn 360 degrees.

fg5aeS9
Figure 8. Hole for servo

To weave cables through the box I made small holes for each of them. It turned out totally unaligned but melting plastic stands far from easy.

MgwWMQI
Figure 9. Holes for cables

Decorating

For the final touch I used some glitter tape to decorate the whole box.

cUBdtgC
Figure 10. Decorated and open
Jz4HUlS
Figure 11. Decorated and closed
WjQ3D4B
Figure 12. Servo through hole

Magic box in action

First video presents how the project works without any changes to the box.

Project with servo not glued

Video belows shows the project in its final form.

Final version of the project

1. Would you like to see a comic depicting this quote? Visit ZEN PENCILS to see it!
2. A piezo is an electronic device that generates a voltage when it’s physically deformed by a vibration, sound wave, or mechanicalstrain. Similarly, when you put a voltage across a piezo, it vibrates and creates a tone. Piezos can be used both to play tones and to detect tones.
3. Device that can turn to a specified position. Usually, they have a servo arm that can turn 180 degrees.