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
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);
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.
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.
push a buton
start cola and whiskey pump
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);
--> 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.
sobo84:
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.
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.