donutsorelse
Published © GPL3+

Valentines Day Romance Bot

What's more romantic than having a robot pour wine for you? Lots of things? Fair enough, it's still kind of fun all the same.

BeginnerFull instructions provided1 hour128
Valentines Day Romance Bot

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
I used a 20kg servo
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Grove - Water Sensor
Seeed Studio Grove - Water Sensor
I used a more generic water sensor
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Romance Bot Schematic

It's a schematic for the arduino setup needed for romance bot

Code

RomanceBot

Arduino
This is the full code for romance bot. If you follow the schematic as well, it should just work :).
#include <Servo.h>

Servo myservo;
int pos = 0;
#define POWER_PIN  7
#define SIGNAL_PIN A5

int trigPin = 11;    // Trigger
int echoPin = 12;    // Echo

boolean refillingWineGlass = false;
int val = 0; // variable to store the sensor value
unsigned long previousTime = 0;

long duration, cm, inches;
int posOff = 0;
int posOn = 160;

void setup() {
  myservo.attach(9);
  pinMode(POWER_PIN, OUTPUT);   // configure D7 pin as an OUTPUT
  digitalWrite(POWER_PIN, LOW); // turn the sensor OFF
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  checkProximity();
  if (refillingWineGlass) {
    digitalWrite(POWER_PIN, HIGH);  // turn the sensor ON
    delay(10);                      // wait 10 milliseconds
    val = analogRead(SIGNAL_PIN); // read the analog value from sensor
    digitalWrite(POWER_PIN, LOW);   // turn the sensor OFF

    if (val < 500) {
      pos = posOn;
      myservo.write(pos);
    } else {
      pos = posOff;
      myservo.write(pos);
      refillingWineGlass = false;
      delay(3000);
    }

    //failsafe to avoid spilling if the water sensor doesnt work well enough
    if (millis() - previousTime > 5000) {
      pos = 0;
      myservo.write(pos);
      refillingWineGlass = false;
      Serial.println("STRANGER DANGER");
      delay(3000);
    }
    Serial.println("REFILLING " + String(val) + "     " + String(cm) + " cm");
  }
}

void checkProximity() {
  // The sensor is triggered by a HIGH pulse of 10 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  digitalWrite(trigPin, LOW);
  delayMicroseconds(5);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  // Read the signal from the sensor: a HIGH pulse whose
  // duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(echoPin, INPUT);
  duration = pulseIn(echoPin, HIGH);

  if (!refillingWineGlass) {
    // Convert the time into a distance
    cm = (duration / 2) / 29.1;     // Divide by 29.1 or multiply by 0.0343
    inches = (duration / 2) / 74;   // Divide by 74 or multiply by 0.0135

    if (cm < 20) {
      delay(1000); // wait 1 second before checking the wine levels
      refillingWineGlass = true;
      previousTime = millis();
    }
  }
}

Credits

donutsorelse

donutsorelse

15 projects • 15 followers
I make different stuff every week of all kinds. Usually I make funny yet useful inventions.

Comments