Video Link to final project: https://youtu.be/lS588oI_GPU
Concept
For this assignment, my concept was to simulate a day and night state using 2 LEDs and a photosensor. The digital sensor would be the switch, while the photosensor would be the analog sensor. One light should turn on while the other is off during each state. I was also inspired by this week’s readings, which discussed the idea of not being afraid to draw inspiration from what other artists have created. The articles by Tigoe helped me gather inspiration from various sources on the internet, such as our GitHub page. From there, I was able to develop this day and night simulation prototype.
Design and Execution
The following schematic represents the foundation on which I built this day and night simulator:
After drawing the schematic, I carefully assembled the entire circuit to represent the desired effect. The following code is the loop which allowed the entire idea come to life:
void loop() { int lightLevel = analogRead(photoPin); // Read photosensor value bool isDay = lightLevel > lightThreshold; // Determine if it's daytime Serial.println(lightLevel); // Print light level for debugging // Read switch positions bool switch1 = !digitalRead(switchPin1); // True if position 1 is active bool switch2 = !digitalRead(switchPin2); // True if position 2 is active if (switch1) { // Position 1: Both LEDs off digitalWrite(dayLed, LOW); analogWrite(nightLed, 0); } else if (switch2) { // Position 2: Daytime/Nighttime mode based on light sensor if (isDay) { // Daytime behavior digitalWrite(dayLed, HIGH); // Daytime LED on analogWrite(nightLed, 0); // Nighttime LED off } else { // Nighttime behavior digitalWrite(dayLed, LOW); // Daytime LED off analogWrite(nightLed, lightLevel / 4); // Nighttime LED brightness based on light level } } delay(100); // Small delay to smooth transitions }
Finally, the project works, and here is a link that demonstrates the final outcome: https://youtu.be/lS588oI_GPU
Final Thoughts and Reflection:
This project allowed me to utilize previous knowledge and to learn and apply new concepts. I believe a great way to improve this project would be to have multiple lights that would react differently for day and night states. The challenge behind this would be wire management, and I believe there is a solution to this problem that I’m still yet to encounter. I am, however, curious about how this could manifest. This exercise is pivotal to my knowledge basket, as it will all contribute to my final project. That’s all for now!