Led with light sensor

in this example, when the light on the sensor falls below 0.2, the button and diodes work fine, when the value is above 0.2 then the button and diode do not work as I wanted, but when the diode is turned on and removed from the sensor and the value on the sensor rises above 0.2 while the diode is running, is the diode not going off? why thatkakoto03

159.xodball (5.1 KB)

Making led-ACT false means that LED will not receive any updates…it does not mean it will turn off.

If you want the LED to always be off for certain sensor values, then you need to use if-else to feed led-LUM. Something like this:

image

i did it, thank you gweimer … you are awesome

can you solve this problem i’m having now … i tried everything but it’s not going … in the arduino IDE in the code i know how to solve it but here at XOD i don’t know how …

What is the problem?

when the outside light is on the value to light the diode then the diode is flashing, it should be narrative to say that it lights up at a lower value of 0.2 but does not light unless the value rises back to 0.3 for example

like this…

// Pins
int sensorPin = 3;
int lightPin = 2;
int led = 0;

// Variables
int lightState = 0;
int lowThreshold = 10;
int highTreshold = 20;

void setup() {

pinMode(lightPin, OUTPUT);

}

void loop() {

// Read the sensor pin
int sensorValue = analogRead(sensorPin);

// If light level is low is detected, switch light on
if (sensorValue < lowThreshold) {
digitalWrite(lightPin, HIGH);
}

// If light level goes up again, switch the lights off
if (sensorValue > highTreshold) {
digitalWrite(lightPin, LOW);
analogWrite(led,5); // turn the LED on (HIGH is the voltage level)
delay(2000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(5000);

} }

The closest to that code I can think of is to only update LED when there is a change to the compares, but a better way in XOD is to remember current state and only change as needed. Since you are only remembering on or off, you can use a flip-flop. Only set it when sensor is less than 0.2. Only clear the flip-flop when sensor is greater than 0.3. Use flip-flop output to feed led-LUM.

gweimer thank you so much … I made it. it’s working right now …