Week 10 – Production Assignment

Concept

This project demonstrates how an arduino system uses both analog and digital inputs to control outputs in different ways. A digital sensor like a button provides simple on or off input to control an LED, while an analog sensor like a potentiometer provides a range of values that are mapped to adjust another LED’s brightness using PWM. So in simple words, the project shows how real world data can be read, processed and translated into responsive visual feedback.

Sketch

Code

const int ANALOG_SENSOR_PIN = A0;  // Potentiometer or photoresistor
const int DIGITAL_SENSOR_PIN = 2;  // Button/switch
const int DIGITAL_LED_PIN = 13;    // LED controlled digitally
const int ANALOG_LED_PIN = 9;      // LED controlled with PWM 

int analogValue = 0;
int digitalValue = 0;
int ledBrightness = 0;

void setup() {
  pinMode(DIGITAL_SENSOR_PIN, INPUT_PULLUP); 
  pinMode(DIGITAL_LED_PIN, OUTPUT);
  pinMode(ANALOG_LED_PIN, OUTPUT);
  
  Serial.begin(9600);
}

void loop() {
  analogValue = analogRead(ANALOG_SENSOR_PIN);
  
  digitalValue = digitalRead(DIGITAL_SENSOR_PIN);
  
  if (digitalValue == LOW) {  
    digitalWrite(DIGITAL_LED_PIN, HIGH);
  } else {
    digitalWrite(DIGITAL_LED_PIN, LOW);
  }

  ledBrightness = map(analogValue, 0, 1023, 0, 255);
  analogWrite(ANALOG_LED_PIN, ledBrightness);
  
  // Debug output
  Serial.print("Analog: ");
  Serial.print(analogValue);
  Serial.print(" | Digital: ");
  Serial.print(digitalValue);
  Serial.print(" | Brightness: ");
  Serial.println(ledBrightness);
  
  delay(10); // Small delay for stability
}

How it was made 

I built this project using an arduino, a button, a potentiometer, and two LEDs on a breadboard. The potentiometer was connected as an analog sensor to control the brightness of one LED, while the button was used as a digital sensor to turn the second LED on and off. I wrote the code to read both inputs, then used analog(Write) to adjust the LED brightness and digital(Write) to control the on/off LED. I also used the serial monitor to display the values for testing and debugging.

Reflection

Honestly, doing this project was very fun. Through this project, I learned how to use both analog and digital inputs with an arduino. I understood that analog inputs give a range of values which can be used to control things like brightness, while digital inputs only have two states. If I did this project again, I would try to make it more creative by adding more sensors or different types of outputs.

Leave a Reply