Components and supplies
Ultrasonic Sensor - HC-SR04 (Generic)
SG90 Micro-servo motor
Arduino Nano R3
Tools and machines
Multitool, Screwdriver
Apps and platforms
Arduino IDE
Project description
Code
OTTO all moves
c_cpp
code for robot
1//---------------------------------------------------------------- 2//-- Otto All moves setup 3//-- You can add functions, gestures or sounds in loop 4//-- CC BY SA (http://ottodiy.com) 5//-- 25 October 2018 6//----------------------------------------------------------------- 7#include <Servo.h> 8#include <Oscillator.h> 9#include <US.h> 10#include <Otto.h> 11Otto Otto; //This is Otto! 12//--------------------------------------------------------- 13//-- First step: Make sure the pins for servos are in the right position 14/* 15 --------------- 16 | O O | 17 |---------------| 18YR 3==> | | <== YL 2 19 --------------- 20 || || 21RR 5==> ----- ------ <== RL 4 22 |----- ------| 23*/ 24 #define PIN_YL 2 //servo[2] 25 #define PIN_YR 3 //servo[3] 26 #define PIN_RL 4 //servo[4] 27 #define PIN_RR 5 //servo[5] 28/*SOUNDS****************** 29 * S_connection S_disconnection S_buttonPushed S_mode1 S_mode2 S_mode3 S_surprise S_OhOoh S_OhOoh2 S_cuddly 30 * S_sleeping S_happy S_superHappy S_happy_short S_sad S_confused S_fart1 S_fart2 S_fart3 31 */ 32/*MOVEMENTS LIST************** 33 * dir=1---> FORWARD/LEFT 34 * dir=-1---> BACKWARD/RIGTH 35 * T : amount of movement. HIGHER VALUE SLOWER MOVEMENT usually 1000 (from 600 to 1400) 36 * h: height of mov. around 20 37 jump(steps=1, int T = 2000); 38 walk(steps, T, dir); 39 turn(steps, T, dir); 40 bend (steps, T, dir); //usually steps =1, T=2000 41 shakeLeg (steps, T, dir); 42 updown(steps, T, HEIGHT); 43 swing(steps, T, HEIGHT); 44 tiptoeSwing(steps, T, HEIGHT); 45 jitter(steps, T, HEIGHT); (small T) 46 ascendingTurn(steps, T, HEIGHT); 47 moonwalker(steps, T, HEIGHT,dir); 48 crusaito(steps, T, HEIGHT,dir); 49 flapping(steps, T, HEIGHT,dir); 50/*GESTURES LIST*************** 51OttoHappy OttoSuperHappy OttoSad OttoSleeping OttoFart OttoConfused OttoLove OttoAngry 52OttoFretful OttoMagic OttoWave OttoVictory OttoFail*/ 53/////////////////////////////////////////////////////////////////// 54//-- Global Variables -------------------------------------------// 55/////////////////////////////////////////////////////////////////// 56bool obstacleDetected = false; 57int distance = 0; 58/////////////////////////////////////////////////////////////////// 59//-- Setup ------------------------------------------------------// 60/////////////////////////////////////////////////////////////////// 61void setup(){ 62 //Set the servo pins 63 Otto.init(PIN_YL,PIN_YR,PIN_RL,PIN_RR,true); 64 Otto.sing(S_connection); //Otto wake up! 65 Otto.home(); 66 delay(50); 67} 68/////////////////////////////////////////////////////////////////// 69//-- Principal Loop ---------------------------------------------// 70//--Uncomment lines or add you own-------------------------------// 71/////////////////////////////////////////////////////////////////// 72void loop() { 73 //OBSTACLE MODE ON!!!! 74 obstacleMode(); 75 Otto.sing(S_surprise); 76 Otto.walk(2,1000,1); //2 steps FORWARD 77 Otto.sing(S_OhOoh); 78 Otto.walk(2,1000,-1); //2 steps BACKSWARD 79 Otto.sing(S_OhOoh2); 80 Otto.playGesture(OttoFretful); 81 Otto.sing(S_cuddly); 82 Otto.home(); 83 Otto.playGesture(OttoSleeping); 84 Otto.sing(S_sleeping); 85 delay(1000); 86 Otto.sing(S_happy); 87 Otto.playGesture(OttoHappy); 88 Otto.turn(2,1000,1);//2 steps turning RIGHT 89 Otto.sing(S_happy_short); 90 delay(50); 91 Otto.playGesture(OttoSuperHappy); 92 Otto.sing(S_superHappy); 93 Otto.turn(2,1000,-1);//2 steps turning RIGHT 94 Otto.playGesture(OttoSad); 95 Otto.sing(S_sad); 96 delay(50); 97 Otto.moonwalker(3, 1000, 25, 1); 98 Otto.playGesture(OttoConfused); 99 Otto.sing(S_confused); 100 Otto.home(); 101 Otto.bend (1, 2000, 1); 102 Otto.playGesture(OttoFart); 103 Otto.sing(S_fart1); 104 Otto.sing(S_fart2); 105 Otto.sing(S_fart3); 106 Otto.home(); 107 Otto.ascendingTurn(1, 2000, 22); 108 Otto.playGesture(OttoVictory); 109 Otto.home(); 110 Otto.updown(1, 2000, 22); 111 Otto.playGesture(OttoMagic); 112 Otto.home(); 113 Otto.playGesture(OttoFail); 114 Otto.sing(S_disconnection); 115} 116/////////////////////////////////////////////////////////////////// 117//-- Function to avoid obstacles 118void obstacleMode(){ 119 distance = Otto.getDistance(); 120 if(distance<15){ 121 Otto.sing(S_surprise); 122 Otto.walk(2,1300,-1); 123 Otto.turn(3,1000,-1); 124 delay(50); 125 } 126 else{ 127 Otto.walk(2,1000,1); 128 } 129} 130
Downloadable files
circuit diagram
used to conect circuit properly
circuit diagram
circuit diagram
used to conect circuit properly
circuit diagram
Comments
Only logged in users can leave comments