production assignment week 10

This project allows us to control the brightness of two LEDs – one red and one green – using a potentiometer and a push button.

Here’s what you’ll see in the video:
An Arduino Uno board.
A potentiometer, acting as a dimmer switch.
A push button for an instant override.
Two LEDs, red and green, responding to our commands.

How does it work?
Let’s dive into the details:
The Potentiometer: As you turn the knob, it sends varying voltage values to the Arduino. The code interprets these values and maps them to control the brightness of the LEDs. Turning one way brightens the green LED while dimming the red, and vice versa.
The Push Button: This acts as an override switch. No matter what the potentiometer setting is, pressing the button instantly turns the red LED on to full brightness.

Technical Insights:
The project utilizes the Arduino’s analog input capabilities to read the potentiometer values and its PWM (Pulse Width Modulation) functionality to control the LED brightness.
The push button is connected to a digital input pin, allowing the Arduino to detect button presses and trigger the override function.

void loop() {
  int sensorValue = analogRead(A0);
  buttonState = digitalRead(btn);
    brightness = map(sensorValue,0,1023,0,255);

  brightness2 = map(sensorValue,0,1023,255,0);

  analogWrite(led,brightness);
    analogWrite(led2, brightness2);

  if (buttonState == HIGH) {
      analogWrite(led,255);
  }

  Serial.println(sensorValue);

}

 

Leave a Reply