Production Assignment – Week 10

For this assignment, we were tasked with using one digital sensor (on/off) and one analog sensor (variable) to control an LED each.

I used a potentiometer as my analog sensor to control and dim a blue LED based on the reading, and used a regular button as my digital sensor (switch).

I used arduino to get the readings from the potentiometer and control the blue LED, but for the switch and green LED, I just used the 5V out to keep things simple.

Materials Used:

  • Jumper Wires
  • Blue LED
  • Green LED
  • Resistor
  • Potentiometer
  • Button

Code:

const int ledPin = 10;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  int sensorLevel = analogRead(A0); // Read from potentiometer
  int brightness = map(sensorLevel, 0, 1023, 0, 255); // Map sensor reading to LED brightness

  analogWrite(ledPin, brightness); // Control LED

  delay(100);
}

 

Demo:

Leave a Reply