So how can I force the program to just turn on a LED, if it hasn't turned on before, even if its getting a "0" again from the sensor, so only if the other one has turned on, by receiving a "1", the first on should be activated.
I'm trying to build a controller for my curtains. My Arduino is connected to a motor and a light-sensor, the pins which are now declared as LEDS, will later be the pins for the motor. the idea was that the light sensor check every 30minutes if there is still sunshine or not, but by using if-conditions the motor would turn every time in the same dire, when there is still light, and its supposed to only turn once, only if it gets a signal that there is no light, it should turn in the other directions once to close the curtains, otherwise do nothing.
const int LIGHT_SENSOR_PIN = A0; // Arduino pin connected to light sensor's pin
const int LED_PIN = 3; // Arduino pin connected to LED's pin
const int ANALOG_THRESHOLD = 500;
// variables will change:
int analogValue;
void setup() {
pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin
if(analogValue < ANALOG_THRESHOLD)
digitalWrite(LED_PIN, HIGH); // turn on LED
else
digitalWrite(LED_PIN, LOW); // turn off LED
}
for real world use, you might want to modify the example code slightly, such as pausing between reads, and maybe offsetting the threshold value between off and on, to avoid too many short cycles. also make sure the photosensor can't see the led or light that's being controlled.
Hi,
Please read the post at the start of any forum , entitled "How to use this Forum".
OR https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
What is your light sensor?
Can you post a link to data/specs please?
Is it an LDR, as in light dependent resistor?
If so you would be better to use an analog input and read its value.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
What model Arduino are you using?