Concept
For my unusual switch, I wanted to use a light sensor to create a simple “password” that isn’t typed or pressed in the usual way. Instead of a button, the user has to shine a flashlight on the sensor in a specific pattern to activate the LED. The idea is inspired by a morse-code style signal: the user must turn the light on for a set amount of time, then off for a set amount of time, and repeat this sequence to successfully trigger the switch. This makes the interaction more playful and unusual, relying on timing and attention rather than direct contact.
How it works
The project uses an LDR to detect light intensity and an LED as the output indicator. The Arduino reads the LDR value and compares it to a threshold to decide if the light is “on” or “off.” The user must follow the correct timing sequence: light on for three seconds, then off for three seconds, repeated three times. If the pattern is completed correctly, the green LED turns on for a few seconds to indicate success.
Github https://github.com/MohdAlkhatib/introtoim/blob/main/sketch.c
void loop() {
int success = 0;
for (int i = 0; i < 3; i++) {
if (analogRead(ldrPin) > lightThreshold) {
delay(3000); // light on for 3 seconds
if (analogRead(ldrPin) < lightThreshold) {
success++;
delay(3000); // light off for 3 seconds
}
}
delay(500); // brief pause between attempts
}
// if the user does the signal correctly 3 times in a row, turn on the LED
if (success == 3) {
digitalWrite(greenLED, HIGH);
delay(3000);
digitalWrite(greenLED, LOW);
}
delay(1000); // short pause before restarting
}
Future Improvements
In the future, I could make the switch more flexible by allowing different light patterns as “passwords” or adjusting the timing for each sequence. I could also add multiple LEDs or even a small sound to give feedback for each correct or incorrect step.