[Kids Project] Shake Animal!
Contents
Make things
Shake to move animals!
Materials
- obniz Board
- power supply for obniz
- DC Motor
- paper cup x2
- AAA battery x3
- battery case
- paper and wire for decorations
How to make
Body
First, make a hole at the bottom of one paper cup.
Fix a motor to a cup with double-sided tape.
Make an animal with the other paper cup and color paper and so on freely.
Hardware connection
Connect DC Motor to an obniz like the table and the image below by referring to DC Motor Library. Please adjust the direction of the DC Motors properly, because rotation direction depends on the DC Motors’ direction.
obniz | DC Motor |
---|---|
0 | OUT1 |
1 | OUT2 |
Put AAA batteries in a battery case to case and solder a cable to obniz J1. Be careful not to short circuit!
Finally, cover the other cup (decorated like animals) to the cup.
Run the program below and shake your smartphone! The stronger you shake it, the stronger the animals move.
Software
To get values about the acceleration of the smartphone, input “deveicemotion” for the first argument, and anonymous function for the second argument in “window.addEventListener” function.
Then, get the value like below.
let x = event.accelerationIncludingGravity.x; let y = event.accelerationIncludingGravity.y;
Please read Detecting device orientation – Web API | MDN for details.