Week 10 – EID Decoration

Concept

For this assignment, the task is to get information from at least one analog sensor and at least one digital sensor (switch), and use this information to control at least two LEDs, in both digital and analog way. Since its EID and after drawing some inspirations from previous works done by a student, I’ve decided to make an EID decoration using the LED lights.

Materials I used

  1. Arduino Uno board
  2. 2 LEDs (RED)
  3. 2 x 220-ohm resistors
  4. 10k-ohm resistor
  5. Tactile push-button switch
  6. Photocell
  7. Breadboard
  8. jumper wires
  9. A piece of cardboard

How it works

The goal is to turn on both LEDs to light up the Eid decoration. To do this, you press one button to light up one LED. Then, to turn on the other LED, you block the photocell’s light by placing your finger over it. When you do both actions together (pressing the button and blocking the photocell), both LEDs will light up at the same time.

Code

int led = 11;
int brightness = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(led, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  int sensorValue = analogRead(A2);
  Serial.println(sensorValue); //prints the sensorValues

  sensorValue = constrain(sensorValue, 410, 450);
  brightness = map(sensorValue, 410, 450, 255, 0); //mapping the sensorValues

  analogWrite( led, brightness);

  delay(30);

}

Video Demonstration

Future Improvements

In future updates, I want to include a condition where simply activating the button or just the photocell won’t turn on the LEDs. Instead, both the button and photocell need to be activated simultaneously to light up the LEDs.

Leave a Reply