GoldScrew
Published © Apache-2.0

Make Eating Robot With Arduino Nano | Gold Screw

Today I will show you how to make eating robot with Arduino Nano. This project I made for my daughter. It's very easy with cheap materials.

BeginnerFull instructions provided10,491
Make Eating Robot With Arduino Nano | Gold Screw

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Arduino Web Editor
Arduino Web Editor

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

Parts connection diagram

Code

GoldScrew_EatingRobot.ino

Arduino
/*
 * Cartboard eating Robot
 * Author: GoldScrew
 * Email: goldscrewdiy@gmail.com
 * Description: It's using HC-SR04 (Detect food by distance <= 5 cm) and Server (to open and close the mouth)
 */
 
#include <Servo.h>  
#define SERVO_PIN 9 // Set pin 9 for servo

// HC-SR04 ultrasonic sensor
const int trig = 3;     // trig of HC-SR04
const int echo = 2;     // echo of HC-SR04

// Servo
Servo mouthServo;

void setup()
{
  // Serial connection with baudrate 960
  Serial.begin(9600);
  
  // Send signal with TRIG
  pinMode(trig, OUTPUT);
  
  // Receive signal with ECHO
  pinMode(echo, INPUT);

  // Mouth Server
  mouthServo.attach(SERVO_PIN);
  mouthServo.write(90);
      
}
void loop()
{
  /* Duration */
  unsigned long duration;
  int distance; //Distance

  /* Send signal from TRIG pin */
  digitalWrite(trig, 0); //Stop trig pin
  delayMicroseconds(2); //Delay 2 micro seconds
  digitalWrite(trig, 1); //Send signal from TRIG pin
  delayMicroseconds(10); //Delay 10 micro seconds
  digitalWrite(trig, 0); //Stop trig pin
  
  /* Measure HIGH pulse width at ECHO pin */
  duration = pulseIn(echo, HIGH);

  //Calculate distance
  distance = int(duration/2/29.412);

  if(distance <= 5)
  {
    //Print distance
    Serial.println("the distance is less than 5 cm");
    
    // Start open mouth
    mouthServo.write(0);

    // Delay
    delay(1200);
    
  } else {

    //Print distance
    Serial.println("the distance is more than 5 cm");
    
    // Close the mouth
    mouthServo.write(90);  
  }
  
  // Delay
  delay(200);
}

Credits

GoldScrew
5 projects • 11 followers
Contact

Comments

Please log in or sign up to comment.