Kids Project. Simple RC Car

What’s this?

Let’s make a simple RC car with an obniz.

Materials

  • obniz x1
  • power supply for obniz x1
  • DC Motor and gear box x2
  • RC car tire x2
  • wood or plastic for RC car foundation

Steps

Body

First, build gear box and motor. You can buy it at Toy Stores.

And fix it on the foundation like wood or plastic. It will be good that you make the foundation to fix an obniz and the battery.

On the back of RC car

Wiring

Connect DC Motors to the obniz like the table and the image below. Please adjust the direction of the DC Motors properly, because rotation direction depends on the DC Motors’ direction.

obnizDC Motor
0[left DC Motor] OUT1
1[left DC Motor] OUT2
2[right DC Motor] OUT2
3[right DC Motor] OUT1

Supply power to the obniz and run the program below. Then, you can control the direction and the rotation of the RC car tires from operation screen like the image below.

Program

<!-- HTML Example -->
<html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
  <script src="https://unpkg.com/obniz@2.0.2/obniz.js" crossorigin="anonymous"></script>
</head>
<body>

<div id="obniz-debug"></div>
  <br>
<button id="lf" class="btn btn-warning" style="width:45%;height:100px;font-size:50px;">↑</button>
<button id="rf" class="btn btn-warning" style="width:45%;height:100px;font-size:50px;">↑</button>
  <br>
  <br>
<button id="lb" class="btn btn-primary" style="width:45%;height:100px;font-size:50px;">↓</button>
<button id="rb" class="btn btn-primary" style="width:45%;height:100px;font-size:50px;">↓</button>

<script>
var obniz = new Obniz("OBNIZ_ID_HERE");
obniz.onconnect = async function () {
  var motorA = obniz.wired("DCMotor",  {forward:3, back:2});
  motorA.power(40);
  var motorB = obniz.wired("DCMotor",  {forward:0, back:1});
  motorB.power(40);

  $("#lf").on('touchstart mousedown', ()=>{
    motorA.move(true);
  })
  $("#lf").on('touchend mouseup',()=>{
    motorA.stop();
  })
  $("#lb").on('touchstart mousedown',()=>{
    motorA.move(false);
  })
  $("#lb").on('touchend mouseup',()=>{
    motorA.stop();
  })
  
  $("#rf").on('touchstart mousedown',()=>{
    motorB.move(true);
  })
  $("#rf").on('touchend mouseup',()=>{
    motorB.stop();
  })
  $("#rb").on('touchstart mousedown',()=>{
    motorB.move(false);
  })
  $("#rb").on('touchend mouseup',()=>{
    motorB.stop();
  })
}

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