Shake to move animals!
- obniz Board
- power supply for obniz
- DC Motor
- paper cup x2
- AAA battery x3
- battery case
- paper and wire for decorations
How to make
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.
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.
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.
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.