> For the complete documentation index, see [llms.txt](https://hopemoore.gitbook.io/coding-for-creatives/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hopemoore.gitbook.io/coding-for-creatives/arduino-info/the-setup/create-a-night-light.md).

# Create a Night Light

This is an example of using an input (sensor) component to change an output of an output component.

## Supplies

|                                                                     |                                                            |
| ------------------------------------------------------------------- | ---------------------------------------------------------- |
| <img src="/files/-MNayW2jUi_Nst3XnGzZ" alt="" data-size="original"> | Circuit Board                                              |
| <img src="/files/-MNayzgMRngmlGc0RjrR" alt="" data-size="original"> | Breadboard                                                 |
| <img src="/files/-MNazfyfWM718wc-6O6v" alt="" data-size="original"> | Jumper Cables                                              |
| <img src="/files/-MNb6aAM5m1RVHyJtNyQ" alt="" data-size="original"> | <p>Photoresistor</p><p>(light sensor)</p>                  |
| <img src="/files/-MNb1OYaVNmqktuIHYim" alt="" data-size="original"> | <p>Standalone LED Light</p><p>(any color with 2 leads)</p> |
| <img src="/files/-MNb05Z02MSj2Zk1pt9n" alt="" data-size="original"> | 100 Ohm Resistor                                           |
| <img src="/files/-MNb1decklIbKjOmK_1p" alt="" data-size="original"> | 220 Ohm Resistor                                           |

## Diagram

![](/files/-MNbIfL9Bp1B1ITvZ7Uu)

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.

```cpp
// Sensor pin is connected to pin A0 (analog) on the Arduino circuit board
int sensorPin = 0;

// LED pin is connected to pin 2 (digital)
int LEDpin = 2;

// Define variables
int lightValue;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(sensorPin, INPUT);
  pinMode(LEDpin, OUTPUT);
  
  // Start Serial connection
  Serial.begin(9600);
}

void loop() {
  // Reads and stores the data coming in from the sensor
  lightValue = analogRead(sensorPin);

  // Lights up if dark enough
  if (lightValue <= 5) {
    digitalWrite(LEDpin, HIGH);
  }
  else {
    digitalWrite(LEDpin, LOW);
  }
  
  delay(100);

  // Sends information to the Serial Monitor
  Serial.print("Light Value: ");
  Serial.print(lightValue);
  delay(100);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hopemoore.gitbook.io/coding-for-creatives/arduino-info/the-setup/create-a-night-light.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
