Robot vacuum garage door

So I have this setup:
A linear actuator opening and closing the door.
A limit switch attached to the charging station to read if the vacuum is on the station.

My goal is that when the robot leaves the charging station the door will open and close againg when its back.

I’m still waiting for my limit switches - but thought I would start tinkering with some code and get some feedback if I’m on the right track.

The idea is to use val to avoid that the close relay turns on everytime it reads the limit switch as closed.

int RELAY1 = 3;
int RELAY2 = 5;
int lmtswtch = 4;
int val = 0;

void setup() {
  pinMode(RELAY1, OUTPUT);
  pinMode(RELAY2, OUTPUT);
  pinMode(lmtswtch, INPUT);
}

void loop() {
  if ( lmtswtch == HIGH && val == 0 )
    digitalWrite(RELAY1, HIGH);
    delay(10000);
    digitalWrite(val, 1);
  if ( lmtswtch == LOW && val == 1 )
    digitalWrite(RELAY2, HIGH);
    delay(10000);
    digitalWrite(val, 0);

}

if ( lmtswtch == HIGH Never gonna happen.

You need to digitalRead the limit switch pin.

So this would fix it?

if ( digitalRead(lmtswtch) == HIGH && val == 0 )

The indentation of your code looks to me like you have an idea about how your code should behave; an idea that the compiler doesn't share.

That'll show up in testing.

digitalWrite(val, 0);I'm not really clear what is attached to pin 0, or how val will ever equal 1

Oh, I misunderstood the purpose of val then. My idea was that whenever the door opened - a value would tell the code that it had been opened - so it knew that it could close. And if it hadn’t been open - it would not try to close it.

I don’t know if this is possible?

If I just use the limit switch - I guess that it would try to close the door everytime it read the switch as LOW, even though it hadn’t been HIGH since the last time it ran?

Is there a way to tell the second part of the code (closing the door) to only run if the limit switch has been HIGH since last time it ran the code?

afonneland:
Is there a way to tell the second part of the code (closing the door) to only run if the limit switch has been HIGH since last time it ran the code?

Yes - have a variable that contains the state of the door. Set it when you open or close. Check it when the limit switch is low to see whether closing makes sense.

we don't know what val is supposed to be here. need more to go on.

I have a nano monitoring some ultrasound sensors to tell me when my garage doors are open and if they stay open more than 20 minutes will send power thru a pin to a buzzer. you could do something like that and then incorporate your vacuum ideas to that.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.