Let me start off by saying that I was disappointed with the amount robots I was able to find that involves the use of an Arduino, ever since I've owned a 3D printer it was something I always wanted to-do. I am no engineer, and I taught myself how to make models on a 3D CAD software (FreeCAD), this is something I do in my free time, and nothing I've made is perfect. This robot is a simple stand-still bot, it does not move expect for its arms and head.
The whole objective of the robot is to be scared of humans and does not like being looked at by one, so when u get close to the Sonic Sensor it acts “Frantic” waving its arms and moving its head out of the way.
PART LIST -
1- Arduino Uno
1- Medium Sized breadboard
1- Sonic Senor
1- OLED 0.96in
1- 3ohm Mini Speaker
3- SG90 Servo motors
A bunch of small sized wires / some large ones
Code for the bot - (it only makes the arms, head & sonic sensor work at the moment)
----------------------------------------------------------------------------------------------------------
#include <Servo.h>
// Pin Definitions
#define HEAD_SERVO_PIN 11 // Head servo pin
#define LEFT_ARM_PIN 9 // Left arm servo pin
#define RIGHT_ARM_PIN 10 // Right arm servo pin
#define TRIG_PIN 12 // Ultrasonic sensor trigger pin
#define ECHO_PIN 13 // Ultrasonic sensor echo pin
// Servo Objects for the head and arms
Servo headServo;
Servo leftArmServo;
Servo rightArmServo;
// Distance Variables
long duration;
int distance;
// Arm positions
int armNeutral = 90;
int armUp = 0;
int armDown = 180;
// Head scanning variables
int scanCenter = 90; // Head centered position
int currentHeadPos = scanCenter;
// Arm movement speeds
int armSpeed = 20; // Speed of arm movements
void setup() {
// Attach the servos to their respective pins
headServo.attach(HEAD_SERVO_PIN);
leftArmServo.attach(LEFT_ARM_PIN);
rightArmServo.attach(RIGHT_ARM_PIN);
// Initialize the ultrasonic sensor
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
// Start with centered head and arms
headServo.write(scanCenter); // Center head
leftArmServo.write(armNeutral); // Center left arm
rightArmServo.write(armNeutral); // Center right arm
delay(1000); // Wait for the servos to settle
randomSeed(analogRead(0)); // Seed the random number generator
}
void loop() {
// Measure the distance using the ultrasonic sensor
distance = getDistance();
// If an object is detected within 5 cm, move both head and arms
if (distance <= 5) {
moveHeadAndArms("frantic"); // Move head and arms frantically
}
// If an object is detected within 20 cm, move both head and arms
else if (distance <= 20) {
moveHeadAndArms("frantic"); // Move head and arms frantically
} else {
// Continue scanning without resetting
headServo.write(scanCenter); // Keep the head centered
leftArmServo.write(armNeutral); // Keep the arms centered
rightArmServo.write(armNeutral); // Keep the arms centered
}
delay(100); // Delay to smooth the operation
}
// Function to get the distance from the ultrasonic sensor
int getDistance() {
// Send a pulse to trigger the sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Measure the duration of the pulse
duration = pulseIn(ECHO_PIN, HIGH);
// Calculate the distance in cm (speed of sound = 343m/s, or 0.0343 cm/us)
int distanceCm = duration * 0.0343 / 2;
return distanceCm;
}
// Function to move both head and arms based on the action type
void moveHeadAndArms(String actionType) {
if (actionType == "frantic") {
// Move head and arms frantically when object is detected
int franticMovement = random(1, 4);
if (franticMovement == 1) {
headServo.write(30); // Move head to left
leftArmServo.write(armUp); // Left arm up
rightArmServo.write(armDown); // Right arm down
}
else if (franticMovement == 2) {
headServo.write(150); // Move head to right
leftArmServo.write(armDown); // Left arm down
rightArmServo.write(armUp); // Right arm up
}
else if (franticMovement == 3) {
headServo.write(180); // Move head to completely turned position
leftArmServo.write(random(0, 180)); // Random left arm movement
rightArmServo.write(random(0, 180)); // Random right arm movement
}
else if (franticMovement == 4) {
headServo.write(60); // Move head to a moderate left position
leftArmServo.write(armUp); // Left arm up
rightArmServo.write(armDown); // Right arm down
}
delay(500); // Short delay before changing arm positions
// Reset arms to neutral position after movement
leftArmServo.write(armNeutral);
rightArmServo.write(armNeutral);
delay(200); // Short delay before the next action
}
}
--------------------------------------------------------------------------------------------------------------
Most parts fit together perfect others not so much, again I do this for fun and to learn, I wanted to upload the “Draft” version awhile, my goal is for other likeminded people to maybe take on this project with me and make this a community driven robot, change / upgrade / add more parts / improve the functions / add functions / change the design whatever comes to your mind while making the bot, want to improve it make it look better do whatever your heart desires.
----------------------------------------------------------------------------------------------------------------
Some parts will require glue but not many, servos pop in place, so do the speaker and OLED the only issue is I made the spots to perfect, and both the speaker & OLED need to be put in perfectly or they won't fit, the only parts that require glue are the feet connectors to the legs & the legs to the body
----------------------------------------------------------------------------------------------------------------
Tags
Modellquelle
