obniz developer team
Published © GPL3+

Singing and Moving Bird for Kids

Easy and fun project for kids. If you move your smartphone, the bird will sing and move depending on the angles of the smartphone.

BeginnerFull instructions provided4 hours649

Things used in this project

Hardware components

obniz
Cambrian Robotics obniz
Cloud Connected IoT Development Board
×1
Adafruit Standard servo - TowerPro SG-5010 - 5010
×1
Adafruit Large Enclosed Piezo Element w/Wires
×1
iPhone
Apple iPhone
Any smartphone
×1
Android device
Android device
Any smartphone
×1
Paper cup
×1
Paper
×1

Story

Read more

Code

Program

JavaScript
<!-- HTML Example -->
<html>
<head>
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@1.8.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>

Credits

obniz developer team

obniz developer team

80 projects • 32 followers
Development board "obniz" is controlled via the internet.

Comments