# Output Component Setup Examples

## Supplies for All

|                                                                                                                                                                                                                                                                   |               |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNaxbhjUd7KYoevsTMF%2F-MNayW2jUi_Nst3XnGzZ%2Fimage.png?alt=media&#x26;token=685eadb7-1fad-4f7e-924d-9553d6a8acc9" alt="" data-size="original"> | Circuit Board |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNaxbhjUd7KYoevsTMF%2F-MNayzgMRngmlGc0RjrR%2Fimage.png?alt=media&#x26;token=e10f37c3-a70c-4180-9696-5902558ba106" alt="" data-size="original"> | Breadboard    |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNaxbhjUd7KYoevsTMF%2F-MNazfyfWM718wc-6O6v%2Fimage.png?alt=media&#x26;token=f3df972a-2913-43dc-abe3-048b86265ba2" alt="" data-size="original"> | Jumper Cables |

## Buzzer

### Additional Supplies

|                                                                                                                                                                                                                                                                   |                  |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------- |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb-SIl1jlV52PS8g-G%2F-MNb-wTn9AB_H3VmuxK_%2Fimage.png?alt=media&#x26;token=aa1b024a-fca6-4f64-86b0-b887706189e4" alt="" data-size="original"> | Buzzer           |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb-SIl1jlV52PS8g-G%2F-MNb05Z02MSj2Zk1pt9n%2Fimage.png?alt=media&#x26;token=35ee6ffd-f212-46e7-908e-e4d904bd0550" alt="" data-size="original"> | 100 Ohm Resistor |

### Diagram

![The data (yellow) wire is connected to digital pin 9.](https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb-SIl1jlV52PS8g-G%2F-MNb0P4xxhO1qplCB91X%2Fimage.png?alt=media\&token=250eedcb-679b-4cfd-8d7d-7540b2db62c5)

### Code

In this example, the buzzer will play a 1KHz tone for 1 second, then silence for 1 second as long as it's plugged in.

```cpp
// Buzzer is connected to pin 9 on the Arduino circuit board
int buzzer = 9;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(buzzer, OUTPUT);
}

void loop() {
  tone(buzzer, 1000);   // Plays 1KHz tone
  delay(1000);          // Plays this tone for 1 second
  noTone(buzzer);       // Plays no tone
  delay(1000);          // Plays this tone for 1 second
}
```

## Standalone LED Light

### Additional Supplies

|                                                                                                                                                                                                                                                                   |                                                                           |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------- |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1OYaVNmqktuIHYim%2Fimage.png?alt=media&#x26;token=0353b969-9de4-4a05-bc07-a09871217d7f" alt="" data-size="original"> | <p>LED light</p><p>(any color, as long as it has only two connectors)</p> |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1decklIbKjOmK_1p%2Fimage.png?alt=media&#x26;token=1b27f65c-8728-45a7-97a8-7d7735a1cf32" alt="" data-size="original"> | 220 Ohm Resistor                                                          |

### Diagram

![The data (yellow) wire is connected to digital pin 9.](https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1qK4siruhhztlr9P%2Fimage.png?alt=media\&token=f32bf8c6-ee97-42a1-9a1e-7d0276c3dc8b)

### Code

This code will make the LED light up for 1 second and go off for 1 second until it is unplugged.

```cpp
// LED is connected to pin 9 on the Arduino circuit board
int LED = 9;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(LED, OUTPUT);
}

void loop() {
  digitalWrite(LED, HIGH);  // Turn light on
  delay(1000);              // Wait 1 second
  digitalWrite(LED, LOW);   // Turn light off
  delay(1000);              // Wait 1 second
}
```

## Multiple LEDs

This example shows using and controlling two separate LEDs as an example of multiple output components.

### Additional Supplies

|                                                                                                                                                                                                                                                                   |                                                                              |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1OYaVNmqktuIHYim%2Fimage.png?alt=media&#x26;token=0353b969-9de4-4a05-bc07-a09871217d7f" alt="" data-size="original"> | <p>2 LED lights</p><p>(any color, as long as it has only two connectors)</p> |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1decklIbKjOmK_1p%2Fimage.png?alt=media&#x26;token=1b27f65c-8728-45a7-97a8-7d7735a1cf32" alt="" data-size="original"> | 2 - 220 Ohm Resistors                                                        |

### Diagram

![The yellow data wire is connected to digital pin 10 and the orange wire to pin 9.](https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb2Q6xW3eU-YZepLxa%2F-MNb311TWuSd7MO81mMQ%2Fimage.png?alt=media\&token=1c6be9e4-1171-4914-ad76-7e08e6853b2f)

### Code

This code will alternate the lights lighting for 1 second each with a second of darkness in between until the Arduino is unplugged.

```cpp
// 1st LED is connected to pin 10 on the Arduino circuit board
int LED = 10;

// 2nd LED is connected to pin 9 on the Arduino circuit board
int LED2 = 9;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(LED, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop() {
  digitalWrite(LED, HIGH);  // Turn light on
  delay(1000);              // Wait 1 second
  digitalWrite(LED, LOW);   // Turn light off
  delay(1000);              // Wait 1 second
  digitalWrite(LED2, HIGH);  // Turn light on
  delay(1000);              // Wait 1 second
  digitalWrite(LED2, LOW);   // Turn light off
  delay(1000);              // Wait 1 second
}
```

## RGB LED

This is a special LED that you can use 0-255 color values to get any color of the RGB rainbow.

### Additional Supplies

|                                                                                                                                                                                                                                                                   |                                                                              |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb3kQuOt0u0zEctPkj%2F-MNb45XVGsC3EhbBbWLG%2Fimage.png?alt=media&#x26;token=af14b862-8091-4507-b1a9-c116339e106f" alt="" data-size="original"> | <p>2 LED lights</p><p>(any color, as long as it has only two connectors)</p> |
| <img src="https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb155tF2Eb8_UvmIhy%2F-MNb1decklIbKjOmK_1p%2Fimage.png?alt=media&#x26;token=1b27f65c-8728-45a7-97a8-7d7735a1cf32" alt="" data-size="original"> | 3 - 220 Ohm Resistors                                                        |

### Diagram

Note: This diagram is for a Cathode RGB LED where the 2nd connector is the ground (negative) connection.

![The blue wire is connected to pin 9, green to pin 10, and red to pin 11.](https://4077345522-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MFloEXqUun2rk6R28rU%2F-MNb3kQuOt0u0zEctPkj%2F-MNb4RmrxqFjQbWJKwof%2Fimage.png?alt=media\&token=eb7367f7-7d24-426a-a357-4506e2a27a58)

## Code

This example turns the light cyan using the "simple" way (setting each color with a line of code).

```cpp
// Red pin is connected to pin 11 on the Arduino circuit board
int red = 11;

// Green pin is connected to pin 10 on the Arduino circuit board
int green = 10;

// Blue pin is connected to pin 9 on the Arduino circuit board
int blue = 9;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  // Example of Cyan (0, 255, 255)
  analogWrite(red, 0);
  analogWrite(green, 255);
  analogWrite(blue, 255);
  delay(1000);
} 
```

This example shows the same thing, but using a custom function, making color changes take fewer lines of code:

```cpp
// Red pin is connected to pin 11 on the Arduino circuit board
int red = 11;

// Green pin is connected to pin 10 on the Arduino circuit board
int green = 10;

// Blue pin is connected to pin 9 on the Arduino circuit board
int blue = 9;

void setup() {
  // Establish the component connection and its type (output/input)
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  // Example of Cyan (0, 255, 255)
  RGB_Color(0, 255, 255);
  delay(1000);
} 

void RGB_Color(int redValue, int greenValue, int blueValue) {
  analogWrite(red, redValue);
  analogWrite(green, greenValue);
  analogWrite(blue, blueValue);
}
```
