Kids Project! Smartphone Piyo Piyo

このエントリーをはてなブックマークに追加

Create a Bird and control it from a smartphone!

Movie

How to make

Material

  • Servo Motor SG5010
  • Piezo Speaker
  • Paper Cup
  • Paper

First, Create base for a bird.
Cut circle and make a tiny hole for motor.

Next, Fix it on top of a motor with side tape.

Attach this to a servo.

Create a bird with cup as you like!

Then, put it on a servo.

Fix a cable like this.

Wire

Piezo Speaker to io0 and io4.
Servomotor signal to io9. vcc to io10, gnd to io11.
You finished! Open HTML.

How to use

Tilt a smartphone to move and tweet.

Program

<!-- HTML Example -->
<html>
<head>
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@2.0.2/obniz.js"></script>
</head>
  
<body>
  <div id="obniz-debug"></div>
  <div id="print"></div>

<script>
  
var speaker;
var servo;
var lastbeta;
var obniz = new Obniz("OBNIZ_ID_HERE")
obniz.onconnect = async () => {

  speaker = obniz.wired("Speaker", {signal:0, gnd:4});
  servo = obniz.wired("ServoMotor", {signal:9,vcc:10, gnd:11});
}

window.addEventListener("deviceorientation", (event) => {
  if (!speaker) return;
  const beta = event.beta;
  const gamma = event.gamma;
  const alpha = event.alpha;
  
  console.log(gamma);
  if (beta > lastbeta + 1 || beta < lastbeta - 1 ){
    speaker.play(parseInt((beta - 0) * (7000 - 4000) / (90 - 0) + 4000));
  } else {
    speaker.stop();
  }
  lastbeta = beta;
  servo.angle(parseInt((gamma - (-80)) * (180 - 0) / (80 - (-80)) + 0));
})

</script>
</body>
</html>

Run Now

The html will be opened to run a program.