Light Trigger
Difficulty: ● ○ ○ ○ ○
-
Make Sure You have:
-
Did you know ?
Parts Required
No products found in parts_required metafield
How It Works ?
GENESIS
Connection Guide
Snap your modules as shown above, copy the code into the Arduino IDE and Click upload
#define LDR_PIN 7
#define POT_PIN 4
#define RED_PIN 6
#define GREEN_PIN 42
#define BLUE_PIN 9
void setup() {
Serial.begin(115200);
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}
void loop() {
int ldrValue = analogRead(LDR_PIN); // LDR value: 0-4095
int potValue = analogRead(POT_PIN); // Pot controls threshold: 0-4095
if (ldrValue < potValue) {
// Light is lower than threshold: turn LED ON (white)
digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);
} else {
// Too much light: turn LED OFF
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);
}
delay(50);
}