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
Arduino Uno board
2 LEDs (RED)
2 x 220-ohm resistors
10k-ohm resistor
Tactile push-button switch
Photocell
Breadboard
jumper wires
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
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
int led = 11;
int brightness = 0;
voidsetup(){
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(led, OUTPUT);
}
voidloop(){
// 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);
}
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);
}
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.