Week 9 | Blinking Light

I was quite busy this week with assignments from other classes that took more time than I had anticipated. Alas, I was quite idea-blocked on what to do for this unusual switch assignment.

Originally, I wanted to see if I could use sound sensors to turn on / off LEDs. However, the IM Lab does not have a sound sensor as of yet. So, I opted for photoresistors.

Exploring the examples provided by Arduino IDE, I found out the fading feature of LED. While it is not an inbuilt feature, by adding delays per update to the LED, we can simulate fading lights.

So, I figured what if I could combine both photoresistors’ outputs with fading light? Well, this is what I made:

I wanted to have some kind of if statements that go beyond what I have here. In my head, I wanted it so that each certain range of photoresistor would give different signals to the light: blinking, full on, full off, etc. However, they are more difficult to implement than I had imagined them.

//PIN NUMBERS
const int ledPin = 9;
const int ldrPin = A0;
int brightness = 0;  // how bright the LED is
int fadeAmount = 5;  // how many points to fade the LED by

void setup() {
  pinMode(ledPin, OUTPUT); // The input from LDR will be returned to LEd
  pinMode(ldrPin, INPUT); // This is the input, if we obstruct, it will return a signal 
}

void loop() {
  int ldrStatus = analogRead(ldrPin);
  Serial.println(int(ldrStatus));

  analogWrite(ledPin, brightness); //TURN ON LED 

  brightness = brightness + fadeAmount; // Change LED Brightness

  if ((ldrStatus <= 600) && (brightness <= 0 || brightness >= 255)){
    fadeAmount = -fadeAmount;
  }

  delay(30);
}

For future projects, I hope I have more time and energy to explore the technicalities of Arduino itself. Maybe I could pair the light with an alarm? So that when the sun is up, I can have strobing lights burning into my eyes. It is 2 AM right now, and I am exhausted 🙁

Resources:

The Basics of Arduino: Adjusting LED Brightness (deviceplus.com)

How to Use a Photoresistor (or Photocell) – Arduino Tutorial : 4 Steps (with Pictures) – Instructables

Leave a Reply