Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Turn LED on if photoresistor has detected light for 5 minutes on: March 20, 2013, 01:15:04 pm
I changed the variable to accurately describe the value.

I have a threshold of about 400 or less with the photo resistor when it is "dark" .  Anything over 400 is assumed to have detected light.  It will not be exactly 400 though.  What are your thoughts?

Code:

int analogPin = A0;    // Photo Resistor
int ledPin = 13;

int timerval = 0;


void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communications:
  Serial.begin(9600);
}

void loop()
{

 static unsigned long lastTimeInputWaslessThanFourHundred = 400;
    if (analogRead(analogPin) == 400)
        lastTimeInputWaslessThanFourHundred = millis();

    if (millis() - lastTimeInputWaslessThanFourHundred > 5UL*60UL*1000UL) {
        // It has been five minutes or more since the last time the input was 0
        digitalWrite(ledPin,HIGH);
        Serial.println("LED ON");
    }
    else {
        // It has been less than five minutes since the last time the input was 0
        digitalWrite(ledPin,LOW);
       Serial.println(analogRead(analogPin));
     }
   
 
}

2  Using Arduino / Programming Questions / Re: Turn LED on if photoresistor has detected light for 5 minutes on: March 20, 2013, 12:35:44 pm
Thank you very much for this simple solution.

I am now having an issue that when the Arudino is power cycled or turned on for the first time, the second 'if' statement runs five or six times in a row.  What are your thoughts on this?

Here is what I have now:

Quote

int analogPin = A0;    // Photo Resistor
int ledPin = 13;

int timerval = 0;


void setup()
{
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communications:
  Serial.begin(9600);
}

void loop()
{

 static unsigned long lastTimeInputWasZero = 400;
    if (analogRead(analogPin) == 400)
        lastTimeInputWasZero = millis();

    if (millis() - lastTimeInputWasZero > 5UL*60UL*1000UL) {
        // It has been five minutes or more since the last time the input was 0
        digitalWrite(ledPin,HIGH);
        Serial.println("LED ON");
    }
    else {
        // It has been less than five minutes since the last time the input was 0
        digitalWrite(ledPin,LOW);
        //Serial.println(analogRead(analogPin));
     }
    
  
}

3  Using Arduino / Programming Questions / Turn LED on if photoresistor has detected light for 5 minutes on: March 19, 2013, 05:34:04 pm
Good Afternoon,

I am trying to determine how to turn an LED on after a Photo resistor has detected a value of 1 or greater for 5 minutes.

My assumption is that I need to increment a variable, if analog input is > 0 and then use delay(1000) to pause for one second and then check the analog input.  Once the Variable reaches 300 (5 minutes) than set the LED pin to high.

A couple of items that I am struggling with:

1.) How do I reset the variable back to 0 if the analog value is 0 before the variable reaches 300.
2.) Once the variable reaches 300 I want to turn the LED on and stop the sketch until the arduino is reset or the analog input is at 0.

Here is what I have so far.  Any help would be greatly appreciated.
--------------------------

const int analogPin = A0;    // Photo Resistor
const int ledPin = 13;     

int timerval = 0;


void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communications:
  Serial.begin(9600);
}

void loop() {
  // read the value of the Photo Resistor:
  int analogValue = analogRead(analogPin);

  // if the timerval = 300, turn on the LED or increment timerval by 1:
  if (analogValue > 0) {
    ++timerval;
    delay(1000);

    if (timerval = 300){
    digitalWrite(ledPin,HIGH);
    }
   
  }
  else {
    digitalWrite(ledPin,LOW);
    timerval = 0;
    delay(1);
  }

  Serial.println(analogValue);
  Serial.println(timerval); 
 
}
4  Using Arduino / Programming Questions / Re: Send email based on event on: January 25, 2013, 05:50:14 pm
Thank you very much Zoomkat I'm going to give this a shot
5  Using Arduino / Programming Questions / Re: Send email based on event on: January 24, 2013, 09:47:37 pm
Thank you for the direction.  I will definitely take a look.  This will be in a remote location.  Would it make sense to provide more logic to check in with device to verify that it is online?
6  Using Arduino / Programming Questions / Send email based on event on: January 24, 2013, 06:08:37 pm
Good Afternoon,

I am currently working on a project that is detecting light.  I have a system that will turn a light on when it is in an error state.  I currently have a photo resistor that is detecting this light.  I would like to send an email if this light is on for more than 2 minutes.  Any suggestions on sending emails?

Any help would be greatly appreciated.  I looked through several online services and Nimbits seems to be the only that will an email based on an event. 
7  Using Arduino / Programming Questions / Re: Control Two LED's with one button on: October 08, 2012, 11:51:22 am
Good Morning,

I was assuming a button press just that.  Pressed and then let up.  Is there a way to make it so that if the button is help down for an unspecified amount of time and then let up, it only counts as one button press?

Thank you for all of your assistance with this.
8  Using Arduino / Programming Questions / Re: Control Two LED's with one button on: September 29, 2012, 12:49:52 pm
Thank you that was very useful
9  Using Arduino / Programming Questions / Control Two LED's with one button on: September 27, 2012, 03:35:16 pm
I am having a hard time finding an example on how to control two LED's with one button.

What I would like to do is turn one LED on with a button press and then on the second button press turn the first LED off and turn the second LED on.

I am thinking that I need to a create a variable that increments each time the button is pressed.  Push button once var = 1 turns LED 1 on.  Button press second time var = 2 turns LED1 off and LED2 on then resets var back to 0.  Seems overly complicated though and I want to minimize the code as much as possible.

Any guidance would be greatly appreciated.
10  Forum 2005-2010 (read only) / Interfacing / Re: Control Serial Devices on: April 30, 2010, 10:38:49 am
Thanks this is information is very helpful.  I will work on this tonight and post the code.
11  Forum 2005-2010 (read only) / Interfacing / Control Serial Devices on: April 29, 2010, 03:04:56 am
Does anyone have any suggestions on interfacing with a projector?  

I would like to send a serial commands to a projector via the press of button on the arduino.  

I have sent strings to the device using a max232.  I would like to program multiple buttons to perform specfic tasks such as turn projector on or off and switch between sources.  

I have not been able to find any sketches that would allow a button to trigger a stored ascii string.


12  Forum 2005-2010 (read only) / Interfacing / Arduino powered KVM Switch on: November 24, 2008, 12:03:05 pm
I am new to Arduino and would like some advice.

I would like to use an Arduino to control a USB KVM switch via RS-232 commands.

Where should I begin?  
Pages: [1]