Go Down

Topic: Audomatic Garage Door Close (Read 3 times) previous topic - next topic

rocketboy001

I'm working on a project that will automatically close a garage door after a set period of time. I'm nearly finished but have one lingering problem - when the override is active I want there to be a beep every x number of minutes (say every 5 minutes) until the override is deactivated. I've tried a few approaches but can't get any to work. I'm hoping that someone can look over what I have and suggest a solution. The code is heavenly commented because I'm writing this for my uncle and I want him to know what's going on in the code.

Also, I'm not a programmer and this is only my second attempt at making something with the Arduino so... I'm open to suggestion to improve the code.

Thanks!

I've attached the code 'cause it was too long to post directly.

Nick Gammon

Sorry, I'm unable to look at code with goto in it. Perhaps someone else can.

Seriously, refactor without it, and without so much confusing code.

As for this:

Code: [Select]

    while (DoorShutSW == HIGH);


Code: [Select]
const int DoorShutSW = 6; // Arduino PIN that the switch for detecting a closed door is connected to

HIGH is 1, DoorShutSW is 6, so that condition will never be true.




Code: [Select]

    while(PIR1, PIR2 == HIGH);


That almost certainly doesn't do what you think it does.

rocketboy001

Lol.

I'm sorry I have to laugh. You start off by criticizing my use of goto when you don't seem to understand the basics.
There is no reason to refractor my use of goto, it works and does not seem to be causing any issues that would cause me to not use it (like an endless loop). A viable solution is one that works - this does. In any case with my limited knowladge, I was unable to come up with an alternative solution. If you are able to offer a better solution - rather than just curt criticism - then I'm all ears.

As noted in the code comments DoorShutSW is a variable that is assigned to pin 6 on the Arduino. Attached to pin 6 is a switch which I'm monitoring to see if it goes high or low (on/off). This is basic stuff and I'm not sure why it's confusing.

while(PIR1, PIR2 == HIGH);

Again, as noted in the comments I'm monitoring the state of two PIR sensors this is effectively saying if either PIR1 or PIR2 is high then continue to execute the if statement.

I assure you that the code works as I have tested it with the hardware (switches, pir sensor, etc) connected to the Arduino. The only issue I'm having is how to get a beep every x number of minutes when the override is active.

I'm open to suggestions as to how to improve the code. Criticizing my work (when I've openly admitted I'm not a programmer) while offering no solutions seems like a waste of both your time and mine.

If it helps here is a video of the attached code in action. It's a bit lengthy and dry but I explain what I'm trying to do and show how it's currently working.

https://vimeo.com/50017640

Thank you,

Adam

dxw00d

#3
Sep 27, 2012, 08:54 am Last Edit: Sep 27, 2012, 09:00 am by dxw00d Reason: 1
Code: [Select]
  while (DoorShutSW == HIGH);
Quote
As noted in the code comments DoorShutSW is a variable that is assigned to pin 6 on the Arduino. Attached to pin 6 is a switch which I'm monitoring to see if it goes high or low (on/off). This is basic stuff and I'm not sure why it's confusing.


Yes, it is basic stuff, but it's confusing because you are evaluating the pin number (which is fixed at 6), not the state of the pin.


Code: [Select]
   while(PIR1, PIR2 == HIGH);
Quote
Again, as noted in the comments I'm monitoring the state of two PIR sensors this is effectively saying if either PIR1 or PIR2 is high then continue to execute the if statement.


No, that isn't saying that (you can look up the C comma operator if you wish - http://en.wikipedia.org/wiki/Comma_operator). You are also evaluating pin numbers, not states, again. You would need something like:

Code: [Select]
while(digitalRead(PIR1) == HIGH || digitalRead(PIR2) == HIGH);

It wouldn't exactly 'continue to execute the if statement', it would sit in this while loop until both of the PIRs evaluated to LOW.

Nick Gammon


I'm sorry I have to laugh. You start off by criticizing my use of goto when you don't seem to understand the basics.


Sorry about that 99.

I'll have to re-read the basics.

Quote
Again, as noted in the comments I'm monitoring the state of two PIR sensors this is effectively saying if either PIR1 or PIR2 is high then continue to execute the if statement.


That's utter nonsense, but believe it if you want to.

Go Up