HELP!!

hello all

Before I go into my problem I am using others code. I am in a rush to get a prototype together so I am trying to learn as i go.

Thank you to those whos codes I am using!!

I am new to Arduino programming.

My project sounds easy on paper (I'm sure to most of you it will be easy)

I am designing a door controller. The door slides open and closed. The aim is that a button is pressed (open) the motor turns till it hits a limit switch. Then the closed button is pressed and the motor turns the other way until it hits the closed switch.

i have included the code (I think) as an attachment and a picture like my wiring. except im using more switches.

currently my main questions are:

you have to hold a button to make the motor turn: which part of the code controls press/release rather than press/hold?

i can make the limit switch funtion but not as i want: if i change the code ( while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(-1);)} to while (digitalRead(ReverseLimitSwitchPin) != LimitSwitchActivated) {
stepper.step(0); then both limit switches need to be held down and i still have to additionally hold a motor direction button.

These are the main questions at the moment. once this is running correctly i will need to add two more sensors to interrupt the closing door (in case some walks under it while closing) but one step at a time.

I am using a nema 17 motor, a4988 stepper driver, the switches are large micro switches (NO, NC and common) plus a breadboard and a ton of wires!!!

any help or guidence is greatly appreaciated!! if you need any more info let me know!!

cheers

I know i have a lot to learn and i am really enjoying this project. But i want to have a working prototype to demo at some point in the next week or two.

trial_2.ino (2.73 KB)

Sounds to me like you are on a deadline and you choose to push off the project till last minutes.

Writing code and debugging said code are only 2 part of this hobby. You mentioned that you used other people's code and now you want other people to modify it to your specifications. What is your contribution to the project then?

Anyway, sorry for the non-helpful comments. So here is the helpful comment: post your code in code tags so it looks like this:

//your code here

since your code is small. It makes it easier for people to look at the code.

You’ll soon learn over time that contributors rarely like analysing Fritzy diagrams. It suggests you really weren’t bothered to invest the effort to draft out the proper block/schematic - so we can figure it out for you.

This looks like you had a thought. found where others had done bits of what you imagined - then plonked them all together hoping it would just work

sorry project development doesn’t work like that.

Your wiring is wrong and the code is wrong too, It's a mess.

Are giving you a brief code and button diagram to match, though if this is the entire project i hopes its for school not a late hand in for university or collage as a child could make this.

#include <Stepper.h>
const byte open_button = 2; //OPEN Button
const byte close_button2 = 3; //CLOSE Button
const byte openLimitSwitchPin = 4;
const byte closeLimitSwitchPin = 5;
const byte numberOfStepperSteps = 200; // number of steps that your stepper motor has
Stepper stepper(numberOfStepperSteps, 8, 9, 10, 11);

void setup() {
  Serial.begin(115200);
  pinMode(open_button,INPUT);
  pinMode(close_button2,INPUT);
  pinMode(openLimitSwitchPin,INPUT);
  pinMode(closeLimitSwitchPin,INPUT);
}

// loop() the Arduino continuously cycles through this as fast as it can
void loop() {
  if (digitalRead(open_button) == HIGH) { // open door
    moveDoor(true);
  }
  else if (digitalRead(close_button2) == HIGH) { // close door
    moveDoor(false);
  }
}

void moveDoor(bool openDoor) {
  if (openDoor) {
    Serial.println(F("Opening door"));
    // Step forward until the limit switch is activated
    while (digitalRead(openLimitSwitchPin) != HIGH) {
      stepper.step(1); // move one step at a time, 200 steps per turn = 1.8 degree's per step
    }
  }
  else {
    Serial.println(F("Closing door"));
    // Step reverse until the limit switch is activated
    while (digitalRead(closeLimitSwitchPin) != HIGH) {
      stepper.step(-1); // move back one step, i.e. reverse
    }
  }
}

Learn how to read and write a proper wiring diagram too, Fritz is for kids to learn electronics.

I was asked to help on the project today. So no I didn’t leave it last minute. It’s a case of someone asking me for help and I’m doing what I can.
Yes I have combined people’s code and no I didn’t expect it to work with out changing, most likely l, a vast majority of it. It did however give me a starting point for some of the knowledge I gained from years ago.
Unfortunately due to work commitments I have not had time to carry on a hobby I had several years ago when I built a 3D printer. The knowledge I gained back then is lost to me now so I’m starting from scratch. So now that we’ve all had our unhelpful comments. Can anyone point me in the right direction. I will add the code tomorrow as I’ve put my laptop away.

I gave you a code that does what you asked, just change the button wiring to match my diagram.

TBH, you’ve been caught in a difficult place.
You need to tell your friend what you just posted to us.
Your lack of kowledge and his lack of preparedness is not a good recipe for success.
You’re a good friend, but maybe you should help him locate a more appropriate source of help. Perhaps paid...?

I’ve sent him screen shots of it all. He too was passed this last minute. Seems a pass the buck kinda game.
I’m looking forward to sinking my teeth into it. Unfortunately time is an issue. Apreaciate the help and the code it will help a lot.
I have a lot to learn and I’m looking forward to it!! So far it’s great fun. It’s rekindled an enjoyment I had all those years ago. The main project isn’t for quite a while but he wants to show the possibilities of how it can work.
As far as I know he has a company to make the electronics board, another supplying a motor and controls and others for other hardware etc...

Thanks again guys will get it set up tomorrow. Then I’m going to try to expand and add two sensors to open the door if someone walks under it while it’s closing

Two more proactive points....
Have a look at the internals of commercial door openers they are obvious, but many people don’t think they work the way they do.
This is due to mechanical advantage, cost and reliability.

The second point to consider is failure modes. So you can open the door (or whatever you need).