Go Down

Topic: Need to simulate elevator buttons and dial (Read 1 time) previous topic - next topic

darkride

Sep 22, 2017, 06:55 pm Last Edit: Sep 22, 2017, 07:05 pm by darkride
Help! I have no Arduino experience beyond the simple "blink the LED" stuff. I have been tasked to create a simulation for a fake elevator for a haunted house (we do it for free) (push a button, light comes on, dial moves..." So basically what I need is-

Push button to start

LED turns on

(optional- relay to trigger sound effect)

start stepper motor to move from position A to position B (I can adjust settings for the actual positions)

relay to trigger a bell "ding"

LED turns off

pause say 30 seconds

reset stepper motor to position A

reset for next button push

I know this is a lot to ask, but I appreciate any assistance you can give!

AWOL


darkride


cedarlakeinstruments

Stepper vs servo depends on a number of factors. But there are other choices if you only need to move between two points: DC motors and solenoids come to mind.
How far does it have to move? How fast? How much weight is it moving?

Are you looking for code help or for someone to write it for you?
Electronics and firmware/software design and assistance. No project too small

FedxE

Hey,i belive the push button has to be pulled up check this link
 btw i'm not a programmer  but try this code

Code: [Select]

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
               // a maximum of eight servo objects can be created

int pos = 0;    // variable to store the servo position
int button = 2;  // The button will be on Pin 2
int led = 4;    // Led will be on Pin 4
int relay = 5;    // Relay will be on Pin 5

void setup()
{
 myservo.attach(9);  // attaches the servo on pin 9 to the servo object
pinMode(pos, OUTPUT);
pinMode(button, INPUT);
pinMode(led, OUTPUT);
digitalWrite (led, LOW);
}

void loop()
{
 
   if (digitalRead(button) == LOW)
   digitalWrite(led, HIGH);
   
 for(pos = 0; pos < 90; pos += 90)  // goes from 0 degrees to 90 degrees
 {                                  // in steps of  degree
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(2000);
   digitalWrite(relay, HIGH);  //Turn on relay for the Bell
   delay(1000);                   // wait 1 sec to turn off Bell
   digitalWrite(relay, LOW);  //Turn off relay for the Bell
   digitalWrite(led, LOW);
   delay (30000);                //delay 30 seconds to return to home position and wait for next push
    for(pos = 90; pos>=90; pos-=90)     // goes from 90 degrees to 0 degrees
 {                               
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
 delay(50);                             // waits 50ms for the servo to reach the position
 }
                         // waits 1s for the servo to reach the position
 }
}
                         

AWOL

@FedxE : you may wish to revisit your code.

darkride

Unfortunately, i have neither the Arduino experience, nor the time to to totally write the code from scratch. I could adjust parameters for what I need to do, but that's about it at this time.

Since we need to simulate the slow movement of an old fashion elevator floor indicator, stepper or servo seem to the logical choices.



Stepper vs servo depends on a number of factors. But there are other choices if you only need to move between two points: DC motors and solenoids come to mind.
How far does it have to move? How fast? How much weight is it moving?

Are you looking for code help or for someone to write it for you?

FedxE

@FedxE : you may wish to revisit your code.
as i said im not a programmer. Anyways could you please tell me whats wrong? I can see that i forgot to add the relay in the void setup.


cedarlakeinstruments

Code is untested, but should work. If you want known-good, tested code, PM me for cost

Code: [Select]

#include <Stepper.h>

#define PB 2
#define LED 3
#define RLY1 4
#define RLY2 5

// Note, many Arduino Relay boards are active LOW, not HIGH
#define ON LOW
#define OFF HIGH

Stepper _stepper(5,6,7,8);

void setup()
{
 pinMode(PB, INPUT_PULLUP);
 pinMode(LED, OUTPUT);
 pinMode(RLY1, OUTPUT);
 pinMode(RLY2, OUTPUT);
 
 digitalWrite(LED, LOW);
 digitalWrite(RLY1, OFF);
 digitalWrite(RLY2, OFF);
}

void loop()
{
 while (digitalRead(PB) == HIGH);
 
 digitalWrite(LED, HIGH);
 digitalWrite(RLY1, ON);
 delay(1000);

 _stepper.step(100);
 delay(1000);

 digitalWrite(RLY2, ON);
 digitalWrite(LED, LOW);
 
 delay(30000);
 _stepper.step(-100);
 digitalWrite(LED, LOW);
 digitalWrite(RLY1, OFF);
 digitalWrite(RLY2, OFF);
}
Electronics and firmware/software design and assistance. No project too small

Go Up