Devices & Components
Arduino Nano
Breadboard - 400 contacts
5mm Red LED
Resistor 1k ohm
Jumper wires (generic)
220 Ω ohm Resistors
Blue 5mm LED
USB A to USB mini (1.5m)
5528 Light Dependent Resistor LDR 5MM Photoresistor
Software & Tools
Google Gemini
Arduino IDE
Project description
Code
Bioluminescent Night Light with LED Proxy
cpp
1/* 2 Bioluminescent Night Light with LED Proxy (Version 1.4) 3 BiotronikMAiker 4 5 6 This project simulates a bioluminescent night light using LEDs and a photoresistor. 7 An LED acts as a proxy for bioluminescent bacteria, turning on and off at set intervals. 8 A photoresistor detects the light from the "bacteria" LED. 9 When the "bacteria" LED is on and the ambient light is low, a second LED (the "night light") is activated. 10 11 12 This code was generated with the assistance of Gemini, an AI assistant, under the guidance and direction of BiotronikMAiker and VideotronicMaker. 13 It is part of a larger project exploring the integration of bioluminescence, Arduino, and AI. 14 15 16 Circuit: 17 - Bacteria LED (e.g., white or yellow) connected to digital pin 3. 18 - Night Light LED (e.g., green) connected to digital pin 2. 19 - Photoresistor connected to analog pin A0. 20 21 22 Version 1 - Prototype without Bacteria: 23 An LED simulates the bioluminescent bacteria. The light sensor/photoresistor detects the light from these initial LEDs. 24 This triggers the Arduino to activate a single LED to indicate that light was sensed. 25 26 27 Modifications by: VideotronicMaker (Instructor) 28 Date: [January 7, 2025] 29*/ 30 31 32// Pin definitions 33const int bacteriaLedPin = 3; // Digital pin connected to the "bacteria" LED (simulating bacteria) 34const int nightLightLedPin = 2; // Digital pin connected to the "night light" LED (indicator) 35const int photoresistorPin = A0; // Analog pin connected to the photoresistor 36 37 38// Timing constants (in milliseconds) 39const unsigned long onTime = 3000; // Time the "bacteria" LED stays on (3 seconds) 40const unsigned long offTime = 2000; // Time the "bacteria" LED stays off (2 seconds) 41 42 43// Light threshold for the photoresistor. 44// Adjust this value based on your photoresistor and ambient lighting conditions. 45const int lightThreshold = 500; 46 47 48// Variable to store the last time the "bacteria" LED was updated 49unsigned long previousMillis = 0; 50 51 52// Variable to track the state of the "bacteria" LED (on or off) 53bool bacteriaLedState = HIGH; // Start with the "bacteria" LED ON 54 55 56void setup() { 57 // Initialize the "bacteria" LED pin as an output. 58 pinMode(bacteriaLedPin, OUTPUT); 59 60 61 // Initialize the "night light" LED pin as an output. 62 pinMode(nightLightLedPin, OUTPUT); 63 64 65 // Turn on the "bacteria" LED initially. 66 digitalWrite(bacteriaLedPin, HIGH); 67} 68 69 70void loop() { 71 // Get the current time in milliseconds. 72 unsigned long currentMillis = millis(); 73 74 75 // --- Bacteria LED Control --- 76 77 78 // Check if the "bacteria" LED is currently ON and if the 'onTime' duration has elapsed. 79 if (bacteriaLedState == HIGH && currentMillis - previousMillis >= onTime) { 80 // Update 'previousMillis' to the current time. 81 previousMillis = currentMillis; 82 83 // Change the state of the "bacteria" LED to OFF. 84 bacteriaLedState = LOW; 85 86 // Turn OFF the "bacteria" LED. 87 digitalWrite(bacteriaLedPin, bacteriaLedState); 88 } 89 // Otherwise, check if the "bacteria" LED is currently OFF and if the 'offTime' duration has elapsed. 90 else if (bacteriaLedState == LOW && currentMillis - previousMillis >= offTime) { 91 // Update 'previousMillis' to the current time. 92 previousMillis = currentMillis; 93 94 // Change the state of the "bacteria" LED to ON. 95 bacteriaLedState = HIGH; 96 97 // Turn ON the "bacteria" LED. 98 digitalWrite(bacteriaLedPin, bacteriaLedState); 99 } 100 101 102 // --- Photoresistor Reading --- 103 104 105 // Read the analog value from the photoresistor. 106 int lightLevel = analogRead(photoresistorPin); 107 108 109 // --- Night Light LED Control --- 110 111 112 // Check if the light level is below the threshold AND the "bacteria" LED is ON. 113 if (lightLevel < lightThreshold && bacteriaLedState == HIGH) { 114 // Turn ON the "night light" LED. 115 digitalWrite(nightLightLedPin, HIGH); 116 } else { 117 // Turn OFF the "night light" LED. 118 digitalWrite(nightLightLedPin, LOW); 119 } 120}
Downloadable files
Bioluminescent Night Light with LED Proxy
biolum_night_light_ledproxy.ino
Comments
Only logged in users can leave comments