Week 10 – Assignment

The project is designed as a competitive game using an Arduino board to determine who can activate their respective LED faster: a player pressing a button or an automated response triggered by a photoresistor detecting darkness. The setup includes two LEDs connected to the Arduino. One LED (connected to pin 10) is controlled by a pushbutton, which, when pressed, signifies the  player’s reaction. The other LED (connected to pin 9) is controlled by a photoresistor, representing an automated “player” that reacts to the absence of light. The game’s objective is to see which mechanism can activate its LED first under the given conditions—either when it becomes dark enough for the photoresistor to react or when the human player presses the button.

This was a lot of fun to make and the concept sort of formed as I put everything together, I mostly focused on using the class notes as a resources however I did use some of the examples on the official Arduino website. 

https://forum.arduino.cc/t/using-an-led-and-a-photoresistor-to-switch-itself-on-and-off/179690

https://projecthub.arduino.cc/agarwalkrishna3009/arduino-diy-led-control-with-ldr-sensor-photoresistor-fa011f

int photoSensorPin = A0;
int buttonPin = 2;
int ledPin1 = 9;
int ledPin2 = 10;

void setup() {
  pinMode(photoSensorPin, INPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
}

void loop() {
  int sensorValue = analogRead(photoSensorPin);
  int buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH) {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, HIGH);
  } else if (sensorValue < 512) {
    digitalWrite(ledPin1, HIGH);
    digitalWrite(ledPin2, LOW);
  } else {
    digitalWrite(ledPin1, LOW);
    digitalWrite(ledPin2, LOW);
  }
}

 

 

Leave a Reply