Getting the "robocup" to work

Hello, I'm building an open source project called "robocup" . It's an automated water bottle that has a flexible straw that is Servo driven. You press a button and the straw rotates 180 deg, you press the button again and it returns 180 in the opposite direction. So I have all the hard parts done, I need help just getting it to respond to the push button. The designer had the .ino file for the Arduino Nano. I believe I correctly downloaded the "button.ino" file to the Nano but all it does is rotate 180 deg then back continuously, this is what I want, i just want the Servo to go after the button is pressed not continuously.

any help would be greatly appreciated

Gavin Seeker [Gseeker65@gmail.com]

Show how your button is wired to the Nano.
Show how the author button is wired to the Nano.
Post the sketch in a "code block."

sorry I'm unclear how to post the schematic, if you click on the "OEDK Rice University-Robocup DIY" link. that's all the information I have

If you don't understand how to post the schematic, you will hardly understand how to solve the problem.

Draw a schematic of your named devices, showing pin numbers, and connecting pin numbers to pin numbers.

If the author has a schematic, mouse-over the schematic, right-click, "copy image," (return to forum), in the message box right-click "paste," click "reply"

there is an option to have a motion sensor instead of the pushbutton, that why there are three wires. Its my understanding that you use the blue and green wires for the switch

Do not attempt to power a servo from an Arduino 5V output, as that can damage or destroy the Arduino.

Instead, use a separate power supply, and be sure to connect the grounds. A 4xAA battery pack will work.

Are you going to post your sketch as requested ?

Is there anything in your project or code that keeps the input pin at a known voltage at all times or is it floating at an unknown voltage, maybe HIGH, maybe LOW when the switch is not closed ?

I don't have a schematic of the power supply; they call out a rechargeable battery pack that plugs into the USB cable

[robocup_button (1).ino|attachment](upload://xIh174Dqk5jtiql5QN2J1kXQk6e.ino) (1.3 KB)

[robocup_button (1).ino|attachment](upload://xIh174Dqk5jtiql5QN2J1kXQk6e.ino) (1.3 KB)

The code can be made really simple:

#include <Servo.h>
Servo servo;

const char servoPin = 3;  //the pin to connect the servo (fill in according to reality)
const char buttonPin = 0;   //the pin to connect the button (fill in according to reality)
const char servoDrinkinAngle = 180; //angle that the servo has to turn to drink (fill in)
const char servoStoredAngle = 0; //angle that the servo has to turn to store the whole thing (fill in)

void setup(){
  servo.attach(servoPin);
  pinMode(buttonPin, INPUT);
}

void loop(){
  delay(digitalRead(buttonPin));      //proceed to the rest of the program if the button is pressed
  servo.write(servoDrinkingAngle);    //set the servo to the drinking position
  delay(!digitalRead(buttonPin);      //wait until the button is released
  delay(50);                          //to cancel button bounce
  delay(digitalRead(buttonPin);       //proceed to the rest of the program if the button is pressed
  servo.write(servoStoredAngle);      //set the servo to the stored position
  delay(!digitalRead(buttonPin);      //delay until the button is released
  delay(50);                          //to cancel button bounce
}

It is definitely not the best or most elegant way to do it, but it should work (haven't tested it) and is really simple. If you want to make sure that the servo doesn't smack the person in the wheelchair, add some kind of for-loop or something similar.

I want to be clear, this is one of the most simple solutions, not the best or most effective one.

Do not post a link to a file. Post the program text.

Why is Rice University letting "engineers" power servos with microcontrollers?


#include<Servo.h>
#include <SPI.h>
Servo servo;
int distance;
int serv=3;
int sensor=4;
int dt=10;
int starttime;
int endtime;
int i;
int buttonState;

void setup() {
Serial.begin(9600);
servo.attach(serv);
servo.write(270);
servo.detach();
pinMode(serv, OUTPUT);
pinMode(sensor,INPUT_PULLUP);
}

void loop() {
int buttonState = digitalRead(sensor);
Serial.write(digitalRead(sensor));

if(buttonState==HIGH){
  endtime = millis();
  starttime = millis();
  while (endtime - starttime < 3000){
    endtime = millis();
    if(buttonState==LOW){
      break;
    }
  }
  if(endtime-starttime >= 3000){
    for (int angle = 270; angle > 0; angle -= 1) {
      servo.attach(serv);
      servo.write(angle);
      delay (10);
      i = 1;
      }
      servo.detach();
      Serial.write('1');
  }
}

if(i == 1){
  if(buttonState==HIGH){
    endtime = millis();
    starttime = millis();
    while(endtime - starttime < 3000){
      endtime = millis();
      if(buttonState==LOW){
        break;
      }
    }
    if(endtime-starttime >= 3000){
      for (int angle = 0; angle < 270; angle += 1) {
        servo.attach(serv);
        servo.write (angle);
        delay (10);
        i = 0;
        }
        servo.detach();
        Serial.write('0');
    }
  }
}
}
1 Like

they must feel the servo doesn't pull enough current

Electronics have no feelings. They have limits.

dt = 10 is not used. How did this make it to the official site?

The code is blocking, all it does is wag the straw (how cruel to a thirsty cripple) and so the sensor is unresponsive.

I am not a fan of these failed, "assisted" gadgets that only make things worse.

Use a simple straw.

code is blocking?

Nothing can happen when the servo is wagging the straw.

Maybe you should start with Arduino basic sketches.

IDE >> FILE >> EXAMPLES >> BUILT-IN EXAMPLES >> here

so you feel this just won't work in this configuration?