Masahiro Mizuno
Published © CC BY

4-Legged Walking Robot

A cute, 3D-printed walking robot.

BeginnerFull instructions provided5 hours942
4-Legged Walking Robot

Things used in this project

Hardware components

obniz
Cambrian Robotics obniz
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×4
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1

Story

Read more

Custom parts and enclosures

4-legged walking robot body gerber data

Schematics

schematic drawing

Code

4-legged walking robot code

HTML
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <script src="https://obniz.io/js/jquery-3.2.1.min.js"></script>
  <script src="https://unpkg.com/obniz@2.0.3/obniz.js" crossorigin="anonymous"></script>
</head>
<body>
 
<h1>ObniZoo Controller</h1>
<button id="home"><font size="4" color="#FF008C">HOME</font></button>
<button id="back"><font size="4" color="#333399">BACK</font></button>
<button id="nobi"><font size="4" color="#F200FF">NOBI</font></button>
<br>   
<br><button id="goback"><font size="4" color="#333399">REV</font></button>    
<button id="go"><font size="4" color="#B22222">FWD</font></button>   
<br>
<br><b>pls hit fwd or rvs button as much as you can!!</b>
  
<div id="print"></div>  
  
<script>
var obniz = new Obniz("xxxx-xxxx");
var tgl = 0;
  
obniz.onconnect = async function () {

  var led = obniz.wired("LED", { anode:2 } );
  var buzz = obniz.wired("Speaker", {signal:9, gnd:1});  
  var servoLL = obniz.wired("ServoMotor", {signal:5});
  var servoLR = obniz.wired("ServoMotor", {signal:6});
  var servoFL = obniz.wired("ServoMotor", {signal:7});
  var servoFR = obniz.wired("ServoMotor", {signal:8});
  var voltage = await obniz.ad3.getWait();
  
  obniz.io4.output(true); // power for Sonar/RGB/photo Tr/IR receiver
  obniz.display.clear();
  obniz.display.print("ObniZoo");
  
  obniz.switch.onchange = function(state) {
    $('#print').text(state);
    obniz.display.clear();
    obniz.display.print(state);
  }  

   
  function posehome() {
      servoFL.angle(85);    servoFR.angle(90);      //
      servoLL.angle(90);    servoLR.angle(98);      //
  }
  function poseback() {
      servoFL.angle(85-20); servoFR.angle(90+20);   // 
      servoLL.angle(90-20); servoLR.angle(98+20);   //     
  }
  function posenobi() {
      servoFL.angle(85-40); servoFR.angle(90+40);   // 
      servoLL.angle(90+40); servoLR.angle(98-40);   //    
  }  

  function move(para) { 
   switch(para) {
   case 0:
      servoFL.angle(85);    servoFR.angle(90+40);   // 
      servoLL.angle(90);    servoLR.angle(98-40);   //  
   break;
   case 1:
      servoFL.angle(85-40); servoFR.angle(90+40);   //
      servoLL.angle(90);    servoLR.angle(98-40);   // 
   break;
   case 2:
      servoFL.angle(85-40);  servoFR.angle(90);     // 
      servoLL.angle(90+40);  servoLR.angle(98-40);  //       
   break;       
   case 3:
      servoFL.angle(85-40);  servoFR.angle(90);     // 
      servoLL.angle(90+40);  servoLR.angle(98);     //        
   break;       
   case 4:
      servoFL.angle(85-40);  servoFR.angle(90+40);  // 
      servoLL.angle(90+40);  servoLR.angle(98);     //       
   break;       
   case 5:
      servoFL.angle(85);     servoFR.angle(90+40);  // 
      servoLL.angle(90+40);  servoLR.angle(98-40);  //       
   break;       
   default:
   }
  }   
   
  
  $('#home').click(function () {
      led.off(); buzz.stop();
      posehome();
      obniz.display.clear(); obniz.display.print("HOME");
      //obniz.display.print(voltage);
  });
  $('#back').click(function () {
      led.off(); buzz.stop(); 
      poseback();
      obniz.display.clear(); obniz.display.print("BACK");
  });
  $('#nobi').click(function () {
      led.on(); buzz.play(40);   
      posenobi();
      obniz.display.clear(); obniz.display.print("NOBI");
  });
  
  var step = 0;
  $('#go').click(function () { 
      buzz.play(200 + 200*step);
      step = step + 1; if(step > 5) { step = 0; }
      move(step); 
      obniz.display.clear(); obniz.display.print("GO"); obniz.display.print(step);
  });    
  $('#goback').click(function () {
      buzz.play(2000 + 200*step);
      step = step - 1; if(step < 0) { step = 5; }
      move(step); 
      obniz.display.clear(); obniz.display.print("GOBACK"); obniz.display.print(step);
  });
}

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

Credits

Masahiro Mizuno

Masahiro Mizuno

20 projects • 32 followers
Chief Prototypist. 20+ years R&D experience in wide range of technology.

Comments