Arduino Nano-Controlled Otto Robot with Ultrasonic Sensor and Servo Motors
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit is designed to control a series of servomotors, an ultrasonic sensor, and a buzzer using an Arduino Nano microcontroller. The circuit includes an I/O Expansion Shield for interfacing the Arduino Nano with the various components. A toggle switch and a 4 x AAA battery mount provide power management capabilities. The primary function of this circuit is to facilitate the movements and actions of a robotic system, as indicated by the embedded code which includes routines for walking, turning, and producing sound effects.
Component List
Microcontroller
- Arduino Nano: A compact microcontroller board based on the ATmega328P, featuring digital and analog I/O pins.
Sensors
- HC-SR04 Ultrasonic Sensor: A distance measuring sensor that uses ultrasonic sound waves to determine the distance to an object.
Actuators
- Servomotor SG90: Small and lightweight servomotors used for precise control of angular motion.
Output Devices
- Buzzer: An electronic buzzer for producing simple tones and sound effects.
Power Supply
- 4 x AAA Battery Mount: A battery holder for four AAA batteries, providing a portable power source for the circuit.
Interface Modules
- I/O Expansion Shield For Arduino Nano: An expansion board that facilitates easy connections between the Arduino Nano and other components.
Switches
- Toggle Switch: A switch used to control the power supply to the circuit.
Wiring Details
Arduino Nano
- Connected to the I/O Expansion Shield to interface with all other components.
HC-SR04 Ultrasonic Sensor
- VCC: Connected to the I/O Expansion Shield for power.
- TRIG: Connected to the I/O Expansion Shield's D8 pin for triggering measurements.
- ECHO: Connected to the I/O Expansion Shield's D9 pin to receive measurement signals.
- GND: Connected to the I/O Expansion Shield for ground.
Servomotor SG90
- SIG: Connected to the I/O Expansion Shield's D2, D3, D4, and D5 pins for signal control.
- VCC: Connected to the I/O Expansion Shield for power.
- GND: Connected to the I/O Expansion Shield for ground.
Buzzer
- PIN: Connected to the I/O Expansion Shield's D13 pin for sound signal control.
- GND: Connected to the I/O Expansion Shield for ground.
4 x AAA Battery Mount
- +: Connected to the Toggle Switch for power distribution.
- -: Connected to the I/O Expansion Shield for ground.
Toggle Switch
- COM: Connected to the I/O Expansion Shield's 5V pin for power control.
- L2: Connected to the positive terminal of the 4 x AAA Battery Mount.
Documented Code
//----------------------------------------------------------------
//-- Otto All moves test
//-- Otto DIY invests time and resources providing open source code and hardware,
//-- please support by purchasing kits from https://www.ottodiy.com/
//-- Make sure to have installed all libraries: https://github.com/OttoDIY/OttoDIYLib
//-----------------------------------------------------------------
#include <Otto.h>
Otto Otto; //This is Otto!
#define LeftLeg 2
#define RightLeg 3
#define LeftFoot 4
#define RightFoot 5
#define Buzzer 13
#define DIN A3 // Data In pin
#define CS A2 // Chip Select pin
#define CLK A1 // Clock pin
#define Orientation 1 // 8x8 LED Matrix orientation Top = 1, Bottom = 2, Left = 3, Right = 4
///////////////////////////////////////////////////////////////////
//-- Setup ------------------------------------------------------//
///////////////////////////////////////////////////////////////////
void setup(){
Otto.init(LeftLeg, RightLeg, LeftFoot, RightFoot, true, Buzzer); //Set the servo pins and Buzzer pin
Otto.initMATRIX( DIN, CS, CLK, Orientation);
Otto.sing(S_connection); //Otto wake up!
Otto.home();
delay(50);
Otto.playGesture(OttoHappy);
}
///////////////////////////////////////////////////////////////////
//-- Principal Loop ---------------------------------------------//
///////////////////////////////////////////////////////////////////
void loop() {
Otto.walk(2,1000,1); //2 steps, "TIME". IF HIGHER THE VALUE THEN SLOWER (from 600 to 1400), 1 FORWARD
Otto.walk(2,1000,-1); //2 steps, T, -1 BACKWARD
Otto.turn(2,1000,1);//3 steps turning LEFT
Otto._tone(10, 3, 1);
Otto.bendTones (100, 200, 1.04, 10, 10);
Otto.home();
delay(100);
Otto.turn(2,1000,-1);//3 steps turning RIGHT
Otto.bend (1,500,1); //usually steps =1, T=2000
Otto.bend (1,2000,-1);
Otto.shakeLeg (1,1500, 1);
Otto.home();
delay(100);
Otto.shakeLeg (1,2000,-1);
Otto.moonwalker(3, 1000, 25,1); //LEFT
Otto.moonwalker(3, 1000, 25,-1); //RIGHT
Otto.crusaito(2, 1000, 20,1);
Otto.crusaito(2, 1000, 20,-1);
delay(100);
Otto.flapping(2, 1000, 20,1);
Otto.flapping(2, 1000, 20,-1);
delay(100);
Otto.swing(2, 1000, 20);
Otto.tiptoeSwing(2, 1000, 20);
Otto.jitter(2, 1000, 20); //(small T)
Otto.updown(2, 1500, 20); // 20 = H "HEIGHT of movement"T
Otto.ascendingTurn(2, 1000, 50);
Otto.jump(1,500); // It doesn't really jumpl ;P
Otto.home();
delay(100);
Otto.sing(S_cuddly);
Otto.sing(S_OhOoh);
Otto.sing(S_OhOoh2);
Otto.sing(S_surprise);
Otto.sing(S_buttonPushed);
Otto.sing(S_mode1);
Otto.sing(S_mode2);
Otto.sing(S_mode3);
Otto.sing(S_sleeping);
Otto.sing(S_fart1);
Otto.sing(S_fart2);
Otto.sing(S_fart3);
Otto.sing(S_happy);
Otto.sing(S_happy_short);
Otto.sing(S_superHappy);
Otto.sing(S_sad);
Otto.sing(S_confused);
Otto.sing(S_disconnection);
delay(100);
Otto.playGesture(OttoHappy);
Otto.playGesture(OttoSuperHappy);
Otto.playGesture(OttoSad);
Otto.playGesture(OttoVictory);
Otto.playGesture(OttoAngry);
Otto.playGesture(OttoSleeping);
Otto.playGesture(OttoFretful);
Otto.playGesture(OttoLove);
Otto.playGesture(OttoConfused);
Otto.playGesture(OttoFart);
Otto.playGesture(OttoWave);
Otto.playGesture(OttoMagic);
Otto.playGesture(OttoFail);
Otto.home();
delay(100);
Otto.putMouth(zero);
delay(100);
Otto.putMouth(one);
delay(100);
Otto.putMouth(two);
delay(100);
Otto.putMouth(three);
delay(100);
Otto.putMouth(four);
delay(100);
Otto.putMouth(five);
delay(100);
Otto.putMouth(6);
delay(100);
Otto.putMouth(7);
delay(100);
Otto.putMouth(8);
delay(100);
Otto.putMouth(9);
delay(100);
Otto.putMouth(smile);
delay(100);
Otto.putMouth(happyOpen);
delay(100);
Otto.putMouth(happyClosed);
delay(100);
Otto.putMouth(heart);
delay(100);
Otto.putMouth(angry);
delay(100);
Otto.putMouth(smallSurprise);
delay(100);
Otto.putMouth(bigSurprise);
delay(100);
Otto.putMouth(tongueOut);
delay(100);
Otto.putMouth(confused);
delay(100);
Otto.putMouth(21); //diagonal
delay(100);
Otto.putMouth(27); //interrogation
delay(100);
Otto.putMouth(23); //sad open
delay(100);
Otto.putMouth(24); //sad closed
delay(100);
Otto.putMouth(vamp1);
delay(100);
Otto.putMouth(vamp2);
delay(100);
Otto.putMouth(xMouth);
delay(100);
Otto.putMouth(okMouth