loading
 A medium sized box that requires the user to succeed in a game of hang man in order to gain access to the contents of the box.  Great gift Idea!!!

my Arduino sketch will be included in this instructible

sorry for the poor quality pictures!
and keep in mind this is my first instructable,
and I forgot to take pictures of the build in process,
all of these pics are from the completed project.

If you have any questions send me an email and I will get back to you asap, NOI7734@gmail.com

Note:
I "borrowed" a lot of code from Dan Wagoner over at www.nerdybynature.com, you can find his "hangmamduino" project there as well, and Dan Wagoner if you somehow stumble upon this "ible", thanks for sharing your code, also I would recommend getting a copy of the "truerandom" library and incorporate that into your code as I did, as the native random function is "psuedorandam".

Step 1: Parts

I am not supplying instruction for the servo lock construction as the parts I used may not be easy to find, its ok just look at the pics below and you will devise something probably a lot better and cleaner ;-)

Parts needed:
1 - wooden box
1 - Arduino board with atmega 328
1 - 16x2 LCD display (get a good price at adafruit.com)
2 - 10k potentiometer (if you got your LCD from adafruit it comes with 1 so you only need 1)
1 - knob for potentiometer
2 - normally open momentary contact switch (button)
1 - servo
2 - 10k resistors
1 - speaker
1 - main power switch
1 - LED with built in mount and resistor
2 - plastic project boxes
1 - 9volt battery and battery strap
lots of wire and solder/soldering iron
parts to make the mechanical lock(I used random hardware I had laying around, see pic)
hot glue gun
dremel tool and drill

If you are going to take the atmega328 out of the arduino board to use the board with other projects later you will also need:

1 - piece of printed circuit board (PCB) or perf board
1 - atmega328
1 - 28 pin MCU socket
1 - 16mhz crystal
2 - 22pf capacitors
1 - 5 volt regulator
1 - 10nf capacitor
1 - 22uf capacitor (use radial lead not axial lead, non-polarized will not work)


Step 2: Sketch

Here is the sketch for the Arduino IDE, also included are the "string" and "truerandom" libraries required for this script to work, head over to arduino.cc for instructions on how to install libraries into the IDE.

Step 3: Solder ATmega328 to PCB

follow the instructions on the following instructable (this one is explained better than I could possible try)

https://www.instructables.com/id/Perfboard-Hackduino-Arduino-compatible-circuit/

I will be referring to all pins on the ATmega328 as Arduino pins, I would recommend printing out the atmega328 to arduino pinout map from the above instructable on step 5 picture 2.

also solder a 10k resistor from digital 3 to ground, and another from digital 6 to ground


Step 4: Wiring Map for Reference

Use this page as reference the wire map is also included in the arduino sketch
ARDUINO PINS:
analog 0 - DO NOT USE!!! 
digital 3 - button inside
analog 3 - 10k pot outside 
digital 4 - servo
digital 5 - speaker 
digital 6 - button outside
digital 7 - LCD D4 11 
digital 8 - LCD D5 12
digital 9 - LCD D6 13 
digital 10 - LCD D7 14
digital 11 - LCD RW 5 
digital 12 - LCD RS 4 
OTHER:
LCD 1 - GND 
LCD 2 - V+ 
LCD 3 - Contrast, 10k pot 
LCD 15 - V+ 
LCD 16 - GND  

Step 5: Assemble Control Box and Battery Box

The battery box is the smaller box to the left of the control box, with the screws facing out so if the 9volt were to drain it could be changed without prying open the box!!!

(hot glue the battery box to the control box, drill a small hole between the 2 boxes for the 2 wires)

sorry for not having detailed pics but I forgot to take some during construction (gimme a break this is my first instructable)

the best way to do this is to cut 14 long pieces of wire (mine were arm length and just barely long enough) and label them on both ends with masking tape and marker as follows:

control box end of wire () ATmega328 end of wire
5v+ () 5v+
5v- () 5v-
9v+ () 9v+
9v- () 9v-
potentiometer () analog 3
button () digital 6
speaker () digital 5
LCD pin 4 () digital 12
LCD pin 5 () digital 11
LCD pin 6 () digital 2
LCD pin 11 () digital 7
LCD pin 12 () digital 8
LCD pin 13 () digital 9
LCD pin 14 () digital 10

install the components in the control box and solder all the labeled wires, solder the 5+ and 5- wires to ALL power and grounds!  (+ to pin 2 and 15 on LCD, to one lead on button, one lead on both potentiometers, and pos lead on led, - to neg led lead, neg potentiometer leads, and pin 1 and 16 on LCD)  dont forget to solder the smaller 10k pot to the lcd pin 3 for the contrast.  Solder the battery strap ground to the 9v- wire, positive from the battery to the main power switch, and from the switch to the 9v+ wire.  feed all 14 wires through a hole drilled in the lid of the box, dont screw the control box down yet, we will need to adjust the contrast on the lcd first, I hot glued the contrast pot to the inside of the control box as well as the speaker, and lcd.

Step 6: Clean Up the Wire Mess!

wrap all 14 wires in heat shrink tubing or electrical tape just to keep things looking clean, (or wire loom would work i suppose).  pull the control box flush with the top and route the clean wrapped wires to where the PCB will be mounted (dont hot glue the wires down yet like mine are) and make a mark with a sharpie where they will need to be cut on each wire, or cut them now, just make sure you dont mix up the wires/labels!

Step 7: Solder the Wires to the PCB

Solder the 9v+ and 9v- wires to the voltage regulator as described in the instructable for mounting the AVR(atmega328) to the PCB.

solder the 5v+ and 5v- the the power and ground rails you made on your PCB (on the same circuit as the 22uf capacitor)

it gets a little hairy in this part, but you'll make it through, just remember to double check all your work BEFORE you put the battery in!!

solder the rest of the labeled wires in the corresponding locations on the PCB.

solder the servo wires to the PCB power ground and signal.

(note: my PCB has a lot more wires than yours probably will...I didnt have any 22pf capacitors for the crystal, so I had to use 2 10pf and 2 1pf caps in parallel for each crystal leg...thats a total of 8 caps where there should only be 2, plus I had to relocate the crystal on the PCB to have room for all 8 caps, then add wires from the AVR to the crystal legs, caps, and back to ground, poor planning on my part!)

Step 8: Test

get a multimeter if you have one and check the resistance across the power and ground rails on the PCB, and on the voltage regulater across input and ground, and across output and ground.  All of these should be open, if they are not, go back and look for a short before you go any further.

if all was well, load up a battery and turn on the main power switch, adjust the contrast on the LCD and check all fuctions including and especially the servo lock function.  (we want to avoid the box locking shut and never opening!)

if there is a problem that you need help with at this point and its not working, return to the intro step and send me an email I will get back to you asap.

if all is well, hot glue your wrapped wires down the way you had them routed, be sure they have a little room to move when the lid opens/closes, mount the control box, very carefully hot glue the corners of the PCB in place.   I would also advise putting in a barrier (piece of wood or some other material) firmly mounted between the storage space of the box and the working components, just so nothing gets damaged by whatever is kept in the box.

I hope you enjoyed this as much as i did!
Dan Ford
<p>Thanks for you replay</p><p>oke i will try, I'll let you know if its works</p>
<p>Hai</p><p>I have the same problem, who can help, I use Arduino Uno a have a error </p><p>secretWord = guessWord.getChars();</p><p>Have also Arduino Mega or Mega 2560 tried</p><p>Kind Regards</p>
<p>change parts of the code into this:</p><p>const char letterVal[] = &quot;_abcdefghijklmnopqrstuvwxyz&quot;;</p><p>char guessLetter;</p><p>char guessLast;</p><p>char guessed[25];</p><p>const char* secretWord;</p><p>int guessedCount = 1;</p><p>int wordSize;</p><p>int gotOne = 0;</p><p>int alreadyGuessed = 0;</p><p>int showAsterisk = 0;</p><p>int buttonState;</p><p>int hangman = 0;</p><p>int totalRight = 0;</p><p>long lastDebounceTime = 0;</p><p>Servo lock; //create a servo object called lock</p><p>int button2on; //integer for button inside box</p><p>LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);</p><p>String guessWord = String(42);</p><p>// hangman graphic characters</p><p>byte topleft[] = { 0x1F, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10 };</p><p>byte topright[] = { 0x1C, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00 };</p><p>byte bottomleft[] = { 0x10, 0x10, 0x10, 0x10, 0x10, 0x1F, 0x1F, 0x1F };</p><p>byte bottomright[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };</p><p>byte head[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x00, 0x00, 0x00 };</p><p>byte topbody[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x04, 0x04, 0x04 };</p><p>byte bottombody[] = { 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };</p><p>byte rightarm[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x05, 0x06, 0x04 };</p><p>byte leftarm[] = { 0x1C, 0x04, 0x04, 0x0E, 0x0E, 0x15, 0x0E, 0x04 };</p><p>byte rightleg[] = { 0x04, 0x04, 0x02, 0x02, 0x01, 0x00, 0x00, 0x00 };</p><p>byte leftleg[] = { 0x04, 0x04, 0x0A, 0x0A, 0x11, 0x00, 0x00, 0x00 };</p><p>byte leftarrow[] = { 0x10, 0x18, 0x1C, 0x1E, 0x1E, 0x1C, 0x18, 0x10 };</p><p>byte rightarrow[] = { 0x01, 0x03, 0x07, 0x0F, 0x0F, 0x07, 0x03, 0x01 };</p><p>void setup()</p><p>{</p><p> lock.write(160); //set lock servo to locked position before it is attatched to prevent servo from moving to 90 degrees on startup</p><p> lock.attach(4); // Connected to servo to control lock</p><p> Serial.begin(9600);</p><p> pinMode (POTPIN, INPUT);</p><p> pinMode (BUTTONPIN, INPUT);</p><p> pinMode (SPEAKERPIN, OUTPUT);</p><p>// pinMode (servon, OUTPUT);</p><p> pinMode (button2, INPUT);</p><p> lcd.begin(16, 2);</p><p> lcd.clear();</p><p> lcd.setCursor(1,0);</p><p> lcd.print(&quot;CACHE&quot;);</p><p> lcd.setCursor(1,1);</p><p> lcd.print(&quot;NAVN&quot;);</p><p> delay(5000);</p><p> // pick a random word using analog 5 for random data</p><p> //randomSeed(analogRead(4));</p><p> newWord();</p><p> //draw the board</p><p> draw_board();</p><p>// digitalWrite(servon, HIGH);</p><p> lock.write(160);</p><p> delay(1000);</p><p>// digitalWrite(servon, LOW);</p><p>}</p><p>void newWord(){</p><p> //pick a random word from the list</p><p> int pick = TrueRandom.random(NUMWORDS);</p><p> const char* pickWord = words[pick];</p><p> guessWord = pickWord;</p><p> secretWord = guessWord.c_str();</p><p> wordSize = guessWord.length();</p><p> Serial.println(guessWord); // print the word to serial for cheaters like me ;) ...or for testing purposes.</p><p>}</p>
<p>hmm.... can't get it to work, could it be that it wont work with arduino uno?</p>
<p>The servo keeps living its own life, and when i connect a button to digital 6, the game automaticly Wins......</p>
It's always nice to see someone &quot;borrow&quot; code. Thanks for the credit...and the random library tip. When I was writing the code I never guessed someone would use it for a lock. Hopefully you also included more words in the dictionary. :)
yes I found a list of the 42 hardest words for hangman, so I used those words, I think my father will be pleasantly surprised with the challenge to get to his fathers day gift, :-P.

About This Instructable

5,808views

12favorites

License:

More by NOI7734:Arduino powered hangman giftbox/lockbox 
Add instructable to: