HELP ME PLZ !!!

Hello arduino community im a average student making a arduino based project but i don't have any expirience at all . im building a arduino controled lock maquette , made in glass and it has 4 doors controled by servos and 2 water pumps with diferent jobs . the problem is that i want to control 2 diferent actions , the upper movement and the down one , to raise or lower the boat , i want to initialize this two actions with 2 diferent buttons but i only have 2p switches can you guys plz help me i am behind schedules and i am alone at this .

Sorry for bad english

ElFixe:
i am behind schedules

Not our problem.

Were you expecting source code ready made for you to submit to your professor as the completed project?

Wire your switches between pin and ground. Use the internal pullups (see pinMode reference). If the switch is pressed / active, digitalRead will return low, else high.

Use that to do whatever you need to do.

ieee488:
Not our problem.

Were you expecting source code ready made for you to submit to your professor as the completed project?

thank you for being so nice , im will not submit it to my professor because he is an engineer who doesn t help me and i will submit it to a juri thx for helping

what is a lock maquette ?
lock maquette
I am not sure, but I am guessing you want to control locks for a boat that goes between two bodies of water.

you say 4 doors. is that two gates (with 2 doors) one one pair on each end ?

one pair closes and seals.
the other pair opens and the boat enters.
the second pair closes and seals.
water is allowed to enter (or exit) until the level is equal to the other level ?

it seems that if you can open and close the locks and seal them, then you are mostly done, just the controls.

press button #1, the lower gate closes and seals.
the pump will fill the space between maybe time your pump or have a sensor to know when it is filled
open the second set of gates.

press button #2
close the upper gate
drain the water until they are equal to the lower level.
open the lower gates.

it sounds simple enough. what are you having problems with ?

I agree with @dave-in-nj. I suspect the main problem at this stage is the lack of time spent thinking.

Have a look at Planning and Implementing a Program

...R

Hi,

lock maquette

Its a model of a lock, I would think a canal lock, like in UK and Europe..

Nice project to build, but not for beginners, if its a class project, then I'd be expecting more tutorial support.
Surprised that you have been given project without any instructons in Arduino programming.

Tom... :slight_smile:

ElFixe:
Hello arduino community im a average student making a arduino based project but i don't have any expirience at all . im building a arduino controled lock maquette , made in glass and it has 4 doors controled by servos and 2 water pumps with diferent jobs . the problem is that i want to control 2 diferent actions , the upper movement and the down one , to raise or lower the boat , i want to initialize this two actions with 2 diferent buttons but i only have 2p switches can you guys plz help me i am behind schedules and i am alone at this .

Sorry for bad english

Controlling multiple actions with a single arduino is no problem. You need to define what is to happen and in what sequence, and what state information is required in your program, to "remember" what is currently going on.

My suggestion:

Initial state

Upper door is closed.
Lower door is open, allowing boats into the chamber.
No pump is running

Assuming one pump to fill chamber with water, and one to empty it, since opening the doors probably does not work if water higher on the upper side, with water pressure holding them shut.

Button 1

Press, hold and release to do the following:

  • if lower door is open, then close it
  • pump water into chamber, raising water level for as long as button is held
  • when button is released, open upper door

Button 2

Press, hold and release to perform the following:

  • if upper door is open, then close it
  • pump water out of chamber, lowering water level for as long as button is held
  • when button is released, open lower door

You need to adapt these descriptions to your needs, and take it from there. Best of luck!

ElFixe:
thank you for being so nice , im will not submit it to my professor because he is an engineer who doesn t help me and i will submit it to a juri thx for helping

"nice" has nothing to do with it.
Submitting someone else's work as your own is cheating.

TomGeorge:
Nice project to build, but not for beginners, if its a class project, then I'd be expecting more tutorial support.
Surprised that you have been given project without any instructons in Arduino programming.

Have you ever read a post here that claimed that they were given all the instructions? ? ?
It is always someone else's fault that they never received the proper instructions.
The professor never explained anything, blah blah blah blah.

ieee488:
Have you ever read a post here that claimed that they were given all the instructions? ? ?

No. But that does not mean that they were not give sufficient instructions :slight_smile:

More likely they were not listening or did not seek clarification at the right time.

...R

so today i followed your hint and made this code but it doens t work neither can you guys help me or something»?

i am a student and this is my final work i created by myself and i have to present it to a juri to get a final note , if possible give me answers plz

Niveis_e_servos_3.ino (2.54 KB)

Robin2:
No. But that does not mean that they were not give sufficient instructions :slight_smile:

More likely they were not listening or did not seek clarification at the right time.

...R

More like they weren't paying attention for the entire semester. :slight_smile:

They act like these projects are a total surprise. ::slight_smile:

You can post with code tags rather than attaching. More people will look at your code.
Your code does not compile, and contains several bracket, brace and syntax errors.

#include <Servo.h>

Servo montante1;
Servo montante2;
Servo jusante1;
Servo jusante2;
byte sensorPin[] = {10, 11};
byte ledPin[] = {12, 13}; // number of leds = numbers of sensors
const byte sensors = 2;
int level = 0;
int motor = A4;
int valve = A5;
const byte button0pin = 2;
const byte button1pin = 3;
byte button0state;
byte button1state;
//#define wayUp ();

//#define wayDown;
//#define checkButtons;


void setup() {

  montante1.attach(6);
  montante2.attach(7);
  jusante1.attach(8);
  jusante2.attach(9);
  pinMode(button0pin, INPUT_PULLUP);
  pinMode(button1pin, INPUT_PULLUP);
  Serial.begin(9600);

  for (int i = 0; i < sensors; i++) {
    pinMode(sensorPin[i], INPUT);
    pinMode(ledPin[i], OUTPUT);
  }
  pinMode(motor, OUTPUT);
  pinMode(valve, OUTPUT);
}

void loop() {

  checkButtons();
  subir();
  descer();


}


void checkButtons() {
  button0state = digitalRead(button0pin);
  button1state = digitalRead(button1pin);
}

void subir {
  if (button0state == LOW && button1state == LOW) {
    return;
  }


  if  (button0state == LOW && button1state == HIGH) {
    jusante1.write(90);
    jusante2.write(90);

    level = 0;
    for (int i = 0; i < sensors; i++) {
      if (digitalRead(sensorPin[i]) == LOW) {
        digitalWrite(ledPin[i], HIGH);
        level = sensors - i;
      } else {
        digitalWrite(ledPin[i], LOW);
      }
    }
    switch (level)
    case 1:

    digitalWrite(motor, HIGH);
    break;
  case 2:

    digitalWrite(motor, LOW);
    break;

  default:

    digitalWrite(motor, LOW);
    break;

    montante1.write(90);
    montante2.write(90);
  }
  if (button0state == HIGH && button1state == HIGH) {
    return;
  }

  void descer {
    if (button0state == LOW && button1state == LOW) {
      return;
    }
    if  (button0state = HIGH &&  button1state == LOW) {
      montante1.write(90);
      montante2.write(90);
      level = 0;
      for (int i = 0; i < sensors; i++) {
        if (digitalRead(sensorPin[i]) == LOW) {
          digitalWrite(ledPin[i], HIGH);
          level = sensors - i;
        } else {
          digitalWrite(ledPin[i], LOW);

        }
        switch (level) {
          case 1:

            digitalWrite(motor, LOW);
            break;
          case 2:

            digitalWrite(motor, HIGH);
            break;

          default:

            digitalWrite(motor, HIGH);
            break;
        }
        jusante1.write(90);
        jusante2.write(90);
      }

      if  (button0state == HIGH && button1state == HIGH) {
        return;
      }
    }

    /*void abrircomportasjusante



      void fechar comportas jusante



      void bomba situação 1


      void abrir comportas montante


      void fechar comportas montante

      void bomba situação 2

    */

If you place each opening { or closing } on a new line, the use of autoformat (Control+t) on your code to help find all the bracket errors.

Here's one thing to fix to get you started. When you define the functions subir and descer the syntax needs(). Compare how check Buttons is set up differently than subir and descir.

void subir {}

void checkButtons() {}

I went through your code and did get it to compile, so if you clean it up and study the bracket arrangements you should be able to do that.

Can you plz send me what you got i have no more options right now ! :o

@ElFixe, you have been given several pieces of advice. Act on them and post the resulting code together with the error messages (if it won't compile) or a description of what it actually does if it does not do wht uou want.

...R

Start by fixing the first error message and ignoring the rest. Often, a flood of error messages result from the original error. So fix the first one, many may go away.

A function declaration needs '()'

void subir {

should be

void subir() {

Same for descer; change both and compile

Next your missing a closing '}' at the end of the subir() function; add it and compile

}  // <---------- ADD

  void descer() {

Next your switch in subir() misses a '{'

    switch (level)
    {  // <---------- ADD
      case 1:

Change to the above and compile again

Now you're missing another '}' at the end of subir(). Fix and compile

And lastly your missing a '}' at the end of the descer() function. Fix and complie.

Hint:
Press T in the IDE; it will properly indent the code. You can than easily spot the errors. E.g. function definitions should always start at the beginning of the line (no indents). The closing curly of a function should also be on the first position of the line.

Would be nice if we could get a picture of what you got in that way we can work with our imagination :smiley:
and give ideas of what you can do and fast.

What you ask is totally basic beginner programming, if you had at least 2 months of experience using
arduino you wouldn't be here :smiley:

Give us please a full list of components you have/want to use and a picture of your "lock maquette"
or at least a paper hand design if you don't have it yet build (and dimensions).

and personally if I'm in the mood I can make/program you a full project in the next 2 days :smiley:
(not in materials just paper design/hardware and code)

D.60

Hi,
Can you post a picture of the model Lock that you are using so we can workout how to control your hardware.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Thanks .. Tom... :slight_smile: