This is an example of using an input (sensor) component to change an output of an output component.
Supplies
Diagram
The photoresistor data (yellow) is connected to pin A0 (analog) and the LED data (orange) is connected to pin 2 (digital).
Code
This code gets the amount of light coming in via the sensor and if it's dark enough, the LED will light up.
// Sensor pin is connected to pin A0 (analog) on the Arduino circuit boardint sensorPin =0;// LED pin is connected to pin 2 (digital)int LEDpin =2;// Define variablesint lightValue;voidsetup() {// Establish the component connection and its type (output/input)pinMode(sensorPin, INPUT);pinMode(LEDpin, OUTPUT);// Start Serial connectionSerial.begin(9600);}voidloop() {// Reads and stores the data coming in from the sensor lightValue =analogRead(sensorPin);// Lights up if dark enoughif (lightValue <=5) {digitalWrite(LEDpin, HIGH); }else {digitalWrite(LEDpin, LOW); }delay(100);// Sends information to the Serial MonitorSerial.print("Light Value: ");Serial.print(lightValue);delay(100);}