Hello!
Please help me with this problem. :~ I have to finish a project by tuesday and I got stuck.
I have to make an elevator model using an arduino, i am using a dc motor, which is connected to an RC car breadboard so when i push on the remote buttons, the motor moves in the specific direction. I am using two relays to virtually press the remote buttons, which work perfectly. I connected them to the arduino, each through one wire, and I made the motor go in each direction with a delay of 1000 using the blink example code a bit modified, all of this works fine. Then I went a step further and added buttons connected to the arduino so when i would press them the motor will go in the two direction⦠with or without delays⦠Now hereās the part where I got stuck. My elevator has 3 floors, each wit a limit switch, so when the elevator is at floor 2 , the 2nd switch is pressed, and so on at all the floors.
What I want to do is make a code that would say:
if the elevator is on floor 1 (limit switch 1 is pressed), an I press the button for the third floor, the motor will spin in direction 1, until the limit switch at floor 3 is pressed(the elevator reached the third floor.
I tried variations of the āButtonā example code, but didnāt work. Iām guessing I need a type of code similar to āmove up until you hit the wall, then stopā.
Other codes I used:
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT); //limit for 3rd floor
pinMode(3, INPUT); //limit for 2nd floor
pinMode(4, INPUT); //limit for 1st floor
pinMode(5, INPUT); //button for 1
pinMode(6, INPUT); //button for 2
pinMode(7, INPUT); //button for 3
pinMode(8, OUTPUT); //motor dir UP (relay 1)
pinMode(9, OUTPUT); //motor dir DOWN (relay 2)}
void loop() {
//Go from level 1 to level 2
while(4==HIGH)
{
if(6==HIGH)
{
digitalWrite(8, HIGH);
}
if(3==HIGH)
{
digitalWrite(8, LOW);
}
}//Go from level 1 to level 3
while(4==HIGH)
{
if(7==HIGH)
{
digitalWrite(8, HIGH);
}
if(2==HIGH)
{
digitalWrite(8, LOW);
}
}//Go from level 2 to level 1
while(3==HIGH)
{
if(5==HIGH)
{
digitalWrite(9, HIGH);
}
if(4==HIGH)
{
digitalWrite(9, LOW);
}
}//Go from level 2 to level 3
while(3==HIGH)
{
if(7==HIGH)
{
digitalWrite(8, HIGH);
}
if(2==HIGH)
{
digitalWrite(8, LOW);
}
}//Go from level 3 to level 1
while(2==HIGH)
{
if(5==HIGH)
{
digitalWrite(9, HIGH);
}
if(4==HIGH)
{
digitalWrite(9, LOW);
}
}//Go from level 3 to level 2
while(2==HIGH)
{
if(6==HIGH)
{
digitalWrite(9, HIGH);
}
if(3==HIGH)
{
digitalWrite(9, LOW);
}
}
}
int timer = 100; // The higher the number, the slower the timing.
void setup() {
// use a for loop to initialize each pin as an output:
for (int thisPin = 2; thisPin < 8; thisPin++) {
pinMode(thisPin, OUTPUT);
}
}void loop() {
// loop from the lowest pin to the highest:
for (int thisPin = 2; thisPin < 8; thisPin++) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}// loop from the highest pin to the lowest:
for (int thisPin = 7; thisPin >= 2; thisPinā) {
// turn the pin on:
digitalWrite(thisPin, HIGH);
delay(timer);
// turn the pin off:
digitalWrite(thisPin, LOW);
}
}
Please help me as soon as possible, I have to finish this project by tuesday!
Thank you!