3 stop motor

Hi all..

I am a newbie with arduino, and was only introduced to it last week. I have seen several projects and am quite impressed and amused..:))

I can go around electronics, but when i come to sketches...hmmm..its new for me.

I need help in a sketch to control a hoist motor to go 3 levels. (Ground floor, 1st floor and second floor).

Any ideas were i can get an arduino sketch for this project?

Thanks all..

Do you know how to detect the level ? There are many sensors that can do that.
Is it full size ? or a small demonstration ?
Or is it only for school without real motors and sensors and you only need to write a sketch ?
Are people actually going in to go to another level ? That is too dangerous.

Hello Peter,

Many thanks to your reply.

So basically this is going to be a small lift in a restaurant, to take the plates up to the first floor, or the second floor. I have already constructed such lifts, but this is the first time, that I have 3 levels. Usually, with 2 levels, it is pretty easy, cause we use a simple Automation Board,(used for sliding gates) with limit switch inputs for levels, and simply connect the doors to the Stop input of the board, so that if the doors are opened, the lift wont operate. So far it has always been a piece of cake.. But now..hehh. .with 3 levels, its a different story!.

I was introduced to arduino last week by a friend of mine, and has followed a lottt of projects on youtube, and viewed some sketches, and am really happy to have found this arduino. I want to learn a lot about it, but it seems like I have to start studying C++..

I would really appreciate, if i could get some help with the sketch for this project.

Thanks.

The Arduino is for fast prototyping. When used in a project like that, you have to add some protection for the Arduino pins. They are directly connected to the microcontroller. But a single resistor or a RC filter is often enough.

The Arduino can do sequences, timing, and all that kind of things. It uses normal 'c' and 'c++' programming.

I don't want to write the complete sketch for you, but if you have a sketch, then I can check it.

Developing a sketch needs it to run many times. Could you make a test with a few leds and switches, or perhaps with Lego or Fischertechnik ?

A state machine could be used for that.
This is an example : help with multiple digital inputs for a car lighting circuit - #10 by Peter_n - Programming Questions - Arduino Forum

Thanks, I have looked that up. I will read it carefully, and see how I can apply it for my project, as yet, I did not really get the hold of it.

Re your last post, I have answered, but somehow, it did not show up here. bohh.

Yes, I understand I need to make some filtering, and other things. The High output coming out from the arduino, will be used to trigger a contactor (via transistors, and an auxilliary 12V) which in return will run the motor.

I guess that the limit switches (NC to NO), and the Floor Call Buttons, can be connected directly to the arduino, since they are voltage free, Right?

As regards to the sketch, yes I understand you. I am not looking for a ready made tailored sketch, but I have tried looking over the internet for something similar, at least to start with.. to get an idea of the language, but to no result. I have not found a page, with "sketches". Maybe I am looking in the wrong place.

I started taking the 3 week tutorial here, but so far only learned the Blinking Led! and a couple of usefull info. Longgg way to tipperrary!. :slight_smile:

As you said, I will bench test the system over and over again, with led s first definately.

The switches are just switches, but could pick up nasty electric spikes from the mains. So a little protection is needed. Or you can use opto-couplers, and solve any electric spike at once with just a simple opto-coupler.
Now that I think of it: use opto-couplers :stuck_out_tongue:

A state machine has a variable that is the current state.

For example:
state 23: going up to level 2
state 24: stopped at level 2
and so on.

In the sketch, a piece of code is used for every state.
The result is a many small pieces of code, but it is easy to maintain and to alter.

However, you don't have to use a state-machine. If you can do the same with a few if-then-else, why not ?

yep.. Optocouplers will be. It would light up the project. hehe

Guess that I will read and try to understand your code. This "c" is so vast!!, but at least I can start building up a mental database of codes, and symbols, until I wait for my Arduino starter pack to arrive, since on this island, no arduinos are available!!.. grrr

Hi peter,

Finally my kit has arrived! :))

So back to my project, I have done this sketch. It is working good, but now comes the hard part!
How can I programm it, so that when I press the MiddleButton, the Up or Down button will light up, following the previous state.

For example: I press UP..Led UP lights up for 10 seconds, than I press Middle. (and I would like to switch on Middle and Down Led)

to the contrary, if I press (Down, and than I press Middle, the led UP and Middle will switch on)

Below is my first ever sketch, after verifying, there were more mistakes than the lines I had written!!.. LOL, but thanks to internet, managed to find all mistakes. A lot of them stupid missing ; and ()

//Setting up a control board to use it for a small hoist model, 3 floors, to control 2 x 12v contactors
// Level sensors and safety sensors will be installed indipendently, on another control board

// set pin numbers:
const int buttonUp = 2; // the number of the pushbutton pin for UP
const int buttonMiddle = 3; // the number of pushbotton pin for middle
const int buttonDown = 4; // the number of the pushbutton pin for Down
const int ledPinUp = 12; // the led output for UP Position
const int ledPinMiddle = 13; // the led output for MIDDLE Position
const int ledPinDown = 11; // the led output for DOWN Position

// inputs that will change:
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;// variables for reading the pushbutton status

void setup() {

pinMode(ledPinUp, OUTPUT); //output for led UP
pinMode(ledPinMiddle, OUTPUT); //output for led UP or Down (must follow last buttonstate) - This Output will take trigger Up or Down
pinMode(ledPinDown, OUTPUT); //output for led DOWN
pinMode(buttonUp, INPUT); //trigger for led UP
pinMode(buttonMiddle, INPUT); //trigger for led UP or Down (This output must trigger Up or Down) depending on last buttonstate
pinMode(buttonDown, INPUT); //trigger for led Down
}

void loop() {
// read the state of the pushbutton value:
buttonState2 = digitalRead(buttonUp);
buttonState3 = digitalRead(buttonMiddle);
buttonState4 = digitalRead(buttonDown);

if (buttonState2 == HIGH) {
digitalWrite(ledPinUp, HIGH); //Turn LED ON for UP for 10 seconds
delay (10000);

}
else {

digitalWrite(ledPinUp, LOW); //turn LED OFF for UP
}
if (buttonState3 == HIGH) {
digitalWrite(ledPinMiddle, HIGH); //turn LED ON for MIDDLE for 10 seconds
delay (10000);
}
else {
digitalWrite(ledPinMiddle, LOW); //turn LED OFF for Middle
}

if (buttonState4 == HIGH) {
digitalWrite(ledPinDown, HIGH); //turn LED ON for DOWN for 10 seconds
delay (10000);
}
else {
digitalWrite(ledPinDown, LOW); //turn LED OFF for DOWN
}
}

Shall I use a limit switch, in inputs Up and Down and use this statement?

There is a common variation called if-else that looks like this:

if (someCondition) {
// do stuff if the condition is true
} else {
// do stuff if the condition is false
}
[Get Code]
There's also the else-if, where you can check a second condition if the first is false:

if (someCondition) {
// do stuff if the condition is true
} else if (anotherCondition) {
// do stuff only if the first condition is false
// and the second condition is true
}

OK, that's a good start Intertronic. That will flash LEDs for 10 seconds or whatever you want. BUT it's not a good way to write a real program. The problem is delay() totally locks up the processor and your code can't do anything like checking if the elevator has touched a limit switch.

Think about loop() running constantly. Thousands of times per second it checks all the inputs (user buttons and limit switches) then, using its memory of what is happening (travelling-up, stationary, whatever) it can set the outputs correctly, thousands of times per second. For timed events, you need to record what time the event started and then on every pass through the loop, it needs to check the time [ using millis() ] to see if it's time to stop doing that thing.

For example, you might need the chef to press the UP button and hold it for half a second before the elevator starts moving. During that half second, you need to keep checking that the elevator is/isn't moving and all the other inputs. So record the millis() that the chef first pressed the button and keep checking constantly to make sure the button stays down for the full 0.5 seconds.

Hi Morgan,

Thanks a lot for your reply. Yes, I have noticed that during the delay, the board goes on Halt, until the delay has passed.

Yes, this would present a problem, if I had to use limit switches, to stop the motor from travelling. (I had in mind to use an auxiliary board, but if I can get around it with a single arduino board, it would be much better)

I did not really understand the (millis) statement that you mentioned, re the chef pressing the button..etc.. As a matter of fact, I do not need any timing, since if I can manage to use 3 inputs as limit switches, than the motor will stop, once these limit switches change state.

I have to try and modify my sketch. This is my first ever sketch, since last week, I did not even know of the existence of arduino, and c++, however I am happy, that so far I managed to write a sketch (not to mention the amount of errors, probably more than I had lines written!.. lol)

I am going to post my sketch here, which is different than the one I had posted before. In this sketch, I am using 2 limit switches, to tell the motor if it should go up or down, when the middle button is pressed. Am I on the right track?

Thanks a lot.

//Setting up a control board to use it for a small hoist model, 3 floors, to control 2 x 12v contactors
// Level sensors and safety sensors will be installed indipendently, on another control board



// set pin numbers:
const int buttonUp = 2;       // the number of the pushbutton pin for UP
const int buttonMiddle = 3;   // the number of pushbotton pin for middle
const int buttonDown = 4;     // the number of the pushbutton pin for Down
const int ledPinUp = 12;      // the led output for UP Position
const int ledPinMiddle = 13;  // the led output for MIDDLE Position
const int ledPinDown = 11;    // the led output for DOWN Position
const int limitup = 7;
const int limitdown = 8;

// inputs that will change:
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState7 = 0;
int buttonState8 = 0;
void setup() {
  Serial.begin(9600);
  pinMode(ledPinUp, OUTPUT);        //output for led UP
  pinMode(ledPinDown, OUTPUT);      //output for led DOWN
  pinMode(buttonUp, INPUT);         //trigger for led UP
  pinMode(buttonDown, INPUT);        //trigger for led Down
  pinMode(limitup, INPUT_PULLUP);       //signal switch for buttonmiddle
  pinMode(limitdown, INPUT_PULLUP);      //signal limit switch for buttonmiddle
}

void loop() {
  // read the state of the pushbutton value:
  buttonState2 = digitalRead(buttonUp);
  buttonState3 = digitalRead(buttonMiddle);
  buttonState4 = digitalRead(buttonDown);
  buttonState7 = digitalRead(limitup);
  buttonState8 = digitalRead(limitdown);

  if (buttonState2 == HIGH) {
    digitalWrite(ledPinUp, HIGH);
    delay (10000);

  }
  else {
    digitalWrite(ledPinUp, LOW);
  }


  if ((buttonState3 == HIGH) && (buttonState7 == HIGH) && (buttonState8 == LOW))

  {
    digitalWrite(ledPinUp, HIGH);
    delay (10000);
  }
  else if ((buttonState3 == HIGH) && (buttonState7 == LOW) && (buttonState8 == HIGH)) {
    digitalWrite(ledPinDown, HIGH);
    delay (10000);
  }

  if (buttonState4 == HIGH) {
    digitalWrite(ledPinDown, HIGH);
    delay (10000);
  }
  else {
    digitalWrite(ledPinDown, LOW);
  }
}

First, use meaningful names for your ButtonState variables. It's difficult to remember if 7 was the up or down switch. You start out with names for the pins so keep that going.

Second, you will need to understand how a "state machine" works. (Search the forums here at Arduino.) It looks like the 'middle' button is the request to drive the hoist to the middle floor. It knows if it needs to start moving up or down by looking at the down and up limits. BUT after the person releases the button and before it arrives at the middle floor, how does it know which way to go? It needs some memory of the 'state' - for example, it need to know that it was moving down and it needs to keep moving down until any limit switch is touched. (Or someone presses the emergency stop button. Then if it does stop in between limit switches, can it remember where it is?)

Hi morganS

Many thanks for your reply.

I know that a state machine, is the best option of all options, I have read and read and read forums about this state machine, and examples.. but I just cant get it into my head!.. I am missing something out, and dont know what it is. Its just like, everbody speaks about it the same way, but in a different language!!, and yet, I have not heard my language. That is how I feel with the state machine. Maybe because I am a total beginner in programming language. A lot of words seem different, but yet have the same meaning, and I am finding this very confusing.

I can understand what you are saying, and I can picture it, but when it comes to writing, I get totally blocked. I keep looking at examples, and I think it is worse.

Re my sketch, and your question of How the elevator is going to go up or down, when someone presses the middle floor, I had wrote this part in the sketch.

ButtonState 7 and 8, are limit switches (physically connected between gnd and pin 7), using a pullup resistor.

buttonstate 3 is the Call Button.

As you said, I have to correct the names, and put some comments in the sketch.

Below is the part of the sketch, that determines if the elevator has to go up or down.

if ((buttonState3 == HIGH) && (buttonState7 == HIGH) && (buttonState8 == LOW))

{
digitalWrite(ledPinUp, HIGH);
delay (10000);
}
else if ((buttonState3 == HIGH) && (buttonState7 == LOW) && (buttonState8 == HIGH)) {
digitalWrite(ledPinDown, HIGH);

Yes, that part was obviously how it decides to go up or down to get to the middle.

A successful state machine requires a state diagram. You must draw it on paper. Don't try to draw it on a computer or start writing code. Think about it from the point of view of the Arduino: it doesn't know anything about the world except what the buttons and limit switches tell it. You will be surprised how complex your state diagram can get with only 3 buttons and 3 switches.

Have a look at the diagram I attached to this message. It's a very simple state machine.

o.k.. saw your diagram. So I try to start with a diagram on paper, and post it here first. Basically I have to draw all the motion, and actions to take on paper.

Lets give it a try. :slight_smile:

Thanks.

ButtonState 7 and 8, are limit switches (physically connected between gnd and pin 7), using a pullup resistor.

buttonstate 3 is the Call Button.

Then change their names to reflect what they are - why make it harder for yourself and others to read your code?

true..true