How to read LED state

Could anyone please give an example of the code you would use to have the Arduino read the state of an LED if it is wired through a digital pin? I need to use this in an “if” statement specifically.

Is this a LED you are controlling via a pin on the Arduino or an external LED that is being controlled by something else e.g. a switch

If its just an external LED that you have connected to a digital pin on the Arduino (assuming you have wired it correctly) All you need to do is set the pin to INPUT and then use digitalRead(PIN_NUMBER);

See the example DigitalReadSerial that comes with the Arduino IDE i.e

/*
  DigitalReadSerial
 Reads a digital input on pin 2, prints the result to the serial monitor 

 This example code is in the public domain.
 */

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);        // delay in between reads for stability
}

This is reading a "button" but its the same principal as an LED

Note if this is an external LED, you probably can't just attach wires between the Anode of the LED and the input pin (and GND to GND), as the forward voltage on an LED is not normally high enough to be detected by a digital input.

liammac001: Could anyone please give an example of the code you would use to have the Arduino read the state of an LED if it is wired through a digital pin? I need to use this in an "if" statement specifically.

Assuming your program is what sets the LED to ON or OFF, you already know the state of the LED, or at least you do at the time your program changes its state. If you don't know afterward, and you want to know whether it was turned ON or OFF, then don't just change its state and throw the information away. Save it in a variable and look at it when you need to know..