sequencing

Hi all;

I’m just getting started with an Uno. I have been reading books and manuals and am starting to grasp the language/syntax. My question branches out a bit so im just going to start with the most important two.

  1. Can 1 Uno carry out a sequence of operations one at a time and then stop?
  2. can a momentary be CLICKED to start the process and carry it out without holding.

The process
think of elevator doors. I am using 2 servos to close them, one turning CW the other turning CCW.

  1. push a button and release.
  2. doors close (will base this on how many degrees of rotation required for them to close which i will determine later)
  3. flash led once (this is actually an attempt at simulating a momentary switch using a reed switch/relay for something else)
  4. turn on another LED for a duration of time (another relay switch but this one runs for about 10-15 seconds)
  5. doors reopen and the Uno powers off.

I have tried this with code (some borrowed some modified and some unique.) and hook-ups. the syntax passes the check but i don’t get the result i want. servos will spin several rotations one way then stop rotate back 1/4-1/2 and then go back again several more. havent even tried connecting the relay switches yet. and it just keeps going

still deciding on the power situation I have been trying to limit this whole thing to a single 9v battery but may add another or some AAs to solely power the Uno and keep the 9v for just the motors.

sorry if i’m not being specific enough but im trying to finish this last min at the end of lunch. any help/response would be appreciated. I will add the code here too soon if anyone needs it but if you have something already in mind or done it would make less confusion because as i said im a bit green and my code is a choppy work in progress at best.

Thank you.
XD

  1. Yes.
  2. Yes.

There have been several posts for power-on/power-off switches.
Basically press a button to turn on P-channel MOSFET, starts up Arduino,
Arduino then holds P-channel on until done and then releases it, pullup resistor on gate turns it off.

I think www.pololu.com has a little module that will do power thing, can't get to their site at the moment to provide a link.

Firstly, one 9V transistor battery is not going to supply the current that the servos need. Normal hobby servos can draw up to an amp or more when loaded. You really need to get a better power supply for the servos. A 9V battery will supply just the Arduino for a little while through the Vin or power plug and 4 AA batteries (6V) are a good source for powering the servos.
As for the button to start the process with a push and release, check out the "button state change" example in the IDE (File, Examples, Digital). Also, while looking at examples check the "blink without delay" example to see how to do event timing without blocking.

Then you mention a relay. How will you drive the relay coil? If the relay coil takes over about 20mA you will need a transistor driver for it so as not to overtax the Arduino output.

Do you want the Arduino to power down, or simply to stop moving the servos. There is a big difference.

Writing a program to make something happen and then stop happening (perhaps waiting a minutes or hours or weeks for the next button press) is very simple. And there is the possibility of having it go to "sleep" to save energy and wake up again when a button is pressed (for example).

If you actually want some external thing to cause the Arduino to switch on and then (later) have the program cause it to switch off completely that is another matter - and probably not complicated to arrange, but less common.

...R

I am using 2 servos to close them,

servos will spin several rotations one way then stop rotate back 1/4-1/2

What kind of servos ? Regular 0 to 180 degrees or continuous rotation ?

Updated:

The Primary process is functioning, however; the 180deg servos are not enough to cover the distance (feeding a spline cord from a car antenna.
is there a way to program continuous servos to run for a specific timing (IE 1.5 seconds) since angles dont work on these?
also when i power up the board it cycles running the servo and briefly powering a pin. is there a way to prevent these?

I would also like to make the button so that it actually powers on the arduino which powers down at the end of its process if this is even possible.

here is the code i am currently working with. it might have some holes because this is from a word sheet and i might have made some small changes in the software which i do not have on this work computer.

Sequence summary

  • push button – arduino switches on
    -servo 1 rotates forward (CW) for 1.5seconds while servo 2 rotates back (CCW) for 1.5seconds
    -momentary relay starts radioshack sound chip
    -a second relay engages connecting the power to the LED chaser array (independent circuit board) for about 8 seconds or however long I determine the sound will run
    -lights stop and servos reverse
    -arduino shuts down

#include <Servo.h>
#include <Button.h>
Servo left; // Create servo object to control a servo
Servo right;

// Set digital pin numbers:
const int buttonPin = 2; // The number of the Pushbutton pin
const int servoPin = 9; // The number of the right Servo pin
const int servoPin2 = 10; // The number of the left Servo pin
const int sound = 13; //momentary reed switch to initiate soundboard
const int chaser = 12;
int buttonState = 0; // Variable for reading the pushbutton status
int directionState = 0; // Variable for reading direction of the servo
int pos = 0; // Variable to store the servo position

void setup() {
pinMode(buttonPin, INPUT_PULLUP);
left.attach(10); //may have these detach then reattach between forward and revers operations
right.attach(9);
pinMode(sound, OUTPUT); //this is working perfectly and so is the chaser pin
}
void loop()
{
buttonState = digitalRead(buttonPin);

//The button is pushed
if (buttonState == HIGH) {

forward();
delay(1000);
digitalWrite(sound, HIGH);
delay(5);
digitalWrite(sound, LOW);
delay(10);
digitalWrite(chaser, HIGH);
delay(10000); //will modify to timestamp duration of sound
digitalWrite(chaser, LOW);
reverse();
}
}

void forward() {
left.write(180);
right.write(0);
}

void reverse() {
left.write(0);
right.write(180);
}

SideTracked:
so i had assumed it was unanswered.

Whatever you assume it is a good idea to go back to your previous post and read everything subsequent to it - carefully.

...R

Robin2:
Do you want the Arduino to power down, or simply to stop moving the servos. There is a big difference.

Writing a program to make something happen and then stop happening (perhaps waiting a minutes or hours or weeks for the next button press) is very simple. And there is the possibility of having it go to "sleep" to save energy and wake up again when a button is pressed (for example).

If you actually want some external thing to cause the Arduino to switch on and then (later) have the program cause it to switch off completely that is another matter - and probably not complicated to arrange, but less common.

...R

Power down, so that it can't be left on by accident and drain the battery.

SideTracked:
Updated:

I succeeded in building my sequence. My original code was good it just turns out that the arduino software decided to change all its ports like to bluetooth instead of usb and yui instead of uno.
The Primary process is functioning, however; the 180deg servos are not enough to cover the distance.
is there a way to program either modified Std servos or cont. servos to run for a specific timing (IE 1.5 seconds) since angles dont work on these?
also when i power up the board it cycles running the servo and briefly powering a pin. is there a way to prevent these?

I would also like to make the button so that it actually powers on the arduino which powers down at the end of its process if this is even possible.

I haven’t studied your code.

Perhaps a 180deg servo would move your door far enough if you made the servo arm longer?

Or you could get a sail winch servo that can move through about 1080 deg? (3 revolutions)

If you have some mechanism that simply disconnects the power to the Arduino when you are finished with it you could also have a momentary switch which you would hold long enough for the Arduino to start and to “undo” whatever switched it off. Maybe you could have a relay that holds the power on as long as the Arduino tells the relay to stay on.

Your entire project code could be in the setup() function if you only want it to run once.

…R

Currently set up with standard (180 degree) servos modified to act as continuous. I mounted lego gears to them which push a splined cable gear harvested from a retracting car antenna. these are mounted in a tight space and so this is the only way i have been able to make it work. I also have a couple of continuous ones on order that should be arriving by friday.

SideTracked:
I also have a couple of continuous ones on order that should be arriving by friday.

Send them back and get sail winch servos?

You can put your Lego gears on them and have position control.

...R