How to Turn on Lights Documentation
This project implements an interactive lighting system that simulates the experience of lighting a lantern using breath. The user must hold a pressure-sensitive FSR sensor and then blow into a microphone (MAX4466) to activate RGB LED groups.
- The LEDs gradually fade in instead of lighting up instantly, creating a smooth and immersive lighting experience.
- Each blow activates the next group of LEDs, and a minimum time gap is enforced between consecutive blows to ensure a natural interaction.
- Once all LED groups are lit, they stay on for 30 seconds before resetting.
- If the user releases the lantern (FSR < threshold) before all LEDs are lit, the system resets to its initial state.
How the System Works
- Idle State:
- The system waits for the FSR to be pressed (FSR > 800) before accepting microphone input.
- If the user releases the FSR before lighting all groups, the system resets.
- Blowing Detection:
- When the microphone detects a reading of 1023, it registers a valid blow event.
- A 3-second gap is enforced before allowing another blow.
- LED Activation:
- Each valid blow activates the next LED group, with a smooth fade-in over 5 seconds.
- The sequence is:
- Blow 1: Group 1 (3 LEDs) fades in.
- Blow 2: Group 2 (2 LEDs) fades in.
- Blow 3: Group 3 (1 LED) fades in.
- After all three groups are lit, the LEDs stay on for 30 seconds.
- Auto-Reset:
- After 30 seconds, the system automatically resets, turning off all LEDs.

LED Fade-In Function
void fadeInLED(int pin) {
int steps = 255;
int delayTime = 5000 / steps; // Fade in over 5 sec
for (int i = 0; i <= 255; i++) {
analogWrite(pin, i);
delay(delayTime);
}
}
Main Loop: Sensor Processing
void loop() {
unsigned long now = millis();
int fsrValue = analogRead(fsrPin);
int micValue = analogRead(micPin);
Serial.print("Mic: ");
Serial.print(micValue);
Serial.print(" | FSR: ");
Serial.println(fsrValue);
// If level 3 is reached, ignore FSR and keep LEDs on for fullLitDuration
if (currentLevel == 3) {
if (now - fullLitStart >= fullLitDuration) {
Serial.println("Full-lit duration reached. Resetting system.");
resetSystem();
}
delay(50);
return;
}
// For levels below 3, process mic only when lantern is held
if (fsrValue > fsrThreshold) {
if (now - lastBlowTime >= blowGap) { // Enforce 3 sec gap
if (micValue >= micBlowThreshold) {
if (!blowActive) { // Rising-edge detection
if (currentLevel < 3) {
currentLevel++;
Serial.print("Blow detected. Increasing level to ");
Serial.println(currentLevel);
if (currentLevel == 1) {
fadeInGroup1();
} else if (currentLevel == 2) {
fadeInGroup2();
} else if (currentLevel == 3) {
fadeInGroup3();
fullLitStart = now; // Start 30-sec timer
}
lastBlowTime = now;
}
blowActive = true;
}
} else {
blowActive = false; // Reset flag when mic reading falls below threshold
}
}
} else {
resetSystem(); // If not held, reset system
}
delay(50);
}




Leave a comment