Aisha – Analog & Digital

For my assignment, I initially wanted to have the LED lights off and then turn them on via the switch. Whilst holding the switch, I wanted to use the light sensor to change the brightness by hovering my finger over it. However, I couldn’t figure out how to use the light sensor whilst using a switch. It wasn’t working for me, unfortunately. So instead, I used the switch for blinking lights in sync and the light sensor to decrease the brightness whilst it is covered. For this, I needed: wires, resistors, a pushbutton, a light sensor, and LED lights.

I implemented the code we did in class for blinking and got help from this youtube video to decrease the brightness via the light sensor.

This is the code I used for decreasing the light when the sensor is covered:

void loop() {
  // put your main code here, to run repeatedly:
  int buttonState = digitalRead(pushButton);
  ldr = analogRead(A0);
  brightness = map(ldr,0,1023,0,255);

   analogWrite(6, brightness);
   analogWrite(3, brightness);

Schematic Diagram:





Future Improvements:

  • I’d like to do my original idea
  • I also would like the brightness of the LED light when the sensor isn’t covered to be brighter.
  • I’d also like to get more confident doing the schematic drawing as it did take me a while to figure it out.


Leave a Reply