Topic outline
- General
General
- Cookie monster
Cookie monster
We found out someone is eating the cookies from the jar in the kitchen! We thought about it and came to the conclusion that the best thing to do would be to prepare a trap to find out who was eating them. Let us build something that will take a picture of whoever opens the cookie jar. No cookie monsters were hurt in the making of this experiment.
Materials
- 1 x control board
- 1 x Education Shield
- 1 x breadboard
- 1 x web camera
- 1 x Power LED module
- 1 x 1 Mohm resistor
- 1 x module cable
- 3 x jumper wire (1 long)
- 1 x Cookie Monster kit
- 1 x Aluminum foil piece
- 1 x conductive cookie jar
- 3-4 x rubber band
- 1 x tape
Note: If you don't have access to a conductive cookie jar, you can wrap your jar or box in aluminum foil.This experiment can be created without the Education shield. You can download the schematics here, and the Fritzing original files can be found in this Github repository.
Instructions
-
Step 1
Attach the shield onto the top of the board.
-
Step 2
Connect the LED module to D6 on the shield.
-
Step 3
Use the module cable to connect the module to the shield.
-
Step 4
-
Step 5
Build a capacitive sensor, go to the reference, learn how to Build a capacitive sensor.
-
Step 6
Using a separate breadboard, connect a 1 Mohm resistor between digital pin 3 and digital pin 2.
-
Step 7
-
Step 8
Gather all the construction materials for the Cookie monster.
-
Step 9
Let's start building the Cookie monster! If you want some building tips, go to the Building Advices reference.
-
Step 10
-
Step 11
-
Step 12
-
Step 13
-
Step 14
-
Step 15
-
Step 16
-
Step 17
Use a rubber band to attach the arms.
-
Step 18
-
Step 19
-
Step 20
-
Step 21
-
Step 22
-
Step 23
-
Step 24
-
Step 25
-
Step 26
-
Step 27
-
Step 28
-
Step 29
-
Step 30
-
Step 31
Use another rubber band to attach the head.
-
Step 32
-
Step 33
Get the web camera.
-
Step 34
-
Step 35
Attach the camera in between the eyes, using another rubber band.
-
Step 36
-
Step 37
Connect the capacitive sensor to the digital pin 3 on the separate breadboard.
-
Step 38
-
Step 39
Pull the module cable, with the LED, through the inside of the body.
-
Step 40
Attach the LED module in the mouth.
-
Step 41
-
Step 42
Put the capacitive sensor under the body, so the sensor sticks out from the front.
-
Step 43
If you don't have access to a conductive cookie jar, you can wrap your jar or box in aluminum foil.To check so that your jar is conductive, you can use a multimeter. Take a look at the Multimeter reference to learn how to use one.
-
Step 44
Place a cookie jar on the capacitive sensor, making sure the metal parts are in contact.
-
Step 45
-
Step 46
Connect the USB cable to the board.
-
Step 47
Connect the board and camera to the computer.
-
Step 48
Find the CookieMonster program and open it.
-
Step 49
Then upload the program to the board.
-
Step 50
Attach the back pieces to the Cookie monster.
-
Step 51
-
Step 52
-
Step 53
-
Step 54
-
Step 55
-
Step 56
-
Step 57
In the IDE, click Sketch > Show Sketch folder. Open the folders Processing > CokieMonster, then open the CookieMonster.pde file.
-
Step 58
Run the CookieMonster.pde program. This program will capture a photo of the thief and save it so you can see it later.
-
Step 59
Now try and take the cookies from the Cookie monster! The thief photo is now in the same folder as the proccessing program file
Code
Find the code in File>Examples>EducationShield>Block3-Magic>Projects>CookieMonster
http://verkstad.cc/urler/ctc-g-b3-p-3-1
Find the Processing code for capturing webcam images of your cookie thief in File>Examples>EducationShield>Block3-Magic>Projects>CookieMonster>Processing>CookieMonster
http://verkstad.cc/urler/ctc-g-b3-p-3-2
Note: To add a library in Processing go to Sketch>Import Library and click on Add Library. This opens up the Contribution Manager, where you can find libraries. In the Filter box write "Video GS", select the library called "Video GStreamer-based video library for Processing" and click on Install, after its done installing close the Contribution Manager window, and done!
How it works
When you touch the cookie jar, the capacitive sensor is activated and the board sends a “p” character to Processing through the serial port. When the Processing sketch receives this character, it takes a picture using the webcam.
Control board
- The EducationShield library is included.
- The CapacitiveSwitch object, sensor is declared.
- The variable led is declared.
- In setup(), serial communication is initialized.
- The capacitive sensor is configured and initialized.
- The led pin is set as an output.
- In loop(), if the capacitive sensor is pressed, that is touched, the LED is turned on and ‘p’ is printed to the serial port.
- The program pauses for 2000 milliseconds.
- If the sensor is not pressed, nothing happens.
Processing
- The processing video and serial libraries are included.
- The camera and serial port objects are declared.
- In setup(), the window size is set to 640 x 480 pixels, and the renderer P2D is chosen.
- The camera and serial port are configured and initialized.
- In draw(), if the camera is available, the camera image is read.
- The image read from the camera is drawn to the program window.
- The String variable timeStamp is declared to hold current date and time.
- The text timeStamp is drawn in coordinates (10, height-10).
- If the key ‘p’ or ‘P’ is pressed the current image is saved to the sketch’s data folder.
- If the serial port is available, the incoming data is read and stored in inByte.
- If inByte is equal to ‘p’, the current image is saved to the sketch’s data folder.
Troubleshooting
- Refer to the illustration and double check your connections. Make sure the shield and jumper wires are firmly connected.
- If Processing is reporting error and no image is showing up, make sure you have the latest version of Processing, and:
- The control board is connected to the computer, and in myPort = new Serial(this, Serial.list()[0], 9600) is using the serial port number of your board. Find it in Tools>Serial Port in the IDE.
- initializeCamera() is using the correct camera number from the list printed out by Processing.
- If you are touching the cookie jar and no image is captured, try touching the capacitive sensor directly. If it is working, you need a more conductive cookie jar. If not, see the capacitive sensorreference for debugging.
- If you can not find the picture of cookie thief, look into the CookieMonster sketch folder of Processing for it.
Learn by doing
- Change the reaction time: make the monster wait for a few seconds before taking the picture, so you catch the thief with cookie in hand!
- Record a monster sound according to these instructions, and use an 8 ohm speaker to play the sound when the capacitive sensor is triggered.