Week 8 – Unusual Switch

Concept

My switch was a pretty simple implementation. I was fascinated by the light sensor and I thought I should use it to implement the switch. The idea was simple; turn on the LED when it is dark and off when there is light and using a light sensor was the best choice.

Setup

Code

const int ldrPin = 2;    // Pin connected to the LDR
const int ledPin = 13;   // Pin connected to the LED

void setup() {
  pinMode(ldrPin, INPUT);   // LDR pin as input
  pinMode(ledPin, OUTPUT);  //LED pin as output
}

void loop() {
  int lightStatus = digitalRead(ldrPin); // LDR value

  if (lightStatus == LOW) {
    // It’s dark, turn on the LED
    digitalWrite(ledPin, HIGH);
  } else {
    // It’s bright, turn off the LED
    digitalWrite(ledPin, LOW);
  }
}

My code was simple to implement as I just modified the example given in class. The code takes in the light sensor pin as input and LED pin as output then it reads the value of the light sensor which is dependent on if light is present or not. Depending on the light sensor value the code will turn on or turn off the LED.

Sketch

IMG_3439

Reflection and Future improvements

Implementing the Arduino was really fun. I was able to learn more on connecting circuits properly and also using the digital read. I am proud of being able to use the light sensor which was very fascinating and fun to implement. For the future I hope to learn more about the capabilities of Arduino and possibly create a light sensitive switch which will light the LED depending on the amount of light in the room and not just light up and turn off.

Leave a Reply