Loading...
  Show Posts
Pages: 1 [2]
16  Using Arduino / Project Guidance / Re: Audomatic Garage Door Close on: September 27, 2012, 12:25:53 pm
I've tried a few approaches but can't get any to work.

...

A viable solution is one that works - this does.

Well, I'm confused. Does it work or not?

As I said in my first and subsequent posts (and as demonstrated in the linked video) the code, as it is written, works. The only thing that I cannot get working is when the override is activated is having a beep go off every x number of minutes.

I'm sorry if I misunderstood you but it seemed as if you were criticizing me, and confused, by my defining the Arduino pins as names (like DoorShutSW). This is what I meant by my "basic stuff" quip. I'm not sure why you'd criticize me doing this when it seems to be SOP in every single example I've ever seen, including the ones on the official Arduino example page.

If I've defined pin 6 as DoorShutSW then it stands to reason that I could then reference pin 6 as DoorShutSW in the rest of my code. Am I wrong?

while(PIR1, PIR2 == HIGH);

All I can say is that this works. Please understand that I'm not a programmer so my approach has basically been throwing things at the wall and using what sticks. This stuck. I saw the use of the comma in this way in some other code (can't remember where at this point) so I tried it and it worked.

while(digitalRead(PIR1) == HIGH || digitalRead(PIR2) == HIGH);

You'll note that I used the || (or) operator in other parts of my code but in this particular statement could not get it to work, I was probably writing it wrong. You seem convinced that my use of the comma does not work, all I'm saying is that it does or at least seems to as far as I can tell. If it is in fact wrong then it is wrong in form and not functionality. I'll try your suggestion when I get back in front of my Arduino.

You also pointed out

while (DoorShutSW == HIGH);

and said

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

DoorShutSW is defined as PIN 6, I'm saying while PIN 6 is HIGH do this. As I understand it a statement like (digitalRead(DoorShutSW) is basically shorthand (or another of writing) (DoorShutSW == HIGH) this is what I remember being told in by someone here on another project I was working on anyway and I've seen both ways in use. In any case it works, it seems to be SOP, so again your criticism/confusion is... confusing.

As for the goto, I know that using goto is frowned upon. In this case, with something as uncomplicated as this, I'm not sure I see what the problem is but again - I'm just throwing at the wall and seeing what sticks. In thinking about this more I'm wondering if having a sub-routine for the override would allow me to accomplish the same result without using the goto. I'm open to suggestions...

Again, as it's written the code works. The only thing that I cannot work out is how to have a beep go every x number of minutes while the override is active.

I'm sorry for my crass responses. You came off a bit crass and it felt like your first post was dedicated to detailing how stupid I am. I was in a mood last night, sorry if I misunderstood. I really am wanting to learn and improve where necessary.
17  Using Arduino / Project Guidance / Re: Audomatic Garage Door Close on: September 27, 2012, 01:13:17 am
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
18  Using Arduino / Project Guidance / Audomatic Garage Door Close on: September 26, 2012, 11:57:32 pm
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.
19  Using Arduino / Project Guidance / Re: Read Line Voltage (US 120v) on: February 25, 2012, 04:02:21 pm
Thanks for the tip.

Could have gone without the snark though.
20  Using Arduino / Project Guidance / Read Line Voltage (US 120v) on: February 25, 2012, 03:18:28 pm
I'm working on a project with my uncle - he wants to use an Arduino to read an input voltage and if the voltage drops or raises beyond a pre-defined threshold then the Arduino would do A (voltage drop) or B (voltage raise).

The issue is that the voltage we need to monitor is US line voltage (120 volts) and I'm not sure how to approach the problem. Any thoughts on the feasibility and/or possible solutions?

Thanks,

Adam   
21  Using Arduino / Project Guidance / Re: Timer on: December 13, 2011, 12:27:53 am
@John

Thanks for all your help -- the code works perfectly. With just a couple of additions below is what will likely end up being the final version of the code:

Code:
const int PumpSwitch = 2; // Arduino PIN that the pump switch is connected to
const int Pump =  3; // Arduino PIN that the pump control is connected to
const int AlarmLED =  4; // Arduino PIN that the alarm LED is connected to
const int AlarmSpeaker = 5; // Arduino PIN that the alarm speaker is connected to

bool PumpState = false; // Initializing the pump state as off
unsigned long PumpRunTime = 0; // Initializing the pump running time

// The following set whether the Arduino PINs are inputs or outputs
void setup() {
  pinMode(PumpSwitch, INPUT);
  pinMode(Pump, OUTPUT);
  pinMode(AlarmLED, OUTPUT);
  pinMode(AlarmSpeaker, OUTPUT);
}

void loop(){
  if (digitalRead(PumpSwitch)) { // If the status of PumpSwitch is HIGH then the pump should be on
    if (!PumpState) {
      PumpState = true; // Pump should be on
      PumpRunTime = millis();  // Start the pump running time
    }
  }
// If the status of PumpSwitch is LOW then the pump should be off
  else {
    PumpState = false;
  }

  digitalWrite(Pump, PumpState);
 
// If the pump has been on longer than 5 seconds, turn it off and sound the alarm untill reset

  if (PumpState && millis() - PumpRunTime > 5000) {
    // LED has been ON for a full 5 seconds
    digitalWrite(Pump, LOW);  // Turn it off
    digitalWrite(AlarmLED, HIGH);  // Turn on the alarm LED
    tone (5, 4000); // Sound a 4000 hertz alarm
  while (true);  // Loop here untill reset to prevent the pump from coming back on
  }
}

Again, thank you so much,

Adam
22  Using Arduino / Project Guidance / Re: Timer on: December 12, 2011, 02:13:47 pm
@John

Thanks, I'll give the code a try as soon as I get home tonight.

Much appreciated,

Adam
23  Using Arduino / Project Guidance / Re: Timer on: December 12, 2011, 11:59:09 am
@John

Your code worked - the LED came on when the switch was turned on, and went off when it was turned off. However, the LED (LedGo) would not automatically turn off after the defined time... I'm not sure why so I tried to adapt points from your code to what I had and it works except for the aforementioned issue of it seemingly still counting after the switch first goes HIGH which in turn prevents the LED (LedGo) from coming back on even if it is switched off before the specified time.

Thoughts?

Again, thanks so much for your help, I've already learned a lot really appreciate it.

Adam
24  Using Arduino / Project Guidance / Re: Timer on: December 12, 2011, 12:12:11 am
Of note,

As I noted in my last post - If I cycle the switch several times, or turn it on then off and wait then the LED (LedGo) does not come back on if the specified time was reached... what's also noteworthy is that the second LED (LedAlarm) does not come on...

I'm lost.
25  Using Arduino / Project Guidance / Re: Timer on: December 11, 2011, 11:47:26 pm
Ok below is my code - thanks John for your tips.

This code works: switch goes HIGH and D2 goes HIGH, turning on the LED and it goes off if on for longer than specified. The only problem is that even if the switch goes LOW it still seems to be counting because after the specified time the LED (LedGo) does not come back on...

Code:
const int Button = 2;
const int LedGo =  3;
const int LedAlarm =  4;

bool ButtonState = false;
bool LedState = false;
unsigned long StartTime = 0;


void setup() {
  pinMode(LedGo, OUTPUT); 
  pinMode(LedAlarm, OUTPUT);   
  pinMode(Button, INPUT); 
}

void loop() {
  ButtonState = digitalRead(Button);
 
  if (ButtonState == true && LedState == false && millis() - StartTime < 5000) {       
    digitalWrite(LedGo, HIGH);
    LedState = true;
    StartTime = millis();
  }
   
  else if (ButtonState == false) {       
    digitalWrite(LedGo, LOW);
    LedState = false;
    StartTime = 0;
  }
 
  else if (ButtonState == true && LedState == true && millis() - StartTime > 5000){
    digitalWrite(LedGo, LOW);
    digitalWrite(LedAlarm, HIGH);
  }
 
}
26  Using Arduino / Project Guidance / Re: Timer on: December 11, 2011, 09:21:26 pm
Correct - either way the issue with my code is that the second IF will not execute until the the switch is LOW... as long as the switch remains HIGH it loops in the first IF statement until the switch goes LOW.

It works but I need it to not care about the state of the switch - if D3 and/or the switch are HIGH for too long then I need D3 to go off and D4 to go on.

My coding skills are lacking...

Thanks,

Adam
27  Using Arduino / Project Guidance / Re: Timer on: December 11, 2011, 09:04:14 pm
Thanks John for your help.

I realized that I was not completely clear - I need the state of the switch monitored so that if it stays on longer than 5 seconds it will put D3 LOW and D4 HIGH.

I'm working on a system to automatically fill a tank and I need to have it so that if the pump switch gets stuck the Arduino will it off after a set period.

So to clarify - The Arduino monitors the state of the switch, when it goes HIGH it turns D3 HIGH. Once the switch is LOW it puts D3 back to LOW and continues to monitor the state of the switch; but if the switch is HIGH for longer than 5 seconds it puts D3 LOW and sets D4 HIGH and stays there until reset.

I've been playing around with the code below and your suggestion helped, the only problem is that the second IF statement only gets executed when the switch is turned off.

Code:
const int Button = 2;
const int LedGo =  3;
const int LedAlarm =  4;


int ButtonState = 0;
int LedState = 0;
long StartTime = 0;


void setup() {
  pinMode(LedGo, OUTPUT); 
  pinMode(LedAlarm, OUTPUT);   
  pinMode(Button, INPUT); 
}

void loop(){
  ButtonState = digitalRead(Button);
 
  if (ButtonState == HIGH) {       
    digitalWrite(LedGo, HIGH);
    LedState = 1;
    StartTime = millis();
  }
 
  if (LedState = 1 and millis() - StartTime > 5000) {
    digitalWrite(LedGo, LOW);
    digitalWrite(LedAlarm, HIGH);
  }
}
28  Using Arduino / Project Guidance / Timer on: December 11, 2011, 06:00:46 pm
Hello,

I'm just getting started with Arduino and I'm looking for some coding help with a project that I'm starting to work on... I'll give a high level example of what I'm after.

A momentary switch is connected to PIN 2.

The Arduino monitors the state of the switch and if it is HIGH (switch is turned on) it sets the state of digital PIN 3 to HIGH, turning on an LED.

Once digital PIN 2 is LOW (switch is off) it sets digital PIN 3 back LOW (turning off the LED)

If the state if digital PIN 3 is HIGH for longer than, say 5 seconds, the Arduino automatically sets it back to LOW (turning off the LED) and sets digital PIN 4 to HIGH and loops until it's reset.


I have the code from the Arduino button example so I can read the state of the switch and control the state of the LEDs from it but I'm not sure how to do the timer...

Any help is appreciated.

Adam
Pages: 1 [2]