Go Down

Topic: How to turn off the LED when Box is closed (Read 135 times) previous topic - next topic

sobo84

Hey to all,
i got a box where LEDs are installed. When i open tzhe box, the light sensor turns on the LEDs. The problem is that the light sensor won´t turn them off while they are on themselves....

Any suggestions how i could solve it? I´m new to arduino and i am using Uno and IDE 1.0.6




Quote
/*
"Zapfsäule"
 
Programmiert
Start: 21.02.2015
Fertiggestellt:XX.XX.2015
 
Tobias Sobkowiak
sobkowiaktobias(at)gmail.com
www.druckundmedientechnologie.de
 
 
 
http://www.arduino.cc/en/Tutorial/Button
*/
// Pinnummern
const int whiskeycolaButton = 2;     // the number of the pushbutton pin
const int colaPin =  13;      // Cola Pumpe (+) Pin
const int whiskeyPin = 12;    // Whiskey Pumpe (+) Pin

// Variablen werden sich ändern...
int buttonState = 0;         // Knopfvariable

//Beleuchtung
int Beleuchtung = 7;
int lightSensor = 0;

void setup() {
  // initialize the LED pin as an output:
  pinMode(colaPin, OUTPUT);  
  // initialize the LED pin as an output:
  pinMode(whiskeyPin, OUTPUT);  
  // initialize the pushbutton pin as an input:
  pinMode(whiskeycolaButton, INPUT);  

  //Beleuchtung
  Serial.begin(9600);
  pinMode(Beleuchtung, OUTPUT);

}

void loop(){
  // Lese Whiskey-Cola-Knopf
  buttonState = digitalRead(whiskeycolaButton);

  // Wenn der Knopf gedrückt wird
  if (buttonState == HIGH) {    
    // Pumpe starten  

    digitalWrite(colaPin, HIGH);
    digitalWrite(whiskeyPin, HIGH);  
    delay(2000);//Befüllzeit
    digitalWrite(colaPin, LOW);
    digitalWrite(whiskeyPin, LOW);
    digitalWrite(colaPin, HIGH);
    delay(7000);//Befüllzeit  
    digitalWrite(colaPin, LOW);
  }

  //Beleuchtung
  int sensorValue = analogRead(lightSensor);
  // print out the value you read:
  Serial.println(sensorValue);

  if (sensorValue < 900)
  {
    digitalWrite(Beleuchtung, HIGH);
  }
  else
  {
    digitalWrite(Beleuchtung, LOW);
  }

}





Robin2

Perhaps you can screen the sensor so it does not see the LEDs when the lid is closed ?

...R

Delta_G

Code: [Select]

 if (buttonState == HIGH) {     
    // Pumpe starten   

    digitalWrite(colaPin, HIGH);
    digitalWrite(whiskeyPin, HIGH); 
    delay(2000);//Befüllzeit
    digitalWrite(colaPin, LOW);
    digitalWrite(whiskeyPin, LOW);
    digitalWrite(colaPin, HIGH);
    delay(7000);//Befüllzeit 
    digitalWrite(colaPin, LOW);
  }




Here you tell the program what to do when you get a HIGH on the switch.  It's not going to try to figure out what you want to do when you get a LOW.  You're going to have to code that part too. 

sobo84

Code: [Select]

 if (buttonState == HIGH) {    
    // Pumpe starten  

    digitalWrite(colaPin, HIGH);
    digitalWrite(whiskeyPin, HIGH);  
    delay(2000);//Befüllzeit
    digitalWrite(colaPin, LOW);
    digitalWrite(whiskeyPin, LOW);
    digitalWrite(colaPin, HIGH);
    delay(7000);//Befüllzeit  
    digitalWrite(colaPin, LOW);
  }




Here you tell the program what to do when you get a HIGH on the switch.  It's not going to try to figure out what you want to do when you get a LOW.  You're going to have to code that part too.  
Thanks for the replies and sorry for confusing. The part you where looking at is only the first on.

1. push a buton
2. start cola and whiskey pump
3. stop after XX secs.

...that runs fine. I don´t think i need an else there..., but i plan to install more buttons and then there willl be an else if.



 //Beleuchtung
 int sensorValue = analogRead(lightSensor);
 // print out the value you read:
 Serial.println(sensorValue);

 if (sensorValue < 900)
 {
   digitalWrite(Beleuchtung, HIGH);
 }
 else
 {
   digitalWrite(Beleuchtung, LOW);
 }

}

--> above is the problematic part. I made a kind of cocktail maker and want it to be enlighted inside when i open it and to turn of the leds when i close the door.

I am using this sensor:

http://www.banggood.com/Photosensitive-Detection-Switch-Light-Sensor-Module-Robot-Kit-Arduino-p-91809.html

sobo84

Or am i going the wrong way to combine different actions in the loop???

UKHeliBob

Quote
I made a kind of cocktail maker and want it to be enlighted inside when i open it and to turn of the leds when i close the door.
The easiest way, of course, would be to have a sensor activated when the door is closed.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

sobo84

The easiest way, of course, would be to have a sensor activated when the door is closed.
Thats what i am trying, but the leds are too shiny when they are on and the sensor won´t deactivate.

arduinodlb

#7
Feb 22, 2015, 10:27 am Last Edit: Feb 22, 2015, 10:32 am by arduinodlb
Or am i going the wrong way to combine different actions in the loop???
No. Combining actions in the loop is fine.

As others say, the problem is that the LEDs produce enough light to make it impossible to use a light detector to know if the door is open or closed. This is not an arduino or programming problem, it's a science problem. One possibility may be to put a colour filter over the sensor to mask detection of the LEDS. That may be difficult, or potentially impossible.

Use a door switch.
Do not IM me. I will not respond. Ask questions in the forum.

TomGeorge

Hi, use a different sensor, microswitch under the lid, magnet and reed switch, anything that doesn't rely on light to activate.
That way it will even work in the dark.


Tom...... :)
Everything runs on smoke, let the smoke out, it stops running......VK3DMK

UKHeliBob

Quote
use a different sensor
That was what I had in mind.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy