I am trying to write code that will turn on the light on pin 13 of the Arduino Uno when pin 8 (or any digital pin) receives a high signal
the if statement spot is where I’m having trouble
a picture of the circuits set up has been attached
here is the code I’ve written
int sw = 8;
int ld = 13;
void setup()
{
pinMode(sw, INPUT);
pinMode(ld, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int val = digitalRead(sw);
Serial.println(val);
delay (100);
if (digitalRead(val) == LOW)
{
digitalWrite(ld, LOW);
}
else if (digitalRead(val) == HIGH)
{
digitalWrite(ld, HIGH);
}
}