# Experimenter's Guide for Metro

## Intro 

# Want to learn about the programming in **Arduino** &nbsp;but don't know where to start?&nbsp;
Danger: 

# Start&nbsp;with the&nbsp; **Experimenters Guide for Metro!**
![](https://cdn-learn.adafruit.com/assets/assets/000/045/498/medium800/adafruit_products_2488-08.jpg?1503086583)

The Experimenters Guide for the Adafruit Metro and Metro Express is meant to serve as a quick-start&nbsp;for makers, artists, hackers, students, educators, or&nbsp;anyone who wants to get started with the Metro or Metro M0 Express.

This guide has lots of **circuits** to get you comfortable with skills like learning about different types of electronic components (and how they work), programming an Adafruit Metro or Metro Express, breadboarding, and modifying code.&nbsp;

**Already have parts and a&nbsp;board that can be programmed by the Arduino IDE?** &nbsp;This guide will work for you too!

As you progress through this guide&nbsp;in order, you'll be comfortable with the Adafruit Metro enough to work on your own projects (or at least enough to try one of the thousands of projects in the Adafruit Learning System)

# About The Experimenters Guides&nbsp;
The experimenters guide is an expanded version of Oomlout's awesome&nbsp;[ARDX kit](https://www.adafruit.com/product/170), but it's compatible the Adafruit Metro Classic and Metro M0 Express. There are a lot of new circuits to take advantage of the Metro Classic and/or Express, and a bunch of small projects to do on your own.&nbsp;

These guides were designed for use both with the 'classic' **Metro (ATmega328)** or&nbsp;**Metro M0 Express (ATSAMD21)** based Metros

You can build all of the circuits with parts from the Adafruit Shop. We even provide links to the parts for each circuit in the parts page.

# Experimenter's Guide for Metro

## Electronics Primer

 **No previous electronic experience is required to have fun with this kit.** Here are a few details about each component to make identifying, and perhaps understanding them, a bit easier. If at any point you are worried about how a component is used or why it's not working the internet offers a treasure trove of advice, or [you can get help on our community support forums](https://forums.adafruit.com/)&nbsp;

## **Identifying Resistors by Color Code**
The graphic above is super useful for the Explorers guide - most CIRCs use them. Resistors have different values, consult this graphic if you get stuck later. If you want to get&nbsp;_really good_&nbsp;at identifying resistors quickly, play our fun&nbsp;iOS Game: [Mho's Resistance](https://www.adafruit.com/mhosresistance)

![](https://cdn-learn.adafruit.com/assets/assets/000/045/486/medium800/adafruit_products_ARDX-EG-ADAF-RAW_cdr.png?1503076933)

# **Lead Clipping**

Some components in this kit come with _very_ long wire leads. To make them more compatible with a breadboard a couple of changes can be&nbsp;made.

### **LEDs:**

Clip the leads so the long lead is ~10mm (3/8”) long and the short one is ~7mm (9/32”). If you don't own clippers, [you can pick up the&nbsp;CHP17 Flush Diagonal Cutters in the Adafruit shop](https://www.adafruit.com/product/152)

### **Resistors:**

Bend the leads down so they are 90 degrees to the cylinder. You can do this precisely with [Pliers](https://www.adafruit.com/product/146)&nbsp;or bending it against a 90 degree desk corner.&nbsp;

Then snip them so they are ~6mm (1/4”) long.

### **Other Components:**

Other components _may_ need clipping. Use your discretion when doing so.

# Identifying: TMP36 and NPN
While the TMP36 Analog Temperature Sensor and the NPN Transistor are similar, they perform very different tasks. To avoid mixing them up in your circuit, use these two pictures to identify which part you have:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/309/medium800/adafruit_products_tmp.png?1502831958)

![](https://cdn-learn.adafruit.com/assets/assets/000/045/308/medium800/adafruit_products_npn.png?1502831937)

# **Parts Field Guide**

#### (all of these parts can be found in the Metro Experimenters&nbsp;kit, _click_ the image to enlarge it)
# Experimenter's Guide for Metro

## Programming Primer

# About Arduino Programming

The Adafruit Metro&nbsp;is programmed in the C language. This is a quick little primer targeted at people who have a little bit of programing experience and just need a briefing on the idiosyncrasies of C and the Arduino IDE. If you find the concepts a bit daunting, don't worry, you can start going through the circuits and pick up most of it along the way.

For a more in-depth explanation of topics discussed both here and in the language, [check out the&nbsp;Arduino.cc Reference page.](https://www.arduino.cc/en/Reference/HomePage)

# The Arduino IDE
Now that Arduino is installed and configured, we're going to take a peek at it. Double click the Arduino icon to open it. &nbsp;It'll open up in a workspace, also called the **IDE** :

![](https://cdn-learn.adafruit.com/assets/assets/000/045/295/medium800/adafruit_products_arduino_ide-parts.png?1502829386)

Don't feel overwhelmed - as you progress through the Experimenters Guide, you'll learn to use each part of the IDE.

# **Structure**

You can think of the structure of an Arduino project like the scaffolding for a building. There's a specific structure that must be adhered to, or it all falls apart (and doesn't compile).

## **`void setup() { }`**&nbsp;

All the code between the two curly brackets **{**  **}** &nbsp;will be run only once&nbsp;when your Metro&nbsp;program first runs.

```
void setup() {
  // put your setup code here, to run once
}
```

## **`void loop() { }`**

This function is run _after_ `void setup()` has finished. After it has run once it will be run again, and again, forever, until power is removed.

```
void loop() {
  // put your main code here, to run repeatedly
}
```

# **Syntax**

One of the _slightly_ _frustrating_ elements of C is its formatting requirements, or syntax. While frustrating, this also makes the language very powerful. If you remember the following you should be alright:

## **`//`** **(single line comment)**

When writing a new sketch, or looking over an old one, having a comment to mark what you were thinking is important. To do this type two forward slashes and everything until the end of the line will be ignored by your program.

```
// this is a comment, it won't get run by the compiller 
this is not a comment, it will cause an error when run!!
```

## **`/* */`** **(multi-line comment)**

If you have a lot to say, you can type on multiple lines using a multi-line comment.&nbsp;Everything between these two symbols will be ignored in your program just like the single line comment.

```
/* 
 * Oh, hey!
 * hi there!
*/
```

# **`{ }`** **(curly brackets)**

These are used to mark when a block of code begins and ends. You'll see it used in functions and loops.

```
void serialPrintHello () 
{ // code begins 
  Serial.println("Hello");
} // code ends 
```

## **`;`** **(the semicolon)&nbsp;**

Each line of code **must** be ended with a semicolon. Missing a semicolon _will cause your code to refuse to compile_. It's often hard to find these, think of them as the _hide and seek champion&nbsp;_of your code and they're harder to overlook and cause errors.

```
// this will compile 
int servoPin = 5; 
// this won't compile, it's missing a semicolon
int servoPin = 5
```

# **Variables**

A program is nothing more than instructions to move numbers around in an intelligent way. Variables are used to do the moving.

## **`int`** **(integer)**

The main workhorse. The integer stores a number in **2 bytes** (or, 16 bits). It has&nbsp;no decimal places and will store a value between -32,768 and 32,767.

```
// this makes the variable i store the value 2
int i = 2;
```

## **`long`**

The long is used&nbsp;when an integer is not large enough. Takes **4 bytes** (32 bits) of RAM and has a larger range than an integer: between -2,147,483,648 and 2,147,483,647.

```auto
// this makes the variable j store the value 2000083647
long j = 2000083647
```

## **`bool`** **(boolean)**

The boolean is a simple variable that can either be True or False. True corresponds to a bit '1' and False corresponds to '0', it's only one bit.

```
// let's make a boolean called openSource and 
// set it to True
bool openSource = True;
// now let's make a variable called closedSource and
// set it to False
bool closeDSource = False;
```

## **`float`** &nbsp;

Used for floating point math, like decimals. Pi is a super long decimal, 3.1415...but it can be represented as a float such that it has more accurate precision (3.14 is more precise than just 3). It takes up&nbsp;4 bytes (32 bits) of RAM and has a range between -3.4028235E+38 and 3.4028235E+38.

```
// integers can't store decimal points
int pi = 3;
// so we use a float!
float pi = 3.14;
```

## `char` **(character)**

Stores **one character** using the ASCII code (ie 'A' = 65). Uses one byte (8 bits) of RAM. The Metro&nbsp;handles strings as an array of char’s.

```
// mychar stores the letter A, represented by an ascii value of 65
char myChar = 'A';
```

# **Math**

Now that we can store numbers in variables, we&nbsp;are going to manipulate them:&nbsp;

## = (equals)

Makes something equal to something else.

```
// b equals one
int b = 1;
// now, the value stored in b equals b times 2, which is one
b = b * 2;
```

## % (modulo)

Gives the remainder of a division operation.

```
// 12 divided by 10 = 1.2, modulo (%) will give us the remainder only
int mod = 12%10
// the value stored in int mod now equals 2
```

## + (addition)&nbsp;

Adds two numbers together.&nbsp;

```
int i = 2+2
// the value stored in int i now equals 4
```

## - (subtraction)

Subtracts one number from another.

```
int f = 4-2
// the value stored in int f now equals 2
```

## \* (multiplication)

Multiplies two numbers together.

```
int z = 5*2
// the value stored in int z now equals 10
```

## / (division)

Divides two numbers.

```
int y = 10/2 
// the value stored in int y now equals 5
```

# **Control Flow**

Programs are able to control the flow of execution (what runs next). These are a &nbsp;couple basic elements that you should get familiar with:

## **`If`**  **Conditions**

This will execute the code between the curly brackets if the condition is true, and if not it will test the else if condition if that is also false the else code will execute.

```
int i = 0;

if(i &gt; 5) {
  // this code does not execute, i is not greater than 5
}
else if (i &gt; 2) {
  // this code also does not execute, i is not greater than 2
}
else {
  // this code DOES execute, i is none of the above, so it falls into
  // this category 
}
```

# **`for()`** Loops

Used when you would like to repeat a chunk of code a number of times (can count up i++ or down i-- or use any variable).

```
for (int i = 1; i &lt; 5; i++) {
  // this code will run 4 times
}
```

# **Digital&nbsp;Input/Output**
![](https://cdn-learn.adafruit.com/assets/assets/000/044/662/medium800/adafruit_products_rsz_metroonluydigital.png?1501683785)

The right side of your Metro (or Metro Express)&nbsp;has a header containing 13 digital pins. These pins can be set to digital values ranging from 0 to 1023. The following commands pertain to these pins only:

## **`pinMode(pin, mode)`**
Used to set a pin's mode.

**Pin is the pin number** you would like to address, Digital 0-19. You can also set digital pinModes on Analog pins 0-5. The mapping for 0-5 is 14-19.

**Mode&nbsp;** can either be&nbsp;set as an **INPUT&nbsp;** or an **OUTPUT**

```
// a red LED is connected on Pin #11
int redLedPin = 11; 

void setup()
{
  // set the red LED as an OUTPUT 
  pinMode(redLedPin, OUTPUT);      
}
```

## **`digitalWrite(pin, value)`**
If you set a pin as an **OUTPUT&nbsp;** using pinMode, you can then set it to either&nbsp; **HIGH or LOW.&nbsp;** Setting the pin&nbsp; **HIGH&nbsp;** will pull it up to +3.3V or +5V. Setting it low will pull it to ground, or zero volts.&nbsp;

```
// this code will flash the LED on and off forever
void loop()
{
  // set the pin high to turn ON the LED
  digitalWrite(redLedPin, HIGH);
  delay(500);
  // set the pin low to turn OFF the LED
  digitalWrite(redLedPin, LOW);
  delay(500);
}
```

## **`digitalRead(pin)`**
Once a pin is set as an **INPUT** ,&nbsp;you can use this to return whether it is **HIGH** (pulled to +5 volts) or **LOW** (pulled to ground).

```
// this will store the value of sensorPin in an integer called sensorValue
int sensorValue = digitalRead(sensorPin);
```

# Analog Input/Output
![](https://cdn-learn.adafruit.com/assets/assets/000/044/664/medium800/adafruit_products_METRO-only-analog.png?1501685487)

While the Metro is a digital board, it's able to do analog operations. This is useful for getting&nbsp;precise sensor values.&nbsp;Here's how to deal with things that aren't digital:

## **`analogWrite(pin, value)`**
Through some "under the hood" tricks, the Metro is able to write analog values via Pulse Width Modulation. You can write any value between 0 and 255.&nbsp;

```
void loop()
{
  // set the LED to full brightness 
  analogWrite(ledPin, 255);  
  // turn the LED off
  analogWrite(ledPin, 0);
}
```

## **`analogRead(pin)`**
Reads the value of the analog pin. The value returned can be between 0 and 1024.&nbsp;

```
sensorVal = analogRead(sensorPin);
```

# Experimenter's Guide for Metro

## Downloads

The experimenters guide has available source code and breadboard diagrams freely available for download on our GitHub:&nbsp;

## Fritzing Diagrams
![](https://cdn-learn.adafruit.com/assets/assets/000/050/230/medium800/adafruit_products_fitzing.png?1516211706)

We designed the breadboard layout diagrams you see in this guide using the Open Source tool [Fritzing](http://fritzing.org). If you’d like to view or modify any of these templates, click the button below:

 **Note:** Most of the diagrams include components for Fritzing from the [Adafruit Fritzing Parts/Boards Library. You'll need to download and install this &nbsp;order to edit our diagrams.](../../../../using-the-adafruit-library-with-fritzing/download-the-fritzing-library-from-github)

[Breadboard Fritzing Diagrams for the Experimenters Guides](https://github.com/adafruit/ARDX-Fritzing-Diagrams)
## Code
[Metro Explorers Guide Code](https://github.com/adafruit/METROX-Examples-and-Project-Sketches)
We also have the newest version of all of this guide's code stored in github Github&nbsp;repository. Feel free to submit issues, contributions, requests and modifications to this repository, we'll answer any questions you have in the[community support forums.](https://forums.adafruit.com/index.php?sid=8bf66132f67d8b36e6c4cdf160fd0cb7)

# Experimenter's Guide for Metro

## What Board Do I Have?

This guide was designed to work&nbsp;with both the [Metro](https://www.adafruit.com/product/2488) and the [Metro Express](https://www.adafruit.com/product/2488). The main way to tell if your board is the express is if it says "express" on the board. There's also a SWD port on the bottom of the Metro Express which isn't present on the Metro. The diagram below points these two differences out:

![](https://cdn-learn.adafruit.com/assets/assets/000/043/338/medium800/adafruit_products_metrovexpress.png?1498856606)

## I have a Metro

&nbsp;This guide will work without any modification, follow the regular steps and have fun!

## I have a Metro Express

There are&nbsp; **two** things to look out for while you work through this guide:

**1) Wiring:** Some&nbsp;circuits have an extra wiring page called "Wiring for Metro Express" and some don't. If the circuit you are looking at does not have this sub-page, use the regular Metro wiring. If you see the Metro Express Wiring page, use the wiring in that page _instead_.&nbsp;

**2) Code:&nbsp;**If there needs to be a modification in code for Metro Express, instructions will be present to switch the code to&nbsp;a Metro Express compatible code.&nbsp;

# Experimenter's Guide for Metro

## Setting up your Metro

Warning: 

If you haven't assembled your Metro or Metro Express, Half-Sized Breadboard and Mounting Plate yet, [click here for instructions](../../../../arduino-prototyping-mounting-plate)

You'll need an [Adafruit Metro](https://www.adafruit.com/product/2488)&nbsp;or Metro Express.&nbsp;

If you did not purchase the Metro Experimenter's Kit, you might&nbsp;want to purchase a&nbsp;[Half-size&nbsp;Breadboard](https://www.adafruit.com/product/64)&nbsp;and the [Plastic mounting plate for the breadboard.&nbsp;](https://www.adafruit.com/product/275)It holds everything you need to experiment with small circuits nicely and keeps everything organized.

&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/665/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501687002)

## USB Micro Cable

&nbsp;

I can't stress it enough. **Make sure you have a good USB cable.** Naughty USB cables **will** really ruin your day, like a stone in your shoe. Throw&nbsp;out bad cables and replace them with a good one - they are designed to be disposable!

![adafruit_products_Micro_USB_Cable_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/007/medium640/adafruit_products_Micro_USB_Cable_White_Background_ORIG.jpg?1502222382)

Danger: 

# Power your Metro!
If you have a Metro, these next steps will get you set up with the Arduino environment. [If you're not sure what board you have, click here.](../../../../experimenters-guide-for-metro/what-board-do-i-have)

Connect your USB Micro cable to the USB Port of the Metro. The&nbsp; **On** LED should turn&nbsp;a solid **green** and remain on.

# Arduino Bootloader Check.
Next you'll want to check if your Metro is programmed with the Arduino bootloader, which is required for use.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/045/503/medium800thumb/adafruit_products_metrobootclassic.jpg?1503087274)

While plugged into power (make sure the **On** LED is turned on), **quickly press the&nbsp;Reset**  **button**. You'll see it quickly flash **three** times. It happens really fast so don't worry if you can't see all three flashes.&nbsp;

# Download the Arduino Software
This is the _free_ application you'll use to write programs and talk to your Metro. There are instructions below for installation in most operating systems (and browser for Chromebook users running CodeBender!).

[Go to the official Arduino Software page](https://www.arduino.cc/en/Main/Software)
Click the button above to go to the official software page ([https://www.arduino.cc/en/Main/Software](https://www.arduino.cc/en/Main/Software)) and you'll see a box that looks like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/044/668/medium800/adafruit_products_Arduino_-_Software.png?1501690766)

### 

Don't worry, the Arduino Software is under&nbsp;_constant_ revisions and the screenshot above is not representative of the latest version. Download the version for your platform.

# Experimenter's Guide for Metro

## Windows Setup

## Downloading for Windows
Download and install with the **&nbsp;Windows Installer.**  **The .zip&nbsp;file** (non-admin install) **is**  **not**  **recommended** unless you cannot run the installer.

# (Windows) Installing Arduino
Click on the **Windows Installer** link to download the installer, then double click to launch it

[![arduino_opening.png](https://cdn-learn.adafruit.com/assets/assets/000/033/477/medium800/arduino_opening.png?1467169949)](../../../../assets/33477)

You may get a warning asking if you're sure you want to run the installer. It's ok, click **YES**

[![arduino_control.png](https://cdn-learn.adafruit.com/assets/assets/000/033/481/medium800/arduino_control.png?1467170285)](../../../../assets/33481)

There is an open source license to click through. Install in the default location

[![arduino_dest.png](https://cdn-learn.adafruit.com/assets/assets/000/033/483/medium800/arduino_dest.png?1467170399)](../../../../assets/33483)

You can use the default setup installation options

[![arduino_setup.png](https://cdn-learn.adafruit.com/assets/assets/000/033/482/medium800/arduino_setup.png?1467170363)](../../../../assets/33482)

Finally it will take a minute or two to install

[![arduino_installing.png](https://cdn-learn.adafruit.com/assets/assets/000/033/484/medium800/arduino_installing.png?1467170432)](../../../../assets/33484)

When done you'll have the software installed:

[![arduino_duinoicon.png](https://cdn-learn.adafruit.com/assets/assets/000/033/485/medium800/arduino_duinoicon.png?1467170498)](../../../../assets/33485)

## (Windows) Installing Drivers
Depending on your Arduino compatible you may need to install seperate drivers for the USB to serial converter

For all Adafruit compatibles, we have an _all in one_ installer that will install all of the Adafruit board drivers. It will also install the FTDI and CP210x drivers

Click below to download our Driver Installer:

[Download Adafruit Boards Windows Driver Installer](https://github.com/adafruit/Adafruit_Windows_Drivers/releases/latest/adafruit_drivers_*.exe)
Download and run the installer

[![arduino_flora_1download.png](https://cdn-learn.adafruit.com/assets/assets/000/033/486/medium800/arduino_flora_1download.png?1467171286)](../../../../assets/33486)

Run the installer! Since we bundle the SiLabs and FTDI drivers as well, you'll need to click through the license

[![arduino_flora_2lic.png](https://cdn-learn.adafruit.com/assets/assets/000/033/487/medium800/arduino_flora_2lic.png?1467171352)](../../../../assets/33487)

Select which drivers you want to install (we suggest selecting all of them so you never have to worry about installing drivers when you start to explore other Arduino-compatibles)

[![arduino_drivres.png](https://cdn-learn.adafruit.com/assets/assets/000/033/490/medium800/arduino_drivres.png?1467171480)](../../../../assets/33490)

Click **Install** to do the installin'

[![arduino_flora_4complete.png](https://cdn-learn.adafruit.com/assets/assets/000/033/489/medium800/arduino_flora_4complete.png?1467171422)](../../../../assets/33489)

You should not need to restart your computer but it's not a _bad_ idea!

## (Windows) Find&nbsp;your Serial COM Port
To verify your Arduino driver installed properly, plug it into USB and open up the **Device Manager**. You can find the Device Manager in the **Control Panel** (search for Device Manager)

[![arduino_devicemanager.png](https://cdn-learn.adafruit.com/assets/assets/000/033/491/medium800/arduino_devicemanager.png?1467171668)](../../../../assets/33491)

When you open the Device Manager, find the section called **Ports** and expand it:

[![arduino_unoCOM.png](https://cdn-learn.adafruit.com/assets/assets/000/033/492/medium800/arduino_unoCOM.png?1467171702)](../../../../assets/33492)

You'll see an icon next to some text that says **Arduino UNO (COMxx)** where **xx** is a number

If you have a Metro, it won't say Arduino UNO, just **USB Serial Port (COMxx)**

[![arduino_genericCOM.png](https://cdn-learn.adafruit.com/assets/assets/000/033/493/medium800/arduino_genericCOM.png?1467171801)](../../../../assets/33493)

The COM number may vary but it should be something like **COM3** or **COM4**. The COM stands for "communication", and each one has a unique number, known as the COM Port number. In this case the COM Port number is COM18.

You can unplug your Arduino to see the COM port device disappear and re-appear when plugged in.

If you **don't** see the Arduino show up, check:

- Is your cable a data cable or charge only? Try another USB cable
- Try another USB port!
- Verify you installed the drivers, you can always try installing them again (never hurts)
- Check your Arduino does not need some other drivers, your vendor can point you at the right driver if necessary

# Experimenter's Guide for Metro

## Mac Setup

## Downloading for macOS or OS X
Download the version for Mac OS X, uncompress the .zip file, and drag the Application out of the folder.&nbsp;

# (macOS/OS X) Installing Arduino
&nbsp;Click on the **Mac OS X Installer** link to download the installer

[![arduino_screenshot_01.png](https://cdn-learn.adafruit.com/assets/assets/000/033/852/medium800/arduino_screenshot_01.png?1468533714)](../../../../assets/33852)

Then double click to expand/launch it

[![arduino_expanding.png](https://cdn-learn.adafruit.com/assets/assets/000/033/850/medium800/arduino_expanding.png?1468533669)](../../../../assets/33850)

it will automatically give you the **Arduino app** the teal icon:

[![arduino_icon.png](https://cdn-learn.adafruit.com/assets/assets/000/033/851/medium800/arduino_icon.png?1468533686)](../../../../assets/33851)

## (macOS/OS X) Find your Serial Port
Now we want to ensure your Metro is properly communicating with your computer. In your&nbsp; **Applications&nbsp;** folder, find the&nbsp; **Utilities** folder and double click it.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/669/medium800/adafruit_products_comport1-utilities.png?1501692116)

Then, find the application named&nbsp; **"Terminal"**. Double click it to open:

![](https://cdn-learn.adafruit.com/assets/assets/000/044/670/medium800/adafruit_products_macsetup2.png?1501692179)

Once&nbsp; **Terminal** is open, you'll be greeted by a prompt. Type the following into it:&nbsp;

`ls /dev/cu*`&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/044/671/medium800/adafruit_products_mac3.png?1501692346)

Once that's typed in, you should see a line with the text&nbsp; **_/dev/cu.usbmodemxxxx&nbsp;_** OR&nbsp;_ **/dev/cu.usbserial-xxxxx**.&nbsp;_The&nbsp; **xxxx's&nbsp;** can be any letter or number. If you see this, the driver was installed properly and the Metro was found on your computer.

If you're not comfortable about using Terminal, there's another (easier) way to check if everything's been installed properly. Click on the **Apple Icon** on your menubar. In the dropdown menu, click&nbsp; **About This Mac.**

![](https://cdn-learn.adafruit.com/assets/assets/000/044/672/medium800/adafruit_products_mac4.png?1501692513)

Then, click on&nbsp; **System Report**. System Profiler will open, then click on **USB&nbsp;** in the&nbsp; **Hardware&nbsp;** drop-down menu. You should see the Adafruit Metro 328 as one of your USB&nbsp;devices.

# (macOS / OS X) Installing Drivers
Next, you'll want to grab and install the FTDI VCP Drivers and the SiLabs CP210x Drivers.

[First, navigate to the FTDI VCP Site and grab the driver for your OS X version and platform.](http://www.ftdichip.com/Drivers/VCP.htm)

![](https://cdn-learn.adafruit.com/assets/assets/000/045/050/medium800/adafruit_products_vcp-drivers.png?1502293152)

Then, unzip the file and install the .dmg file.

[You'll also need the SiLabs CP210x Drivers. You can get them from the SiLabs site.](https://www.silabs.com/products/development-tools/software/usb-to-uart-bridge-vcp-drivers)

![](https://cdn-learn.adafruit.com/assets/assets/000/045/051/medium800/adafruit_products_vcpsilabs.png?1502293229)

Then, unzip the file and install the .dmg file.

## Verifying macOS / OS X&nbsp;Drivers
We just want to verify that everything is correctly set up. Plug your Metro Classic in, then &nbsp;open the Arduino IDE and navigate to&nbsp; **Tools \> Port.&nbsp;**

![](https://cdn-learn.adafruit.com/assets/assets/000/045/052/medium800/adafruit_products_Port____dev_cu_usbserial-00406114__and_Tools_and_Menubar.png?1502293443)

You should see a device listed as **/dev/cu.usbserial** , followed by number and/or letters. This is your Metro Classic.&nbsp;

If you don't see this, ensure your FTDI and SILabs drivers are correctly installed (for both the right OS Version and Platform). Then, check both the USB port you're using (try another port) or a cable (you might be using a charge-only cable).

# Experimenter's Guide for Metro

## Linux Setup

## Downloading for Linux
There are download options available for both 32-bit and 64-bit Linux. Download the version for the system you're using, manually decompress the .tar file, and install the software.&nbsp;&nbsp;

# (Linux) Installing Arduino
Click on the matching **Linux Installer** link (32 bit, 64 bit or ARM) to download the installer - save the file to your Downloads folder

[![arduino_download.png](https://cdn-learn.adafruit.com/assets/assets/000/033/866/medium800/arduino_download.png?1468536076)](../../../../assets/33866)

From within your Terminal program, **cd** to the Downloads directory, and untar the package with **tar xf arduino\*.xz** then **cd** into the **arduino-n.n.n** folder created:

[![arduino_untar.png](https://cdn-learn.adafruit.com/assets/assets/000/033/867/medium800/arduino_untar.png?1468536145)](../../../../assets/33867)

Run **./install.sh** to install the software. I've got an old Ubuntu install so I got warnings, but it did create that desktop icon for me!

[![arduino_install.png](https://cdn-learn.adafruit.com/assets/assets/000/033/868/medium800/arduino_install.png?1468536234)](../../../../assets/33868)

## (Linux) Installing Drivers
Linux doesn't have any drivers to install, assuming you're running a v2.6 kernel or higher, which is almost certainly true. These instructions assume you're running Ubuntu. Each Linux distribution is different, but the instructions should be basic enough to follow for other distros.

You can verify your kernel version by running **uname -a** in a terminal window, note that this kernel is version **2.6.20**

[![arduino_uname.png](https://cdn-learn.adafruit.com/assets/assets/000/033/864/medium800/arduino_uname.png?1468535524)](../../../../assets/33864)

And this one is **3.2.0-23**

[![arduino_lin32.png](https://cdn-learn.adafruit.com/assets/assets/000/033/863/medium800/arduino_lin32.png?1468535496)](../../../../assets/33863)

Some older Linux distributions used to install **brltty** (braille device) which will conflict with the Arduino. You **must uninstall brltty if it is installed!** Do so by running `sudo apt-get remove brltty `or equivalent In a terminal window. If it says it's not installed then thats OK. If you're not running a Debian-derived installation use whatever tool is necessary to verify that you don't have **brltty** running

## (Linux) Find your Serial Port
Plug in the Arduino, verify that the green LED is lit, and type **ls /dev/ttyUSB\*** into a terminal window, you should see a device file called something like ttyUSB0

[![arduino_lstty.png](https://cdn-learn.adafruit.com/assets/assets/000/033/869/medium800/arduino_lstty.png?1468536338)](../../../../assets/33869)

If you can't seem to find it, use **dmesg | tail** right after plugging in the Arduino and look for hints on where it may put the device file. For example here is says **Serial Device converter now attached to ttyUSB0**

[![arduino_dmsgtail.png](https://cdn-learn.adafruit.com/assets/assets/000/033/870/medium800/arduino_dmsgtail.png?1468536357)](../../../../assets/33870)

If you see something like this

`[1900.712000] ftdi_sio 2-10:1.0: FTDI USB Serial Device converter detected[1900.712000] drivers/usb/serial/ftdi_sio.c: Detected FT232BM[1900.712000] usb 2-10: FTDI USB Serial Device converter now attached to ttyUSB0[1901.868000] usb 2-10: usbfs: interface 0 claimed by ftdi_sio while 'brltty' sets config #1 [1901.872000] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0 [1901.872000] ftdi_sio 2-10:1.0: device disconnected`

That means you have not uninstalled **brltty** and you should try again.

# Experimenter's Guide for Metro

## Configure Arduino for the Metro Express

Info: 

If you've followed the [Setting up your Metro Express](../../../../experimenters-guide-for-metro/setting-up-your-metro-express) page, you should be ready to roll. We need to make some modifications to Arduino to allow it to work with the Metro Express.&nbsp;

## Metro Express Arduino IDE Setup
After you have downloaded and installed **the latest version of Arduino IDE** , you will need to start the IDE&nbsp;and navigate to&nbsp;the **Preferences** menu. You can access it from the **File** menu in _Windows_ or _Linux_, or the **Arduino** menu on _OS X_.

[![flora_prefs.png](https://cdn-learn.adafruit.com/assets/assets/000/041/549/medium800/flora_prefs.png?1494204209)](../../../../assets/41549)

A dialog will pop up just like the one shown below.

[![flora_Screen_Shot_2015-05-07_at_9.07.21_AM.png](https://cdn-learn.adafruit.com/assets/assets/000/025/281/medium800/flora_Screen_Shot_2015-05-07_at_9.07.21_AM.png?1431004060)](../../../../assets/25281)

We will be adding a URL to the new **Additional Boards Manager URLs** option. The list of URLs is comma separated, and _you will only have to add each&nbsp;URL once._&nbsp;New Adafruit boards and updates to existing boards&nbsp;will automatically be picked up&nbsp;by the Board Manager each time&nbsp;it is opened. The URLs point to index files that the Board Manager uses to build the list of available & installed boards.

To find the most up to date list of URLs you can&nbsp;add, you can visit the list of [third party board URLs on the Arduino IDE wiki](https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls#list-of-3rd-party-boards-support-urls). We will only need to add one URL to the IDE in this example, but _ **you can add multiple URLS by separating them with commas** _. Copy and paste the link below into the&nbsp; **Additional Boards Manager URLs** option in the Arduino IDE preferences.

### `https://adafruit.github.io/arduino-board-index/package_adafruit_index.json`

[![flora_urls.png](https://cdn-learn.adafruit.com/assets/assets/000/033/278/medium800/flora_urls.png?1466733189)](../../../../assets/33278)

Here's a short description of each of the Adafruit supplied packages that will be available in the Board Manager when you add the URL:

- **Adafruit AVR Boards** - Includes support for Flora, Gemma, Feather 32u4, Trinket, & Trinket Pro.
- **Adafruit SAMD Boards** - Includes support for Feather M0, Metro M0, Circuit Playground Express, Gemma M0 and Trinket M0
- **Arduino Leonardo & Micro MIDI-USB** - This adds MIDI over USB support for the Flora, Feather 32u4, Micro and Leonardo using the [arcore project](https://github.com/rkistner/arcore).

If you have multiple boards you want to support, say ESP8266 and Adafruit, have both URLs in the text box separated by a comma (,)

Once done click **OK** to save the new preference settings. Next we will look at installing boards with the Board Manager.

Now continue to the next step to actually install the board support package!

# Using the Metro Express with Arduino IDE
Since the Metro Express M0&nbsp;uses an ATSAMD21 chip running at 48 MHz, you can pretty easily get it working with the Arduino IDE. Most libraries (including the popular ones like NeoPixels and display) will work with the M0, especially devices & sensors that use i2c or SPI.

Now that you have added the appropriate URLs to the Arduino IDE preferences in the previous page, you can open the **Boards Manager** by navigating to the **Tools-\>Board** &nbsp;menu.

[![adafruit_products_boardmanager.png](https://cdn-learn.adafruit.com/assets/assets/000/028/791/medium800/adafruit_products_boardmanager.png?1448652571)](../../../../assets/28791)

Once the Board Manager opens, click on the category drop down menu on the top left hand side of the window and select **Contributed**. You will then be able to select and install the boards supplied&nbsp;by the URLs added to the prefrences.

# Install SAMD Support
First up, install the **Arduino SAMD Boards** version **1.6.15** or later

You can type **Arduino SAMD** in the top search bar, then when you see the entry, click **Install**

[![adafruit_products_arduinosamd162.png](https://cdn-learn.adafruit.com/assets/assets/000/028/792/medium800/adafruit_products_arduinosamd162.png?1448652786)](../../../../assets/28792)

# Install Adafruit SAMD
Next you can install the Adafruit SAMD package to add the board file definitions

You can type **Adafruit SAMD** in the top search bar, then when you see the entry, click **Install**

[![adafruit_products_adafruitsamd.png](https://cdn-learn.adafruit.com/assets/assets/000/028/794/medium800/adafruit_products_adafruitsamd.png?1448652973)](../../../../assets/28794)

Even though in theory you don't need to - I recommend rebooting the IDE

**Quit and reopen&nbsp;the Arduino IDE** to ensure that all of the boards are properly installed. You should now be able to select and upload to the new boards listed in the **Tools-\>Board** menu.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/681/medium800/adafruit_products_arduinoboardselect.png?1501694774)

Select the&nbsp; **Adafruit Metro M0 Express&nbsp;** from the dropdown.&nbsp;

# Experimenter's Guide for Metro

## CIRC01: Blinking LED

![](https://cdn-learn.adafruit.com/assets/assets/000/042/557/medium800thumb/adafruit_products_IMG_1833.jpg?1497372392)

# What We're Doing

LEDs (light emitting diodes) are used in all sorts of clever things which is why we have included them in this guide. We will start off with something very simple, turning one on and off, repeatedly, producing a pleasant blinking effect. To get started, grab the parts from the parts page and then plug everything in according to the layout diagram.

# Experimenter's Guide for Metro

## Parts

## Let's begin by gathering our parts:
Danger: 

### **10mm Blue LED**

&nbsp;

[If you'd like to order more of these 10mm LEDs from the Adafruit shop click here!](https://www.adafruit.com/product/847)

![adafruit_products_Untitled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/624/medium640/adafruit_products_Untitled.png?1499439881)

### **560 Ohm Resistor**

Colors: Green \> Blue \> Brown

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/514/medium640/adafruit_products_560ohm.png?1499356545)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/515/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499356545)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/683/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695033)

# Experimenter's Guide for Metro

## Wiring 

# Breadboard Layout

Connect your parts to your breadboard as shown below.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/050/262/medium800/adafruit_products_circ01_bb.png?1516230556)

## Steps
1. Connect the longer leg&nbsp;of the LED to **Pin&nbsp;13** on the Metro. The shorter lead should be connected with a resistor to the ground terminal.&nbsp;
2. The Metro is capable of supplying 5V to your breadboard. Use a **red** &nbsp;wire to connect the **5V Pin** on the Metro to the left power&nbsp;rail of the breadboard. Connect **&nbsp;** the **GND Pin&nbsp;** of the Metro to the rightmost part of the power rail.&nbsp;
3. Connect one leg of the 560 Ohm resistor to the shorter leg of the resistor. The other leg of this resistor is connected to the rail with the black wire (this will be your ground rail).
4. Your completed circuit should be identical to the layout&nbsp;above. Make sure to verify all connections before moving on.&nbsp;

## Breadboard Layout Sheet&nbsp;
Each circuit comes with a printable layout sheet to place on the mini-breadboard. You can hold them down with headers (or tape) like this:

![](https://cdn-learn.adafruit.com/assets/assets/000/049/712/medium800/adafruit_products_CIRC01-3dexploded-445.png?1514488655)

[Click here to download the printable Breadboard Layout Sheet for CIRC01](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-01-sheet-ADAF/CIRC-01-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code 

![](https://cdn-learn.adafruit.com/assets/assets/000/042/604/medium800thumb/adafruit_products_loadblinksketch_%281%29.jpg?1497447493)

The Arduino Editor provides a great example for blinking a LED. There's no need to type anything, just click in the following in the Arduino Editor: **_File \> Examples \> 1.Basic \> Blink_**

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/042/629/medium800thumb/adafruit_products_boardslect.jpg?1497465940)

Next, we want Arduino to know what Board is being used currently. To do this, navigate to **Tools \> Board \> Arduino/Genuino Uno**

&nbsp;&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/042/628/medium800thumb/adafruit_products_portselect.jpg?1497465712)

Lastly, we&nbsp;need to upload the program. To do this plug the Metro&nbsp;board into your USB port. Then select the proper port in **Tools \> Serial Port \> (the Serial/COM port of your metro)**. Next upload the program by going to **Sketch \> Upload** (or press&nbsp; **ctrl+u** on your keyboard)

After uploading to the Metro, you should see the LED on both the Metro and the breadboard blinking.&nbsp;

## Blink&nbsp;

If you have trouble loading the Blink Sketch from Arduino's examples, you can copy and paste the code below into the editor.&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC01_BLINK_LED/CIRC01_BLINK_LED.ino

## Having issues with CIRC01?
### 

LEDs will only work in **one** direction. Try taking it out and twisting it 180 degrees. (no need to worry, installing it backwards does no permanent harm).

### 

This happens sometimes, the most likely cause is a confused serial port, you can change this in **tools\>serial port\>**

### 

[A broken circuit is no fun, post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better 

## **Congrats on building your&nbsp;first circuit with the Adafruit Metro!**

Let's play around to make your circuit better and learn some more tricks/tips that will be useful later on.

# Change&nbsp;the pin
The LED is connected to pin 13 but we can use any of the METRO’s pins. To change it take the wire plugged into pin 13 and move it to a pin of your choice (from 0- 13)

You can also use analog 0-5, Analog #0 is 14, Analog #1 is 15, etc.

Then in the code change all occurrences of `LED_BUILTIN` -\> _newpin_. That is, change every&nbsp; `LED_BUILTIN` to `8`

Then Upload the sketch: &nbsp;by pressing **ctrl+u**

# Change the Blink time

Unhappy with one second on one second off? In the code change the lines:

`digitalWrite(LED_BUILTIN, HIGH); `  
`delay(time on); //(seconds * 1000) `  
`digitalWrite(LED_BUILTIN, LOW); `  
`delay(time off); //(seconds * 1000)`

# Control the brightness

Along with digital (on/off) control the METRO can control some pins in an analog (brightness) fashion. (more details on this in later circuits). To play around with it. Change the LED to pin 9: (also change the wire) by replacing all `LED_BUILTIN` with `9`

Replace the code inside the _{ }_'s of _loop()_ with the following line:

`analogWrite(9, new number);`

Note that in the line above,

`new number` is any number between 0 and 255. 0 turns the LED completely off. 255 is the maximum brightness of the LED. Anything between 0 and 255 is a varying brightness. Play around and find one that you like.&nbsp;

# Fading

We will use another included example program. To open go to **File \> Examples \> 3.Analog \> Fading&nbsp;**

Then upload to your board and watch as the LED fades in and then out.

# Experimenter's Guide for Metro

## CIRC02: 8 LED Fun

![](https://cdn-learn.adafruit.com/assets/assets/000/042/791/medium800thumb/adafruit_products_IMG_1933.jpg?1497633584)

# What We're Doing

We have caused one LED to blink, now it's time to up the stakes. Lets connect eight. We'll also have an opportunity to stretch the Metro&nbsp;a bit by creating various lighting sequences. This circuit is also a nice setup to experiment with writing your own programs and getting a feel for how the Metro works.

Along with controlling the LEDs we start looking into a few simple programming methods to keep your programs small: `for()` loops and `array[]`'s&nbsp;

# Experimenter's Guide for Metro

## Parts 

### **5mm Green LED**

**x8 (You'll need 8 of these for CIRC02)**

&nbsp;

[If you'd like to order extra green LEDs from the Adafruit shop, click here!&nbsp;](https://www.adafruit.com/product/298)

&nbsp;

![adafruit_products_greenled_(1).png](https://cdn-learn.adafruit.com/assets/assets/000/043/625/medium640/adafruit_products_greenled_%281%29.png?1499440477)

### **560 Ohm Resistor**

**x8 (You'll need 8 of these for CIRC02)**

(These are the same resistors that you used in CIRC01, the colors go from:&nbsp;Green \> Blue \> Brown)

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/516/medium640/adafruit_products_560ohm.png?1499356598)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/542/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357482)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/682/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695006)

# Experimenter's Guide for Metro

## Wiring 

## Breadboard Layout
![](https://cdn-learn.adafruit.com/assets/assets/000/042/783/medium800/adafruit_products_circ02-left-side_bb-1-ANNOTATED.png?1497627080)

# Steps

1. First, connect the 8 Green LEDs to the breadboard. It's useful to space them one hole apart as shown in the layout picture.&nbsp;
2. Next, starting with the green LED at the bottom, connect the longer side&nbsp;of the green LED to a digital pin on the metro. Start with **Pin 2&nbsp;** and work your way up until&nbsp; **Pin 9. &nbsp;** (tip: use different color wires to color-code&nbsp;your LEDs)
3. Then, connect the 8 (560ohm) resistors to the shorter side&nbsp;of the LED.
4. The Metro is capable of supplying 5V to your breadboard. Use a **red** &nbsp;wire to connect the **5V Pin** on the Metro to the left power&nbsp;rail of the breadboard. Connect **&nbsp;** the **GND Pin&nbsp;** of the Metro to the rightmost part of the power rail.
5. Your completed circuit should be identical to the layout&nbsp;above. Make sure to verify all connections before moving on.&nbsp;

[Click here to download the printable Breadboard Layout Sheet for CIRC02](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-02-sheet-ADAF/CIRC-02-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

The CIRC02 code is not one of the default Arduino sketches. To use it, copy the code&nbsp;from below and paste it into&nbsp;a new Arduino Sketch **(ctrl+n/command+n)**

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC02_8_LEDS/CIRC02_8_LEDS.ino

## Compile and Upload
![](https://cdn-learn.adafruit.com/assets/assets/000/042/670/medium800thumb/adafruit_products_verifysketch.jpg?1497473513)

Before uploading, an important step is to verify that your code compiles. Click on the **check button** on the toolbar (or, on your keyboard press **control+r** or **command+r** for mac users) to compile your code.&nbsp;

If you receive no errors compiling, **upload the sketch to the board** ([click here for a refresher on how to do this&nbsp;from the previous circuit](../../../../experimenters-guide-for-metro/make-it-better-1#code)). After uploading, you should see an animated LED light show [like this](../../../../experimenters-guide-for-metro/circ02-8-led-fun#circ02-8-led-fun).

# Not Working? CIRC02 not matching the GIF?
### 

It is easy to insert an LED backwards. Check the LEDs that aren't working and ensure they the right way around.

### 

With eight wires it's easy to cross a couple. Double check that the first LED is plugged into pin 2 and each pin thereafter.&nbsp;

### 

Its easy to accidentally misplace a wire without noticing. Pulling everything out and starting with a fresh slate is often easier than trying to track down the problem.

### 

[We'll help you out! Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better 

# Switching to Loops
Bored of watching the light show? Want to make your own animation, change the animation, or learn about looping&nbsp;functions? Let's make CIRC02 better!

In the `void loop()`&nbsp;procedure, there are 4 lines. The last three all start with a `//`. This means the line is a comment (it won't run). We can switch the program to use loops by deleting the comments (If you want to learn more about comments,&nbsp;[we have a great writeup](../../../../ladyadas-learn-arduino-lesson-number-2#slash-slash-one-line-comments)!).

First, inside `void loop()`, add slashes&nbsp;to disable the `oneAfterAnotherNoLoop()`&nbsp;procedure from running:

&nbsp; &nbsp; `oneAfterAnotherNoLoop();`_&nbsp;-\>_ `//oneAfterAnotherNoLoop();`

Next, we are going to delete comments (slashes) to enable the&nbsp;oneAfterAnotherLoop() procedure&nbsp;to run with loops:

**&nbsp; &nbsp;** `//oneAfterAnotherLoop();` &nbsp;_-\>_&nbsp;`oneAfterAnotherLoop(); `

We should verify that our code compiles correctly now, click the check mark (or, **ctrl/command+r)**. If everything compiles with no errors, go ahead and Upload ( **ctrl+u** ) the new program to your metro.&nbsp;

### 

There was no change! Both procedures run the same animation.&nbsp; (click to reveal the answer)

### 

oneAfterAnotherNoLoop() runs the animation without using a loop which makes for a lot of typing. Using oneAfterAnotherLoop() will require less typing to run the same animation! (click to reveal the answer)

# Extra Animations
Tired of this animation? There are more animations for you to play around with!

**To enable them** , **uncomment** (just delete the `//`) **row 3 and row 4** so that:

**&nbsp; &nbsp;** `//oneOnAtATime();` -\> `oneOnAtATime();`

**&nbsp; &nbsp;** `//inAndOut();` -\> `inAndOut();`

&nbsp;Then Upload the program ( **ctrl+u** ) to your board and enjoy the new light animations.&nbsp;

# Make your own animations
Go ahead and jump into the included code and start changing things around. &nbsp;

To tell the Metro to **turn a LED on** ,

&nbsp; &nbsp; `digitalWrite(pinNumber, HIGH);`

If you want to tell the Metro to **turn a LED off** ,

&nbsp; &nbsp;`digitalWrite(pinNumber, LOW);`&nbsp;

Type away!&nbsp;Regardless of what you change you won't break anything.

# Experimenter's Guide for Metro

## CIRC03: Spin Motor Spin

![](https://cdn-learn.adafruit.com/assets/assets/000/042/793/medium800thumb/adafruit_products_IMG_1937.jpg?1497641790)

# What We're Doing

The Metro's pins are great for directly controlling small electric items like LEDs. However, when dealing with larger items (like a toy motor or washing machine), an external transistor is required.

A transistor is incredibly useful. It switches a lot of current using a much smaller current. A transistor has 3 pins. For a negative type (_NPN_) transistor, you connect your load to collector and the emitter to ground. Then, when a small current flows from base to the emitter, a current will flow through the transistor and your motor will spin (this happens when we set our Metro&nbsp;pins&nbsp; **high** ). [For a more in-depth explanation about transistors, click here](../../../../adafruit-arduino-lesson-13-dc-motors/arduino-code?view=all#transistors).

There are literally _thousands_ of different types of transistors, allowing every situation to be perfectly matched. We have chosen a _P2N2222,_&nbsp;a rather common general purpose transistor. The important factors in our case are that its maximum voltage (_40v_) and its maximum current (_600 milliamp_) are both high enough for our toy motor ([full details can be found on its datasheet](http://ardx.org/2222)).

# Experimenter's Guide for Metro

## Parts

### **DC&nbsp;Toy/Hobby Motor**

&nbsp;

[If you'd like to order another DC Motor from the Adafruit shop, click here!](https://www.adafruit.com/product/711)

![adafruit_products_Toy_Motor_White_Background_Final_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/519/medium640/adafruit_products_Toy_Motor_White_Background_Final_ORIG.jpg?1499356666)

### **Transistor (PN2222 or MPS2222)**

&nbsp;

[If you'd like to order extra NPN transistors from the Adafruit shop, click here!](https://www.adafruit.com/product/756)

![adafruit_products_Transistors_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/520/medium640/adafruit_products_Transistors_White_Background_ORIG.jpg?1499356722)

 **2.2k Ohm Resistor**

**Colors: Red \> Red \> Red**

&nbsp;

[If you'd like to order extra 2.2k Ohm resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2782)

![adafruit_products_2kohm-andrew.png](https://cdn-learn.adafruit.com/assets/assets/000/043/523/medium640/adafruit_products_2kohm-andrew.png?1499356875)

### **Diode (1N4001)**

&nbsp;

[If you'd like to order more diodes from the Adafruit shop, click here!](https://www.adafruit.com/product/755)

![adafruit_products_Diodes_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/527/medium640/adafruit_products_Diodes_White_Background_ORIG.jpg?1499356984)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/531/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357076)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/687/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695113)

# Experimenter's Guide for Metro

## Wiring 

Warning: 

 **Before** beginning CIRC03, you should note the following things:

- The&nbsp; **flat side** of the _transistor_ should face the Metro.
- &nbsp;The **striped**  **side** &nbsp;of the _diode_ should be facing towards the bottom of the Metro
- The resistor used in this circuit is different from the past two (CIRC01/CIRC02). Make sure the color bands read **red \> red \> red**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/050/090/medium800/adafruit_products_circ03_bb.png?1515790864)

# Steps&nbsp;

1. Connect **GND** &nbsp;and **5V&nbsp;** on the Metro to the **red** and **blue** power rails.
2. Ensure the&nbsp; **flat side** of the transistor faces towards the Metro. Connect the **Emitter** (labled on the diagram above) to the&nbsp; **GND&nbsp;** rail. First connect&nbsp;the **Base** to the 2.2k Ohm resistor, _then_ to the 5V rail. Leave the collector for now.&nbsp;
3. Connect the **striped** &nbsp;lead of the diode to the **5V** rail, and the **un-striped lead** &nbsp;to the **collector** of the t_ransistor_.&nbsp;
4. The **blue** &nbsp;motor wire&nbsp;should be connected to the **striped**  **diode** &nbsp; **lead**. Connect the&nbsp; **red** &nbsp;motor wire to the bottom (un-striped) side of the diode.&nbsp;
5. **Re-read the notes above the diagram to ensure you did not make any errors while connecting components.** It does **not** matter which way you connect the motor's leads for now.

[Click here to download the printable Breadboard Layout Sheet for CIRC03](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-03-sheet-ADAF/CIRC-03-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

Just like we did in the previous circuit, copy and paste the code into a new Arduino sketch. Then [compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC03_MOTOR/CIRC03_MOTOR.ino

# Having Trouble with CIRC03?
### 

If you sourced your own transistor, double check with the data sheet that the pinout is compatible with a PN2222 (many are reversed).

### 

If you sourced your own motor, double check that it will work with 5 volts and that it does not draw too much power.

### 

Sometimes the Metro board will disconnect from the computer. Try un-plugging and then re-plugging it into your USB port.

### 

[Have no fear, we'll help you out! Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

# Controlling Speed
We played with the Metro's&nbsp;ability to control the brightness of an LED earlier. Now, we will use the same feature to control the speed of our motor.

The Metro&nbsp;does this using something called **Pulse Width Modulation** (_ **PWM** _). This relies on the METRO’s ability to operate _really, really fast_. Rather than directly controlling the voltage coming from the pin, **the Metro&nbsp;will switch the pin on and off very quickly**.

In the computer world this is going from 0 to 5 volts many times a second, but in the human world we see it as a voltage. For example: if the Metro&nbsp;is PWM'ing at _50%,_ we see the light dimmed _50%_ because our eyes are not quick enough to see it flashing on and off. The same feature works with transistors. ([if you want&nbsp;a visual explanation of this concept, click here](../../../../adafruit-arduino-lesson-3-rgb-leds/theory-pwm?view=all#theory-pwm))

Don't believe me? **Try it out!**

Copy and paste the code snippet below into the `loop()` function of your code:

```
// motorOnThenOff();
motorOnThenOffWithSpeed();
// motorAcceleration();
```

Then Upload&nbsp;the program.

You can change the speeds by changing variables `onSpeed` and `offSpeed` to any number between _0_ (stop the motor) and _255_ (full power!)

# Accelerating and&nbsp;Decelerating
### Why stop at two speeds? Why not accelerate and decelerate the motor.

To do this simply change the loop() code to read:

```
// motorOnThenOff();
// motorOnThenOffWithSpeed();
motorAcceleration();
```

Then Upload the program and watch as your motor _slowly accelerates up to full speed then slows down again_.

If you would like **to change the speed of acceleration,** &nbsp;change the variable `delayTime` (larger means a longer acceleration time) to a different value.

# Experimenter's Guide for Metro

## CIRC04: A Single Servo

![](https://cdn-learn.adafruit.com/assets/assets/000/042/911/medium800thumb/adafruit_products_IMG_2119.jpg?1498232895)

Spinning a motor is good fun but when it comes to projects where motion control is required they tend to leave us wanting more.

The answer? Hobby servos. They are mass produced, widely available and cost anything from a couple of dollars to hundreds.

Inside is a small gearbox (to make the movement more powerful) and some electronics (to make it easier to control). A standard servo is positionable from 0 to 180 degrees.

![](https://cdn-learn.adafruit.com/assets/assets/000/042/897/medium800/adafruit_products_learn_arduino_servos.png?1498224449)

(Servo Positioning picture from Simon Monk's&nbsp;[Arduino Lesson 14. Servo Motors](../../../../adafruit-arduino-lesson-14-servo-motors/arduino-code-for-sweep?view=all#servo-motors))

Positioning is controlled through a timed pulse, between 1.25 milliseconds (0 degrees) and 1.75 milliseconds (180 degrees) (1.5 milliseconds for 90 degrees). Timing varies between manufacturer. If the pulse is sent every 25-50 milliseconds the servo will run smoothly. One of the great features of the Adafruit Metro is it has a software library which&nbsp;can control servos using a single line of code

# Experimenter's Guide for Metro

## Parts

### **Mini Servo**

&nbsp;

[If you'd like to order an extra mini servo from the Adafruit shop, click here!](https://www.adafruit.com/product/169)

[There are&nbsp;many other servo sizes and types in the Adafruit store, check out our offerings](https://www.adafruit.com/?q=servo&)

&nbsp;

![adafruit_products_Servo_White_BackgroundORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/522/medium640/adafruit_products_Servo_White_BackgroundORIG.jpg?1499356771)

### **3-Pin Header**

&nbsp;

[If you'd like to order extra headers from the Adafruit shop, click here! (these are 40-pins but you can break them apart easily)](https://www.adafruit.com/product/2671)

![adafruit_products_3_Pin_Header_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/524/medium640/adafruit_products_3_Pin_Header_White_Background_ORIG.jpg?1499356822)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/526/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499356889)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/685/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695051)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/042/998/medium800/adafruit_products_circ04-fixed-web.png?1498489026)

The wiring for CIRC04 is much simpler&nbsp;than the last two circuits you made.

1. Connect the **5V**  **pin** on the Metro **to** the **power rail** on the breadboard.
2. Connect the **GND**  **pin** on the Metro **to** the **ground rail** on the breadboard.
3. Connect the **female end** of the servo to the 3-Pin header.
4. Plug the 3-Pin header into any row on the breadboard.
5. Connect the **ground rail** &nbsp;to the **brown servo wire.**
6. Connect the **power rail** to the **red servo wire.&nbsp;**
7. Connect **Metro Pin 9** to the **orange servo wire (signal).&nbsp;**

&nbsp;If you're having trouble, check the "Connection details" below for wiring help.

## Connection details:
![](https://cdn-learn.adafruit.com/assets/assets/000/042/905/medium800/adafruit_products_circ04-closeup.png?1498228721)

## Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC01](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-04-sheet-ADAF/CIRC-04-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

The servo code we are going to use is included in Arduino (just like CIRC001) under: **File \> Examples \> Servo \> Sweep.**

![](https://cdn-learn.adafruit.com/assets/assets/000/042/906/medium800thumb/adafruit_products_sweep_select.jpg?1498229842)

After loading the sketch,&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload)&nbsp;and watch the servo move!

# Sweep

If you're having trouble loading Sweep from Arduino's included examples, the full source code is below to copy/paste into the Arduino editor.&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC04_SERVO/CIRC04_SERVO.ino

# Not Working?&nbsp;
### 

Even with colored wires it is still shockingly easy to plug a servo in backwards. This might be the case.[Check the connection table if you need help.](../../../../experimenters-guide-for-metro/wiring-3#connection-details)

### 

If the servo begins moving then twitches, and there's a flashing light on your METRO board, the power supply you are using is not quite up to the challenge. Using a fresh battery instead of USB should solve this problem.

### 

A mistake we made a time or two was simply forgetting to connect the power (red and brown wires) to +5 volts and ground. Check your connections again for faults.

### 

[We'll help you out! Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

# Potentiometer Control
We have yet to experiment with inputs but if you would like to control your motor, a potentiometer is a great choice and the Arduino editor has a example program for it. We are going to learn about the potentiometer in CIRC08, but we can get our feet wet with this type of input by modifying CIRC04.

### **Parts**

You'll only need to add one part to this circuit: the blue trim potentiometer. You can find it in your box:

 **Breadboard Trim Potentiometer - 10k**

&nbsp;

[If you'd like to buy an extra trimpot from the Adafruit store, click here!](https://www.adafruit.com/product/356)

![adafruit_products_TRIMPOT.png](https://cdn-learn.adafruit.com/assets/assets/000/043/000/medium640/adafruit_products_TRIMPOT.png?1498489982)

## Wiring the Potentiometer
Wire it such that&nbsp;the two outermost pins go to the power and ground rail. The **inner pin** should go to the Metro's **analog pin 0.** Note that **we are using** an **analog pin instead of a digital pin** &nbsp;this time, they are located on the **left side** of the Metro **instead of the right side.**

## Metro&nbsp;Breadboard Diagram

Be careful - the **Trim Potentiometer connects to the 3.3v** input on the Metro, **not the 5V rail.**

![](https://cdn-learn.adafruit.com/assets/assets/000/044/710/medium800/adafruit_products_CIRC04-knob_bb.png?1501696551)

## Loading the example code

The code to load potentiometer control onto your revised CIRC04 is provided by Arduino under

**File \> Servo \> Knob.&nbsp;** After loading the sketch,&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload). Move the potentiometer left and right, you should see the servo move with it.

# Self-Timing

While it is easy to control a servo using the Metro's&nbsp;included library, sometimes it is fun to figure out how to program something yourself. Try it! Remember that we're controlling the pulse directly so you could use this method to control servos on any of the Metro's 20 available pins (you need to highly optimize this code before doing that).

# Other fun servo ideas

Servos can be used to do all sorts of things. [The Adafruit Learning System is a great resource to find a fun project with servos.](../../../../search?q=servo&)

**Here are a few of our favorites:**

[Animatronic Servo Tail: Who hasn't imagined having a tail? With a single servo and a little math, we can make this real!](What%20kid%20hasn%E2%80%99t%20imagined%20what%20it%E2%80%99s%20like%20having%20a%20tail?%20Let%E2%80%99s%20make%20it%20real!)

![adafruit_products_Introduction___Really_Simple_Animatronic_Tail___Adafruit_Learning_System.png](https://cdn-learn.adafruit.com/assets/assets/000/043/006/medium640/adafruit_products_Introduction___Really_Simple_Animatronic_Tail___Adafruit_Learning_System.png?1498490529)

[Have you ever wanted to build a robot, but don't know where to start? Or... are you looking for a project that you can cut-your-teeth on?](../../../../3d-printed-animatronic-robot-head/mission-control?view=all)  
  
[This servo-controlled animatronic robot head uses two servos for movement, two speakers for eyes and an LED mouth for a friendly remote-controlled robot.](../../../../3d-printed-animatronic-robot-head/mission-control?view=all)

![adafruit_products_IMG_0268.jpeg](https://cdn-learn.adafruit.com/assets/assets/000/044/714/medium640/adafruit_products_IMG_0268.jpeg?1501698089)

[Our&nbsp;fully-assembled **pan-tilt kit** is the perfect way to give your project full range&nbsp;motion with two micro servos. The pan-tilt can rotate roughly 180° from side-to-side and can tilt up&downwards around 150°. &nbsp;It also comes fully assembled with two Micro Servos (SG-90 or SG-92 type) included and a 38mm x 36mm space to mount a camera or sensor or whatever you like.](https://www.adafruit.com/product/1967)

&nbsp;

![adafruit_products_1967-01.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/715/medium640/adafruit_products_1967-01.jpg?1501698276)

[Sandblaster is a variation on Blue Buggy&nbsp;remixing the original Cox International gas-powered sand buggy&nbsp;- scaled-down, converted to electric, and 3D printable!](../../../../sandblaster-3d-printed-sand-buggy#read-me-first)

[You can use it to explore obstacle avoidance, autonomous navigation, driverless vehicle design, or assisted Remote Control. Or… build in the morning and race in the afternoon!](../../../../sandblaster-3d-printed-sand-buggy#read-me-first)

[Crazy fun for your local hackerspace / makerspace or family night!](../../../../sandblaster-3d-printed-sand-buggy#read-me-first)

![adafruit_products_sandblaster.png](https://cdn-learn.adafruit.com/assets/assets/000/044/716/medium640/adafruit_products_sandblaster.png?1501698369)

# Experimenter's Guide for Metro

## CIRC05: 8 More LEDs 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/051/medium800thumb/adafruit_products_IMG_2213.jpg?1498509839)

Time to start playing with chips, or integrated circuits (ICs) as they like to be called. The external packaging of a chip can be very deceptive. For example, the chip on the Metro&nbsp;board (a microcontroller) and the one we will use in this circuit (a shift register) look very similar but are in fact rather different. The price of the Atmel 328p chip on the Metro&nbsp;board is a few dollars while the 74HC595 is a couple dozen cents. It's a good introductory chip, and once you're comfortable playing around with it and its [datasheet](http://adafru.it/METROX74HC595),&nbsp;the world of chips will be your oyster.

The shift register (also called a serial to parallel converter), will give you an additional 8 outputs (to control LEDs and the like) using only three Metro&nbsp;pins. They can also be linked together to give you a nearly unlimited number of outputs using the same four pins. To use it you “clock in” the data and then lock it in (latch it).

![](https://cdn-learn.adafruit.com/assets/assets/000/044/843/medium800thumb/adafruit_products_rpuQXNoLIJ-latch-clock-data.jpg?1501861465)

To do this, you set the data pin to either _HIGH_ or _LOW_, pulse the clock, then set the data pin again and pulse the clock repeating until you have shifted out 8 bits of data. Then you pulse the latch and the 8 bits are transferred to the shift registers pins. It sounds complicated but is _really_ simple once you get the hang of it. [(click here for a more in depth look at how a shift register works)](https://cdn-shop.adafruit.com/datasheets/sn74hc595.pdf)

# Experimenter's Guide for Metro

## Parts

### **5mm Red LED**

**Qty: x8&nbsp;**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/563/medium640/adafruit_products_redled.png?1499359502)

### **74HC595 Shift Register**

&nbsp;

[If you'd like to order more shift registers from the Adafruit shop, click here!](https://www.adafruit.com/product/450)

![adafruit_products_Shift_Register_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/521/medium640/adafruit_products_Shift_Register_White_Background_ORIG.jpg?1499356752)

### **560 Ohm Resistor**

**Qty: x8**

**Colors: Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/525/medium640/adafruit_products_560ohm.png?1499356858)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/530/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357072)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/686/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695055)

# Experimenter's Guide for Metro

## Wiring

CIRC05 is considerably more complex to wire than other circuits. However, it isn't impossible and just takes some time and patience.

We&nbsp;broke down this into three larger steps, follow all of them in order and you'll be rewarded with a fun LED show!

## Chip&nbsp;Orientation
![](https://cdn-learn.adafruit.com/assets/assets/000/043/036/medium800/adafruit_products_circ05-editing_fzz_-_Fritzing_-__Breadboard_View_.png?1498506354)

The shift register should be placed such that the **half moon** circle on it **should face the top** of the breadboard.&nbsp;

## Step 1: Connect Power/GND
![](https://cdn-learn.adafruit.com/assets/assets/000/043/037/medium800/adafruit_products_circ05-editing_fzz_-_Fritzing_-__Breadboard_View_f.png?1498506851)

It's easier to see the diagram without the bulk of the wires in the way. Let's first start by connecting&nbsp;all power and ground points on the circuit. _Note_ that we are expanding the power and ground rails by connecting the left rails to the right rails. This is for ease of access and to keep everything tidy.&nbsp;

We are also going to plug in our resistors. Resistors plug into the _cathode_ (shorter end) of the LED, and then into ground.

## Step 2: Connect Data Pins to the Metro
![](https://cdn-learn.adafruit.com/assets/assets/000/043/038/medium800/adafruit_products_circ05-editing_fzz_-_Fritzing_-__Breadboard_View_.png?1498506961)

Pins 2, 3, and 4 on the metro correspond to the **Data (pin 14)**, **Latch (pin 12)**, and **Clock (pin 11)** on the shift register.&nbsp;

## Step 3: Connect the LEDs
Next up is connecting the LEDs to the shift register. We have a handy pinout below to help you, along with the final diagram.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/034/medium800/adafruit_products_circ05_bb-1.png?1498506124)

Once you complete the LED wiring, _double check_ all your wiring against the final diagram. After that, move onto the Code section.&nbsp;

## Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC05](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-05-sheet-ADAF/CIRC-05-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

Copy/Paste the code below into an empty&nbsp;arduino sketch. Then&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC05_SHIFT_REGISTER/CIRC05_SHIFT_REGISTER.ino

# Not Working?
### 

The chip is inserted backwards. Turn off the power to your Metro, then rotate the chip such that the half-moon cutout on the chip faces the top of the breadboard.

### 

Sorry to sound like a broken record, but make absolutely sure your wiring is correct. If you're unsure: pull everything out and start fresh.&nbsp;

### 

This circuit is both simple and complex at the same time, let us know your frustration with it so we can address it in future editions of the kit.&nbsp;

# Experimenter's Guide for Metro

## Make It Better

# Doing it the Hard Way

The Metro makes complex actions very simple. A perfect example of this is shifting and manipulating data. However, one of the nice things about the Metro is that you can adjust the difficulty of what you are trying to achieve.&nbsp;

In the `loop()`, switch `updateLEDs(i);` to `updateLEDsLong(i);`

### 

You shouldn't have! There was no difference in the actions the code took. The code was changed to communicate with the LEDs one bit at a time by using the serial peripheral interface.

# Controlling Individual LEDs

Just like CIRC02, you&nbsp;can individually control the LEDs on your breadboard. The current state of the eight LEDs are stored in one&nbsp;8-bit value ([for more info on this subject, we have a great Collin's Lab video on Binary and Hex](../../../../collins-lab-binary-and-hex/video)). The code provided already takes care of the [bit&nbsp;manipulations](http://playground.arduino.cc/Code/BitMath).&nbsp;

To control individual LEDs, we replace the code within `loop()` with the following:

```
    int delayTime = 100; // # of ms to delay btween LED updates
for(int i=0; i&lt;8; i++){
  changeLED(i, ON);
  delay(delayTime);
}
for(int i=0;i&lt;8;i++){
  changeLED(i,OFF);
  delay(delayTime);
}
  
```

Then, compile and upload this to your Metro. The code will cause the LEDs to light up one after another and then turn off. Read through the code and the links for a better understanding of how it works.

# More Animations

If you did CIRC02, there was a part in the Make It Better section about [adding additional animations](../../../../experimenters-guide-for-metro/make-it-better-4#extra-animations). The format of changing the LEDs in this circuit will be similar.&nbsp;

CIRC02 let you&nbsp;change the LEDs using

&nbsp; &nbsp; &nbsp;`digitalWrite(LED, state)`

CIRC05 uses the changeLED() routine to perform the same operation:

&nbsp; &nbsp; &nbsp;`changeLED(LED, state)`

You can repurpose the code from CIRC02's additional animations by first copying the animation code from CIRC02 into this sketch and then changing all the `digitalWrite()` routines to `changeLED()`. You'll also need to change a few other things, just follow the compiler errors and it works itself out.

# Experimenter's Guide for Metro

## CIRC06: Music with Piezo

![](https://cdn-learn.adafruit.com/assets/assets/000/043/057/medium800/adafruit_products_IMG_2218.jpg?1498511728)

To this point we have controlled light, motion, and electrons. Let's tackle **sound** next. But sound is an _analog_ phenomena, how will our _digital_&nbsp;Metro cope? We will once again rely on its incredible speed which will let it mimic analog behavior.

We are going to attach a piezo element to one of the Metro's digital pins. A piezo element makes a clicking sound each time it is pulsed with current. If we pulse it at the right frequency (for example 440 times a second to make the note _middle A_), these clicks will run together to produce notes.

Let's get to experimenting and make&nbsp;your Metro play "Twinkle Twinkle Little Star"!

# Experimenter's Guide for Metro

## Parts

### **Piezo&nbsp;**** Buzzer**

&nbsp;

[If you'd like to order another Pizeo Buzzer from the Adafruit shop, click here!](https://www.adafruit.com/product/160)

![adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/528/medium640/adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg?1499356968)

### **Breadboard Wiring Bundle**

&nbsp;

[&nbsp;If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/532/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357087)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/688/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695117)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/043/056/medium800/adafruit_products_circ06_bb-1.png?1498510627)

Wiring this circuit is much easier than CIRC05:

1. Connect your GND and 5V rails.
2. Connect one side of the piezo to **GND**
3. Connect the other side of the piezo to the Metro's **Digital Pin 9**

## Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC06](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-06-sheet-ADAF/CIRC-06-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

Copy/Paste the code below into an empty&nbsp;arduino sketch. Then&nbsp;[compile and upload it to your Metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC06_PIEZO/CIRC06_PIEZO.ino

# Not Working?
### 

Given the size and shape of the piezo element it is easy to miss the right holes on the breadboard. Try double checking its placement.

### 

Just pull up the piezo element whilst you think, upload your program then plug it back in.

### 

The code is written so you can easily add your own songs, check out the Make It Better section for more info on modifying the code.

# Experimenter's Guide for Metro

## Make It Better

# Playing with Speed

The timing for each note is calculated based on variables, as such we can tweak the sound of each note or the timing. To change the speed of the melody, we only need to change one line:

&nbsp; &nbsp; &nbsp;`int tempo = 300;` **--\>** `int tempo = (new #); `

Change `new #` to a larger number to slow the melody down, or a smaller number to speed it up!

# Tuning the Notes

If you are worried about the notes being a little bit out of tune, this can be fixed as well. The notes have been calculated based on a formula from the comment block at the top of the program. But to tune individual notes just adjust their values in the tones[] array up or down until they sound right. Each note is matched by its name in the names[] array.

For example: If we want a _c (c=1915)_ to be a higher pitch, we need to find it's initial&nbsp;value:

&nbsp; &nbsp; &nbsp;`char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };`

&nbsp; &nbsp; &nbsp;`int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956 };`

and then change&nbsp;the number within tones[] to something larger, let's go with **1975** :

&nbsp; &nbsp; &nbsp;`char names[] = { 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C' };`

&nbsp; &nbsp; &nbsp;`int tones[] = { 1975, 1700, 1519, 1432, 1275, 1136, 1014, 956 };`

# Composing your own Melodies:

While the program is pre-set to play 'Twinkle Twinkle Little Star', the program can easily be changed to play something&nbsp;else.&nbsp;

A song takes the format of one integer (`int length`) and two arrays (`char notes[]` and `int beats[]`).&nbsp;

`int length` - defines the number of notes

`char notes[]` - defines each note

`int beat[]` - defines how long each note will be played for

### **Twinkle Twinkle Little Star**
```
int length = 15;
char notes[] = {"ccggaagffeeddc"};
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
```

### **Happy Birthday (First line)**
```
int length = 13;
char notes[] = {"ccdcfeccdcgf"};
int beats[] = {1,1,1,1,1,2,1,1,1,1,1,2,4};
```

To become familiar with how code&nbsp;works, it's always a good idea to look at examples. Above&nbsp;are two songs. Run them, and then modify them to compose your own melody.

# Experimenter's Guide for Metro

## CIRC07: Button Pressing

![](https://cdn-learn.adafruit.com/assets/assets/000/043/089/medium800thumb/adafruit_products_IMG_2266_%281%29.jpg?1498581323)

Up to this point we have focused entirely on outputs. It's time to get our Metro&nbsp;to listen, watch and feel. We'll start with a simple pushbutton.

Wiring up the pushbutton is simple. There is one component, the pull up resistor, that might seem out of place. This is included because a Metro&nbsp;doesn't sense the same way we do (i.e: _button pressed_, _button unpressed_). Instead it looks at the voltage on the pin and decides whether it is _HIGH_ or _LOW_. The button is set up to pull the Metro's&nbsp;pin _LOW_ when it is pressed, however, when the button is unpressed the voltage of the pin will float (causing occasional errors). To get the Metro&nbsp;to reliably read the pin as HIGH when the button is unpressed, we add a&nbsp;pull up resistor into the circuit.&nbsp;

# Experimenter's Guide for Metro

## Parts

### **Pushbutton**

### **Qty: x2**

&nbsp;

[If you'd like to order more pushbuttons from the Adafruit shop, click here!](https://www.adafruit.com/product/367)

![adafruit_products_12mm_button_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/000/medium640/adafruit_products_12mm_button_iso_White_Background_ORIG.jpg?1502222047)

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/597/medium640/adafruit_products_redled.png?1499360867)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

**Qty: x2**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

### &nbsp;
![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/529/medium640/adafruit_products_10kohm.png?1499357023)

### **560 Ohm Resistor**

**Colors: Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/544/medium640/adafruit_products_560ohm.png?1499357640)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/533/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357094)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/689/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695157)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/050/275/medium800/adafruit_products_circ07_bb.png?1516288534)

The wiring for CIRC07 is simple - the wires going to the digital pins on the Metro&nbsp;sit between the switch terminal and the resistor.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/842/medium800/adafruit_products_IMG_3505.jpg?1501860335)

 **Pro-Tip:** When pushing the pushbutton into the breadboard, be careful not to bend the legs outwards too much or else it won't make contact with the breadboard. Seat&nbsp;it in the gap in the breadboard.

## Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC07](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-07-sheet-ADAF/CIRC-07-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

This code is provided for you in the Arduino editor under: **File \> Examples \> 2. Digital \> Button.&nbsp;** Load it into the Arduino editor, then&nbsp;[compile and upload it to your Metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

## **Code:**
https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC07_BUTTON/CIRC07_BUTTON.ino

# Not Working?
### 

The pushbutton is square and because of this it is easy to put it in the wrong way. Give it a 90 degree twist and see if it starts working.

### 

A bit of a silly mistake we constantly made, when you switch from simple on off to fading remember to move the LED wire from pin 13 to pin 9.

### 

No worries these circuits are all super stripped down to make playing with the components easy, but once you throw them together the sky is the limit.

# Experimenter's Guide for Metro

## Make It Better

## Light Switch
![](https://cdn-learn.adafruit.com/assets/assets/000/043/087/medium800thumb/adafruit_products_circ08-switch.jpg?1498581121)

If you feel the initial example is a bit underwhelming ("I don't need a metro to do _this_!"), let's use the metro to do something a bit more complicated. We are going to make a light-switch. One of the buttons on your breadboard is going to turn on the light, and the other is going to turn it off!

This is super simple, we're just going to change a few lines of code:

```python
int ledPin = 13; // choose the pin for the LED
int buttonPin1 = 3; // button 1
int buttonPin2 = 2; // button 2

void setup() {
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(buttonPin1, INPUT); // make button 1 an input
  pinMode(buttonPin2, INPUT); // make button 2 an input
}

void loop() {
  if (digitalRead(buttonPin1) == LOW) {
    digitalWrite(ledPin, LOW); // turn LED OFF
  }
  else if (digitalRead(buttonPin2) == LOW) {
    digitalWrite(ledPin, HIGH); // turn LED ON
  }
}
```

Copy and paste the code into a blank sketch, upload it to the board, and start toggling the LED on and off.

## Fading
![](https://cdn-learn.adafruit.com/assets/assets/000/043/086/medium800thumb/adafruit_products_circ07onoff.jpg?1498581004)

Let's use the buttons to control an analog signal. To do this, you will need to change the wire connecting the LED from **Pi**** n 13 **to** P ****in 9**.

In the code, change:

&nbsp; `int ledPin = 13;` **-\>** `int ledPin = 9;`

Next, change the` loop()` code to read:

```
int value = 0;
void loop() { 
  if(digitalRead(buttonPin1) == LOW){
    value--;
  }
  else if(digitalRead(buttonPin2) == LOW){
    value++;
  }
  value = constrain(value, 0, 255);
  analogWrite(ledPin, value);
  delay(10);
}
```

## Changing Fade Speed

If you would like the LED to fade faster or slower, there is only one line of code that needs to be changed:

&nbsp; &nbsp; &nbsp;`delay(10);` **-\>** `delay(new #);`

To fade _faster_: make the number _smaller_.&nbsp;

To fade _slower_: make the number _larger._

# Experimenter's Guide for Metro

## CIRC08: Twisting

![](https://cdn-learn.adafruit.com/assets/assets/000/043/082/medium800thumb/adafruit_products_circ08.jpg?1498580892)

Along with the digital pins, the Metro also has 6 pins which can be used for analog input.

![](https://cdn-learn.adafruit.com/assets/assets/000/043/067/medium800/adafruit_products_analogdigitalconverter.png?1498575932)

These inputs take a **voltage** (from 0 to 5 volts) **and convert it to a digital number** between 0 (0 volts) and 1023 (5 volts) (10 bits of resolution).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/068/medium800/adafruit_products_TRIMPOTtut.png?1498576154)

A very useful device that exploits these inputs is a potentiometer (also called a variable resistor). When it is connected with 5 volts across its outer pins the middle pin will read some value between 0 and 5 volts dependent on the angle to which it is turned (ie. 2.5 volts in the middle). We can then use the returned values as a variable in our program.

# Experimenter's Guide for Metro

## Parts

### **Breadboard Trim Potentiometer - 10k**

&nbsp;

[If you'd like to buy an extra trimpot from the Adafruit store, click here!](https://www.adafruit.com/product/356)

![adafruit_products_Potentiometer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/534/medium640/adafruit_products_Potentiometer_White_Background_ORIG.jpg?1499357223)

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/603/medium640/adafruit_products_redled.png?1499361753)

### **560 Ohm Resistor**

**Colors: Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/539/medium640/adafruit_products_560ohm.png?1499357368)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/541/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357435)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/690/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695181)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/050/272/medium800/adafruit_products_circ08_bb.png?1516287647)

CIRC08 is quick&nbsp;to wire up:

1. Longer end of the LED connects to a 560 ohm resistor, which connects to ground.
2. The shorter (cathode) end connects to the metro's&nbsp; **digital Pin 13**
3. The middle pin of the potentiometer connects to&nbsp; **Analog Pin 0**
4. Outer pins of the potentiometer connect to the&nbsp; **5V&nbsp;** and **GND** rails.&nbsp;

## Printable Breadboard Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC08](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-08-sheet-ADAF/CIRC-08-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Wiring for Metro Express

If you are using the [Adafruit Metro Express](https://www.adafruit.com/product/3505), the wiring below should be used. [If you're not sure what board you have, check this page.](../../../../experimenters-guide-for-metro/what-board-do-i-have)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/335/medium800/adafruit_products_circ08_bb-EXPRESS.png?1498855704)

# Experimenter's Guide for Metro

## Code

Arduino includes this example, find it under:&nbsp; **File \> Examples \> 3.Analog \> Analog Input**

Then [compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;Tweak the potentiometer to change the LEDs brightness.&nbsp;

_If you are having trouble finding or loading the example, the code is below:_

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC08_POTENTIOMETER/CIRC08_POTENTIOMETER.ino

## Not Working?
### 

This is most likely due to a slightly dodgy connection with the potentiometer's pins. This can usually be fixed by taping the potentiometer down.

### 

Make sure you haven't accidentally connected the potentiometer's wiper to digital pin 0 rather than analog pin 0. (the row of pins beneath the power pins)

### 

You can try operating the circuit upside down. Sometimes this helps.

# Experimenter's Guide for Metro

## Using the Arduino Serial Plotter

We're going to start plotting...values! Arduino comes with a cool tool called the Serial Plotter. It can give you visualizations of variables in real-time. This is super useful for visualizing data, troubleshooting your code, and visualizing your variables as&nbsp;waveforms.&nbsp;

We are going to first need to modify the code for CIRC08. Copy and paste the code below into the Arduino Editor. Then compile and upload.

```
/*
  Analog Input, but with Serial Plotter!
 Demonstrates analog input by reading an analog sensor on analog pin 0 and
 turning on and off a light emitting diode(LED)  connected to digital pin 13.
 The amount of time the LED will be on and off depends on
 the value obtained by analogRead().

 The circuit:
 * Potentiometer attached to analog input 0
 * center pin of the potentiometer to the analog pin
 * one side pin (either one) to ground
 * the other side pin to +5V
 * LED anode (long leg) attached to digital output 13
 * LED cathode (short leg) attached to ground

 * Note: because most Arduinos have a built-in LED attached
 to pin 13 on the board, the LED is optional.


 Created by David Cuartielles
 modified 30 Aug 2011
 By Tom Igoe

 This example code is in the public domain.

 http://www.arduino.cc/en/Tutorial/AnalogInput

 */

int sensorPin = A0;    // select the input pin for the potentiometer
int ledPin = 13;      // select the pin for the LED
int sensorValue = 0;  // variable to store the value coming from the sensor

void setup() {
  // declare the ledPin as an OUTPUT:
  pinMode(ledPin, OUTPUT);
  // begin the serial monitor @ 9600 baud
  Serial.begin(9600);
}

void loop() {
  // read the value from the sensor:
  sensorValue = analogRead(sensorPin);

  Serial.println(sensorValue);
  Serial.print(" ");
 
  delay(20);
}
```

When you call `Serial.println(value)`, the Serial Plotter will put that variable on the plot. The Y-Axis of the plot auto-resizes.&nbsp;

**If you want to**  **plot** &nbsp; **multiple variables,&nbsp;** you'll need a `Serial.println(value)` call for each of the variables, separated by a `Serial.print(" ")` or `Serial.print("\t")`:

`Serial.print(variable1); `

`Serial.print(" "); `

`Serial.println(variable2);`

Let's try it out with the new code above. Compile and upload the program above, then navigate to **Tools \> Serial Plotter.&nbsp;** The code uses a baud rate of 9600, make sure it's set in the serial monitor as 9600 too.

You should see something like this when you twist the trim potentiometer around:

![](https://cdn-learn.adafruit.com/assets/assets/000/044/736/medium800thumb/adafruit_products_out.jpg?1501707166)

# Experimenter's Guide for Metro

## Make It Better

## Threshold Switching
Sometimes you will want to switch an output when a value exceeds a certain threshold.&nbsp;

To do this with a potentiometer, change the `loop()` code to:

```
    void loop() {
  int threshold = 512;
  if(analogRead(sensorPin) &gt; threshold) { 
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}
  
```

This will cause the LED to turn on when the value is above 512 (halfway on the potentiometer dial), you can adjust the sensitivity by changing the threshold value.&nbsp;

## Fading
Let's control the brightness of an LED directly from the potentiometer. To do this we need to first change the pin the LED is connected to.&nbsp;

Move the wire from&nbsp; **Pin 13** to&nbsp; **Pin 9** and change the following line in the code:

&nbsp; &nbsp; &nbsp;`int ledPin = 13;` **-\>** `int ledPin = 9;`

Then, change the loop code to:

```auto
void loop() {
  int value = analogRead(sensorPin) / 4;
  analogWrite(ledPin, value);
}
```

Upload the code and watch as your LED fades in relation to your potentiometer spinning. (_Note_: the reason we divide the value by 4 is the analogRead() function returns a value from 0 to 1023 (10 bits), and analogWrite() takes a value from 0 to 255 (8 bits))

## Controlling the servo
![](https://cdn-learn.adafruit.com/assets/assets/000/043/079/medium800thumb/adafruit_products_servo.jpg?1498580793)

This is a really neat example and brings a couple of circuits changing the threshold value. Wire up the servo like you did in CIRC-04:

![](https://cdn-learn.adafruit.com/assets/assets/000/043/076/medium800/adafruit_products_circ08-servo_bb.png?1498580188)

Then, open the example program Knob ( **File \> Examples \> Servo \> Knob** ). Upload to your METRO and then watch as the servo shaft turns as you turn the potentiometer.&nbsp;

# Experimenter's Guide for Metro

## CIRC09: Light

![](https://cdn-learn.adafruit.com/assets/assets/000/043/122/medium800thumb/adafruit_products_IMG_2278.jpg?1498596348)

Whilst getting input from a potentiometer can be useful for human controlled experiments, what do we use when we want an environmentally controlled experiment?

We use exactly the same principles but instead of a potentiometer (twist based resistance) we use a photo resistor (light based resistance). The Metro&nbsp;cannot directly sense resistance (it senses voltage) so we set up a [voltage divider](http://adafru.it/METROXVODI). The exact voltage at the sensing pin i_s calculable_, but for our purposes (just sensing relative light) we can experiment with the values and see what works for us. _A low value will occur when the sensor is well lit_ while a high value will occur when it is in darkness.

# Experimenter's Guide for Metro

## Parts

### **5mm Red LED** &nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/045/356/medium640/adafruit_products_redled.png?1502910976)

### **Photo Sensor**

&nbsp;

[If you'd like to order another photoresistor from the Adafruit shop, click here!](https://www.adafruit.com/product/2831)

![adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/001/medium640/adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg?1502222100)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

### &nbsp;
![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/628/medium640/adafruit_products_10kohm.png?1499440796)

### **560 Ohm Resistor**

**Colors:** &nbsp; **Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/633/medium640/adafruit_products_560ohm.png?1499440964)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/638/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499441145)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/691/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695198)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/050/273/medium800/adafruit_products_circ09_bb.png?1516287823)

1. Wire up the LED: anode to&nbsp; **pin 9**. Cathode to a 560 ohm resistor and then to ground.
2. Wire up the Photoresistor. Connect one end of the 10k ohm resistor to the power rail. Connect the other end of it to A0 and one end of the the photoresistor. The other end of the resistor should be grounded.&nbsp;

## Printable Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC09](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-09-sheet-ADAF/CIRC-09-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Wiring for Metro Express

If you are using the [Adafruit Metro Express](https://www.adafruit.com/product/3505), the wiring below should be used. [If you're not sure what board you have, check this page.](../../../../experimenters-guide-for-metro/what-board-do-i-have)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/433/medium800/adafruit_products_circ09_bb-express.png?1499098500)

# Experimenter's Guide for Metro

## Code

Copy and paste the code below into a new Arduino sketch. Then,&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC09_LIGHT/CIRC09_LIGHT.ino

## Not Working?
Info: 

### 

This is a mistake we continue to make time and time again, if only they could make an LED that worked both ways. Pull it up and give it a twist.

### 

Given that the spacing of the wires on the photo-resistor is not standard, it is easy to misplace it. Double check its in the right place.

### 

You may be in a room which is either too bright or dark. Try turning the lights on or off to see if this helps. Or if you have a flashlight near by give that a try.

# Experimenter's Guide for Metro

## Make It Better

## Reverse the Response
Perhaps you would like the opposite response. Don't worry we can easily reverse this response just change:

`analogWrite(ledPin, lightLevel);` -\> `analogWrite(ledPin, 255 - lightLevel);`

Upload your modified sketch and watch the response change.

## Night Light
Rather than controlling the brightness of the LED in response to light, lets instead turn it on or off based on a threshold value. Change the loop() code with:

```
void loop(){ 
  int threshold = 300; 
  if(analogRead(lightPin) &gt; threshold){ 
    digitalWrite(ledPin, HIGH); 
  }
  else{ 
    digitalWrite(ledPin, LOW); 
  } 
}
```

## Light Controlled Servo
Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/044/742/medium800/adafruit_products_circ09-servo_bb.png?1501710634)

Lets use our newly found light sensing skills to control a servo (and at the same time engage in a little bit of Arduino code hacking). Wire up a servo connected to pin 9 (like in CIRC-04). Then open the Knob example program (the same one we used in CIRC-08) **File \> Examples \> Library-Servo \> Knob**. Upload the code to your board and watch as it works unmodified.

## Using the full range of your servo
You'll notice that the servo will only operate over a limited portion of its range. This is because with the voltage dividing circuit we use the voltage on analog pin 0 will not range from 0 to 5 volts but instead between two lesser values (these values will change based on your setup). To fix this play with the line: `val = map(val, 0, 1023, 0, 179);`&nbsp; ([For hints on what to do, click here](http://arduino.cc/en/Reference/Map))

## Learn More!
[If you'd like to understand the magic behind the photo sensor, we have a learn guide explaining more about this subject](../../../../photocells)

# Experimenter's Guide for Metro

## CIRC10: Temperature

![](https://cdn-learn.adafruit.com/assets/assets/000/043/124/medium800thumb/adafruit_products_IMG_2282.jpg?1498596453)

What's the next phenomenon&nbsp;we will measure with our Metro? **Temperature**.

To do this we'll use a rather complicated IC (integrated circuit) hidden in a package identical to our P2N2222AG transistors, the **TMP36**. It has three pin's, ground, signal and power..and is easy to use.

It outputs 10 millivolts per degree centigrade on the signal pin (to allow measuring temperatures below freezing there is a 500 mV offset eg. 25 degrees C = 750 mV, 0 degrees C = 500mV). To convert this from the digital value to degrees, we will use some of the Arduino's math abilities. Then to display it we'll use one of the IDE's rather powerful features, the debug window. We'll output the value over a serial connection to display on the screen. Let's get to it.  
  
One extra note, this circuit uses the Arduino IDE's serial monitor. To open this, first upload the program then click the button which looks like a square with an antennae.

# Experimenter's Guide for Metro

## Parts

Warning: 

## [Am I using a NPN **Transistor** or a TMP36 **Temperature Sensor?**](../../../../experimenters-guide-for-metro/electronics-primer-1#identifying-tmp36-and-npn)
### **Analog Temperature Sensor**

&nbsp;

[If you'd like an extra temperature sensor, you can grab one from the Adafruit shop, click here](https://www.adafruit.com/product/165)

![adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/536/medium640/adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg?1499357232)

### **Breadboard Wiring Bundle**

&nbsp;

[&nbsp;If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/537/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499357293)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/692/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695274)

# Experimenter's Guide for Metro

## Wiring

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/109/medium800/adafruit_products_temperature_tmp36pinout.gif?1498590312)

### **Wire it up**
![](https://cdn-learn.adafruit.com/assets/assets/000/050/274/medium800/adafruit_products_circ10_bb.png?1516287983)

## Printable Breadboard Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC10](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-10-sheet-ADAF/CIRC-10-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Wiring for Metro Express

If you are using the [Adafruit Metro Express](https://www.adafruit.com/product/3505), the wiring below should be used. [If you're not sure what board you have, check this page.](../../../../experimenters-guide-for-metro/what-board-do-i-have)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/431/medium800/adafruit_products_circ10_bb-express.png?1499096411)

# Experimenter's Guide for Metro

## Code

Copy/Paste the code below.&nbsp;

Then [compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC10_TEMPERATURE/CIRC10_TEMPERATURE.ino

## Using the Arduino Serial Monitor
![](https://cdn-learn.adafruit.com/assets/assets/000/043/108/medium800thumb/adafruit_products_sermon.jpg?1498589371)

Click on the **magnifying glass icon** on the toolbar of&nbsp;the Arduino IDE. You should see the serial monitor pop up and start printing out numbers.&nbsp;

## Not Working?
### 

This program has no outward indication it is working. To see the results you must open the Arduino IDE's serial monitor.

### 

This happens because the serial monitor is receiving data at a different speed than expected. To fix this, click the pull-down box that reads "\*\*\* baud" and change it to "9600 baud".

### 

Try pinching the sensor with your fingers to heat it up or pressing a bag of ice against it to cool it down.

# Experimenter's Guide for Metro

## Make It Better

## Outputting Voltage
This is a simple matter of changing _one_ line. Our sensor outputs 10mv per degree centigrade so to get voltage we simply display the result of `getVoltage()`. Delete the line:

&nbsp; &nbsp; &nbsp;`temperature = (temperature - .5) * 100; `

## Outputting degrees Fahrenheit
Again this is a simple change requiring only math. to go degrees C _-\>_ degrees F we use the formula:  
_&nbsp;&nbsp;&nbsp;&nbsp;( F = C \* 1.8) + 32 )_

Add the line:  
&nbsp;&nbsp;&nbsp;&nbsp;`temperature = (((temperature - .5) * 100)*1.8) + 32;` before `Serial.println(temperature); `

## More informative output
Lets add a message to the serial output to make what is appearing in the Serial Monitor more informative.

To do this, change this line:   
&nbsp; &nbsp; &nbsp;`Serial.println(temperature);`

to:

&nbsp; `Serial.print(temperature);`

Then, we add another line with informative text about the temperature on a new line:  
&nbsp; `Serial.println(" degrees centigrade");`

The change to the first line means when we next output it will appear on the same line.

## Changing the serial speed
If you ever wish to output a lot of data over the serial line time is of the essence. We are currently transmitting at 9600 baud but much faster speeds are possible.

To change this change the line:

&nbsp; `Serial.begin(9600);`

to:

&nbsp; `Serial.begin(115200);`

Upload the sketch turn on the serial monitor, **then change the speed from 9600 baud to 115200 baud in the pull down menu.** You are now transmitting data _12 times faster._

# Experimenter's Guide for Metro

## CIRC10.5: Temperature Alarm

 **CIRC10&nbsp;** only works when you are connected to the serial monitor. Let's free your board from wires and make a **free-standing circuit!**

This is a _bonus_ circuit!! We are going to make a free-standing alarm to alert us if it's too hot/cold.&nbsp;

### Running the Metro Express off a 9V Battery
One of the included parts in the Experimenter's Kit is the [9V battery clip](https://www.adafruit.com/product/80).

If you have a 9V battery, snap it into the clip and plug the clip into the barel-jack of the Metro:

![](https://cdn-learn.adafruit.com/assets/assets/000/043/480/medium800/adafruit_products_circ10.5-BARREL_bb.png?1499273300)

Our temperature sensor is now running off of a 9V battery. This is awesome, but we still have no way to be alerted of temperatures getting too hot/cold.

## Add a Piezo!
The Piezo element was first introduced in CIRC06. You send it digital output and it buzzes. Next up is buzzing the piezo when it exceeds a certain temperature. The Piezo can be used as an alarm with minimal modifications to the circuit:

![](https://cdn-learn.adafruit.com/assets/assets/000/043/481/medium800/adafruit_products_circ10.5_bb.png?1499273917)

Code for the temperature alarm is below (copy and paste it into a blank Arduino sketch), compile and upload it to your Metro:

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC10_5_TEMP_ALARM/CIRC10_5_TEMP_ALARM.ino

### Changing the&nbsp;variables

We predefined freezing and boiling variables in Celsius, but if you want to use Fahrenheit (or [kelvin](https://en.wikipedia.org/wiki/Kelvin)&nbsp;just change the variables below to other values:

&nbsp; &nbsp; &nbsp;`float freezeTemp = 0;`

&nbsp; &nbsp; &nbsp;`float boilTemp = 26;`

# Experimenter's Guide for Metro

## CIRC11: Larger Loads with Relays

![](https://cdn-learn.adafruit.com/assets/assets/000/043/125/medium800thumb/adafruit_products_IMG_2283.jpg?1498596608)

This next circuit is a bit of a challenge. We combine what we learned about using transistors in CIRC03 to control a relay.

![](https://cdn-learn.adafruit.com/assets/assets/000/045/152/medium800thumb/adafruit_products_dctrim.jpg?1502464840)

A relay is an electrically controlled mechanical switch. Inside the little plastic box is an electromagnet that, when energized, causes a switch to trip (often with a very satisfying clicking sound). You can buy relays that vary in size from a quarter of the size of the one in this kit up to as big as a fridge, each capable of switching a certain amount of current. They are immensely fun because there is an element of the physical to them.

While all the silicon we've played with to this point is fun sometimes, you may just want to wire up a hundred switches to control something magnificent. Relays give you the ability to dream it up then control it with your Arduino. Now onto&nbsp;using today's technology to control the past. ([The 1N4001 diode is acting as a flyback diode](http://ardx.org/4001), click here for more info about flyback diodes)

# Experimenter's Guide for Metro

## Parts

### **DPDT Relay**

&nbsp;

![adafruit_products_Relay_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/545/medium640/adafruit_products_Relay_White_Background_ORIG.jpg?1499357774)

### **560 Ohm Resistor**

**QTY: x2**

**Colors: Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/546/medium640/adafruit_products_560ohm.png?1499357866)

### **2.2k Ohm Resistor**

**Colors: Red \> Red \> Red**

&nbsp;

[If you'd like to order extra 2.2k Ohm resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2782)

![adafruit_products_2kohm-andrew.png](https://cdn-learn.adafruit.com/assets/assets/000/043/549/medium640/adafruit_products_2kohm-andrew.png?1499358044)

Warning: 

# [Am I using a NPN&nbsp; **Transistor** &nbsp;or a TMP36&nbsp; **Temperature Sensor?**](../../../../experimenters-guide-for-metro/electronics-primer-1#identifying-tmp36-and-npn)
### **Transistor (PN2222 or MPS2222)**

&nbsp;

[If you'd like to order extra NPN transistors from the Adafruit shop, click here!](https://www.adafruit.com/product/756)

![adafruit_products_Transistors_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/552/medium640/adafruit_products_Transistors_White_Background_ORIG.jpg?1499358049)

### **Diode (1N4001)**

&nbsp;

[If you'd like to order more diodes from the Adafruit shop, click here!](https://www.adafruit.com/product/755)

![adafruit_products_Diodes_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/554/medium640/adafruit_products_Diodes_White_Background_ORIG.jpg?1499358087)

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/596/medium640/adafruit_products_redled.png?1499360755)

### **5mm Green LED**

&nbsp;

[If you'd like to order extra green LEDs from the Adafruit shop, click here!&nbsp;](https://www.adafruit.com/product/298)

![adafruit_products_greenled_(1).png](https://cdn-learn.adafruit.com/assets/assets/000/043/626/medium640/adafruit_products_greenled_%281%29.png?1499440670)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/632/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499440858)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/693/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695282)

# Experimenter's Guide for Metro

## Wiring

## Wire it up:
![](https://cdn-learn.adafruit.com/assets/assets/000/067/747/medium800/adafruit_products_circ11.png?1545144349)

Warning: 

## Close-up of the relay wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/044/745/medium800/adafruit_products_CIRC11_fzz_-_Fritzing_-__Breadboard_View_.png?1501711438)

Make sure **the small square at the top of the DPDT Relay faces the top** of the breadboard. Also, ensure the **stripe** on the diode **faces**  **the**  **right side** of the DPDT Relay.&nbsp;

## Printable Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC11](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-11-sheet-ADAF/CIRC-11-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

Copy and paste the code below into a blank Arduino sketch. Then&nbsp;[compile and upload it to your Metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC11_RELAY/CIRC11_RELAY.ino

## Not Working?
### 

The example code uses pin 13 and we have the relay connected to pin 2. Make sure you made this change in the code:

&nbsp; `LED_BUILTIN -> 2`

### 

The transistor or coil portion of the circuit isn't quite working. Check the transistor is plugged in the right way.

### 

The included relays are designed to be soldered rather than used in a breadboard. As such you may need to press it in to ensure it works (and it may pop out occasionally).

# Experimenter's Guide for Metro

## Make It Better

# Check out the Back-EMF Pulse
 **Replace the diode with an LED.** You'll see it blink each time it "snubs" the coil voltage spike when it turns off.

# Controlling a Motor
In CIRC-03 we controlled a motor using a transistor. However if you want to control a larger motor a relay is a good option. To do this, simply remove the red LED and connect the motor in its place.&nbsp;

# Controlling Motor Direction
A bit of a complicated improvement to finish. To control the direction of spin of a DC motor we must be able to reverse the direction of current flow through it. To do this manually we reverse the leads. To do it electrically we require something called an h-bridge. This can be done using a DPDT relay to control the motor's direction, wire up the following circuit. It looks complicated but can be accomplished using only a few extra wires. Give it a try.

# Schematic Layout
![](https://cdn-learn.adafruit.com/assets/assets/000/043/111/medium800/adafruit_products_ARDX-EX-11-01.png?1498591571)

## Breadboard Layout
![](https://cdn-learn.adafruit.com/assets/assets/000/045/368/medium800thumb/adafruit_products_spin.jpg?1502914082)

# Experimenter's Guide for Metro

## CIRC12: Colorful Light

![](https://cdn-learn.adafruit.com/assets/assets/000/043/205/medium800thumb/adafruit_products_IMG_2299.jpg?1498664949)

We've blinked an LED and controlled eight in sequence. Now it's time to control color. Using an RGB LED (actual 3 LEDs in a single housing) we can generate any color our heart desires.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/113/medium800/adafruit_products_colorwheel.png?1498593080)

We do this through color mixing, what’s required is delving back to your elementary art days of playing with colored cellophane to produce different colors (if you can’t remember that far back don’t worry here’s a color wheel to help you out).

# Experimenter's Guide for Metro

## Parts

### **RGB LED**

&nbsp;

[If you'd like to pick up another RGB LED from the Adafruit Shop, click here.&nbsp;](https://www.adafruit.com/product/159)

![adafruit_products_rgbled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/631/medium640/adafruit_products_rgbled.png?1499440943)

### **560 Ohm Resistor**

**QTY: x3**

**Colors:** &nbsp; **Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/548/medium640/adafruit_products_560ohm.png?1499357905)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/551/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499358044)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/694/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695290)

# Experimenter's Guide for Metro

## Wiring

## Wire according to the diagram below:
![](https://cdn-learn.adafruit.com/assets/assets/000/050/267/medium800/adafruit_products_circ12_bb.png?1516231208)

1. Connect the first RGB LED leg to a 560 ohm resistor, then&nbsp; **Pin 9**
2. Connect the second&nbsp;RGB LED leg to a 560 ohm resistor, then&nbsp; **Pin 10**
3. Connect the first RGB LED leg to a 560 ohm resistor, then&nbsp; **Pin 11**

Note that the **longest leg&nbsp;** of the RGB LED connects to the power rail, 5V.&nbsp;

## Printable Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC12](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-12-sheet-ADAF/CIRC-12-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Wiring for Metro Express

If you are using the [Adafruit Metro Express](https://www.adafruit.com/product/3505), the wiring below should be used. [If you're not sure what board you have, check this page.](../../../../experimenters-guide-for-metro/what-board-do-i-have)

Warning: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/432/medium800/adafruit_products_circ12-express_bb.png?1499097165)

# Experimenter's Guide for Metro

## Code

Copy and paste the code below into a blank Arduino sketch. Then&nbsp;[compile and upload it to your Metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC12_RGB_LED/CIRC12_RGB_LED.ino

## Having Trouble?&nbsp;
### 

With the four pins of the LED so close together, it’s sometimes easy to misplace one. Try double checking each pin is where it should be.

### 

Some RGB LEDs have green and blue swapped, change your code so the pins are swapped and re-upload!

### 

The red diode within the RGB LED may be a bit brighter than the other two. To make your colors more balanced, try using a higher ohm resistor (or two resistors in series).

### 

If you’re looking to do more why not check out all the lovely extra bits and bobs available from the [Adafruit Shop.](http://www.adafruit.com)

# Experimenter's Guide for Metro

## Make It Better

## More Colors
I imagine you are less than impressed by the cyan glowing LED before you. To display a different color, change the color in the code to one of the others:

&nbsp; &nbsp; &nbsp;`setColor(ledDigitalOne, CYAN);` -\> `setColor(ledDigitalOne, newColor)`

## Display a Random Color
Of course we can do more than display a constant color. To see how we can cycle through random colors, change the `loop()` code to:

```
void loop() {
  //setColor(ledDigitalOne, CYAN);
  randomColor();
}
```

# Analog Color Control
While switching between colors is good fun, RGB LEDs really come into their own when mixed with analog control. Using PWM (pulse width modulation), it's possible to produce nearly any color and fade between them. Sadly, the code for this is a bit too long for the section above, so click&nbsp;below to see the code:&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC12_ANALOG_CTRL/CIRC12_ANALOG_CTRL.ino

# Experimenter's Guide for Metro

## CIRC13: Squeezing 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/204/medium800thumb/adafruit_products_IMG_2294.jpg?1498664573)

Force Sensitive Resistors (FSRs) are sensors that allow you to detect the pressure exerted on them. They're similar to a potentiometer (like in CIRC08), except instead of varying resistance by twisting, the FSR's resistance varies with pressure.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/044/756/medium800/adafruit_products_force___flex_FSRimage.jpg?1501772394)

The FSR is made of 2 layer separated by a spacer. The more you press, the more dots on the active element touch the semiconductor, and that makes the resistance go down. They're not good for detecting exact weight, but they're great for detecting squeezing and pushing and poking. [If you'd like to dive a bit deeper into how FSRs exactly work, ladyada has a great learn guide which goes over more technical details.](../../../../force-sensitive-resistor-fsr/overview)

# Experimenter's Guide for Metro

## Parts

### **Force Sensitive Resistor&nbsp;**

&nbsp;

[If you'd like to order a force sensitive resistor from the Adafruit shop, click here!](https://www.adafruit.com/product/166)

![adafruit_products_Force_Sensitive_Resisitor_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/547/medium640/adafruit_products_Force_Sensitive_Resisitor_White_Background_ORIG.jpg?1499357841)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

### &nbsp;
![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/550/medium640/adafruit_products_10kohm.png?1499358044)

### **5mm Green LED**

&nbsp;

[If you'd like to order extra green LEDs from the Adafruit shop, click here!&nbsp;](https://www.adafruit.com/product/298)

![adafruit_products_greenled_(1).png](https://cdn-learn.adafruit.com/assets/assets/000/043/639/medium640/adafruit_products_greenled_%281%29.png?1499441427)

### **560 Ohm Resistor**

**Colors:** &nbsp; **Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/553/medium640/adafruit_products_560ohm.png?1499358103)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/640/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499441487)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/695/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695298)

# Experimenter's Guide for Metro

## Wiring

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/050/268/medium800/adafruit_products_circ13_bb.png?1516231276)

The last circuit is easy to build, but really fun to use:

1. One end of the Force Sensitive Resistor (FSR) connects to the power rail.
2. The other end of the FSR connects to&nbsp; **analog pin 2&nbsp;** and a 10k ohm pull-up resistor.
3. Connect a red LED to&nbsp; **pin 9** and a 560 ohm current-limiting resistor.&nbsp;

## Printable Breadboard Layout Sheet
[Click here to download the printable Breadboard Layout Sheet for CIRC13](https://s3.amazonaws.com/adafruit-download/experimenter_guide_metro/CIRC-13-sheet-ADAF/CIRC-13-sheet-ADAF-1.png)
# Experimenter's Guide for Metro

## Code

Copy and paste the code below into a blank Arduino sketch. Then&nbsp;[compile and upload it to your Metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC13_FSR/CIRC13_FSR.ino

## Not Working?&nbsp;
### 

LEDs will only work in one direction. Try taking it out and twisting it 180 degrees. (no need to worry, installing it backwards does no permanent harm).

### 

This is a result of the FSR’s response to pressure not being quite linear. But do not fear it can be changed in code (check out the details in the Making it Better section)

### 

You're in luck - this guide has extra **CIRC** uits and a few&nbsp; **PROJ** ects included! Check the sidebar on the left for a full listing.

# Experimenter's Guide for Metro

## Make It Better

## Calibrating the Range
While the light is now fading, chances are its response isn't quite perfect. To adjust the response, we need to add one more line to our code:

&nbsp; &nbsp; &nbsp;`map(value, fromLow, fromHigh, toLow, toHigh)`

To calibrate our sensor, we can use the serial monitor like in CIRC-11. Open the serial monitor, then replace the `fromLow` value with the value display when the sensor is fully pressed.

Then, replace the `fromHigh` value with the unpressed value.&nbsp;

Finally, fill in the range `toLow = 0` and `toHigh = 255`

The result will look something like this:

```
int value = analogRead(sensePin);
map(value, 125, 854, 0, 255);
analogWrite(ledPin, value);
```

## The RGB Strongperson Test
Step right up to test your strength against the Adafruit Metro [High Striker Game!](https://en.wikipedia.org/wiki/High_striker)&nbsp;Only the strongest will succeed! Let's quickly modify the circuit with a RGB LED to indicate strength-level and modify the code to display how hard someone is pressing the force-sensitive resistor.&nbsp;

### Diagram:&nbsp;RGB + Force Resistor
![](https://cdn-learn.adafruit.com/assets/assets/000/043/622/medium800/adafruit_products_circ13-mib_bb.png?1499434118)

The code below will need to be first run, and then modified. After running it, open the Serial Monitor and press the force sensitive resistor as hard as possible. The value printed is the maxForce that someone could press on the FSR on your circuit. Set maxForce to the value in your serial monitor:

&nbsp; &nbsp; &nbsp;`// set maxForce`  
&nbsp; &nbsp; &nbsp;`int maxForce = FORCEVALUE;`

After setting the maxForce, try your luck! We've included a serial printout to show how hard you're depressing the FSR.&nbsp;

```
/*
  FSR Strongperson Test for Metro (and Metro Express)
  
  Utilizes a  FSR and a RGB LED to test how strong you are.

  Created 7 July 2017
  By Brent Rubell for Adafruit Industries
  Support Open Source ~ buy Adafruit 

*/

// fsr pin
int sensePin = A2; 
// rgb led pins
int rgbLED[] = {9, 10, 11};

// common cathode rgbleds
const boolean ON = LOW;
const boolean OFF = HIGH;

//  predefined colors 
const boolean BLUE[] = {ON, OFF, OFF}; 
const boolean RED[] = {OFF, OFF, ON}; 
const boolean GREEN[] = {OFF, ON, OFF};

void setup() {
 Serial.begin(9600);
 
 // set all rgb pins as outputs  
 for(int i = 0; i&lt;3; i++){
  pinMode(rgbLED[i], OUTPUT);
 }
}

void loop() {
 // scale voltage down to 255 from 1023
 int force = analogRead(sensePin) / 4; 
 // check maximum force by squeezing the FSR 
 Serial.println(force);
 
 // set maxForce
 int maxForce = 160;
 
 // calculate regions
 int lowForce = maxForce / 3;
 int medForce = (maxForce / 3) * 2;
 // check force regions
 if(force &lt; lowForce) {
  Serial.println("easy");
  setColor(rgbLED, RED);
 }
 else if (force &gt; lowForce &amp;&amp; force &lt; medForce) {
  Serial.println("medium");
  setColor(rgbLED, BLUE);
 }
 else {
  Serial.println("hard");
  setColor(rgbLED, GREEN);
 }
 
}

// rgb color mixing
void setColor(int* led, const boolean* color) {
  for(int i = 0; i &lt; 3; i++){
    digitalWrite(led[i], color[i]);
  }
}
```

## Other Applications
With sensors, the real fun comes in how you use them in neat and unexpected ways. So get thinking about how and where sensing force could enhance your life (or the life of others).&nbsp;

# Experimenter's Guide for Metro

## CIRC14: Character LCDs

![](https://cdn-learn.adafruit.com/assets/assets/000/044/814/medium800thumb/adafruit_products_char_lcd.jpg?1501791923)

[We carry a slew of different types of Character LCDs in the Adafruit Store](https://www.adafruit.com/category/63_96). The Experimenter's kit provides one, but i[f you don't have one, the 16x2 variety is used](https://www.adafruit.com/product/181) in the Experimenter's guide.

Character LCDs are super useful for displaying text, data, variable information or providing an interface to interact with. You've already used the Serial Monitor in previous learn guides. While it's useful to display data from the Metro, it needs to be tethered to the computer via USB. The character LCD lets you have a free-standing display for whatever you want to print - text, data, and even small icons (5px x 7px)

# Experimenter's Guide for Metro

## Parts

### **16x2 Character LCD**

&nbsp;

[If you'd like to buy a white-on-blue 16x2 character lcd from the Adafruit shop, click here!](https://www.adafruit.com/product/1447)

![adafruit_products_Screen_White_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/804/medium640/adafruit_products_Screen_White_Background.jpg?1501788763)

### **Breadboard Trim Potentiometer - 10k**

&nbsp;

[If you'd like to buy an extra trimpot from the Adafruit store, click here!](https://www.adafruit.com/product/356)

![adafruit_products_Potentiometer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/805/medium640/adafruit_products_Potentiometer_White_Background_ORIG.jpg?1501788819)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/806/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1501788857)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/807/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501788941)

# Experimenter's Guide for Metro

## Wiring

The instructions and wiring on&nbsp;this page&nbsp;is based off of [ladyada's wonderful Character LCD wiring guide,](../../../../character-lcds/lcd-varieties?view=all#wiring-a-character-lcd) but updated for Fritzing.&nbsp;

# Assembling your LCD
Some 16x2 LCDs may come assembled, meaning the header is already soldered on:

### Assembled Standard LCD 16x2 + extras - White on Blue

[Assembled Standard LCD 16x2 + extras - White on Blue](https://www.adafruit.com/product/1447)
Standard HD44780 LCDs are useful for creating standalone projects. &nbsp;This product is similar to our [Standard LCD 16x2 display **but comes with the header soldered on!**](https://www.adafruit.com/products/181)

- 16 characters wide, 2 rows
- White text...

In Stock
[Buy Now](https://www.adafruit.com/product/1447)
[Related Guides to the Product](https://learn.adafruit.com/products/1447/guides)
![Angled shot of long, rectangular, LCD screen module breakout.](https://cdn-shop.adafruit.com/640x480/1447-05.jpg)

We also have some that are unassembled with an unsoldered header:

### Standard LCD 16x2 + extras

[Standard LCD 16x2 + extras](https://www.adafruit.com/product/181)
Standard HD44780 LCDs are useful for creating standalone projects.

- 16 characters wide, 2 rows
- White text on blue background
- Connection port is 0.1" pitch, single row for easy breadboarding and wiring
- Pins are documented on the back of the LCD to assist...

In Stock
[Buy Now](https://www.adafruit.com/product/181)
[Related Guides to the Product](https://learn.adafruit.com/products/181/guides)
![Character LCD with 16x2 characters, with header and potentiometer](https://cdn-shop.adafruit.com/640x480/181-06.jpg)

If your LCD is assembled, you can skip these next steps and proceed directly to wiring it up. Otherwise, follow along below.&nbsp;

## Soldering your LCD
Soldering is a very useful skill in the realm of electronics. It's the process of joining two metals together, using another piece of metal (also known as solder) between them. If you have never done this before, Bill Earl wrote an awesome visual guide entitled&nbsp;_Adafruit Guide To Excellent&nbsp;Soldering_&nbsp;which will get you off the ground, fast. If you would prefer&nbsp;to watch a video, Collin's Lab covers soldering,&nbsp;too:

https://www.youtube.com/watch?v=QKbJxytERvg

The 16x2 LCD is not that hard to solder, but it does have a lot of pins. We have some advice for soldering these like a pro:

Start by plugging your 16x2 LCD and header into your breadboard.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/044/783/medium800/adafruit_products_IMG_3462.jpg?1501783212)

Then, (with a medium-level of heat, _dont make your iron too hot!_)&nbsp;start soldering&nbsp; **Pin 1** to the header. Next solder&nbsp; **Pin 16.&nbsp;** This will "tack" the header to the LCD, making soldering the rest of the pins&nbsp;easier.&nbsp;

Now, go solder all the other pins!

 **Messed up? Issues with your header?&nbsp;** Soldering is very fix-able. It'll just take time. Check this guide for your mistakes, and correct them before moving on.&nbsp;

# Wiring Power and Backlight
Info: 

First, plug your LCD&nbsp;into the breadboard. Then,&nbsp;connect the **+5V** &nbsp; **Pin** &nbsp;to the power rail and the&nbsp; **GND&nbsp;**** Pin**to the ground rail.&nbsp;

![adafruit_products_1.png](https://cdn-learn.adafruit.com/assets/assets/000/044/763/medium640/adafruit_products_1.png?1501775731)

Next, connect **LCD Pin 16** to the GND&nbsp;rail, and&nbsp; **LCD Pin 15** to the power rail.

&nbsp;

![adafruit_products_2.png](https://cdn-learn.adafruit.com/assets/assets/000/044/764/medium640/adafruit_products_2.png?1501775776)

Info: 

Let's check it's power. Connect your Metro or Metro Express to power. You should see the LCD light up. Some low-cost LCDs don't come with a backlight.

If you have one with a backlight and **if you don't see it lighting up, go back and check over your wiring.**

![adafruit_products_IMG_3440.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/787/medium640/adafruit_products_IMG_3440.jpg?1501783890)

## Wiring the Contrast Circuit
 **Next** , let's **place the contrast potentiometer to the left of LCD Pin 16.** You can place it anywhere on the breadboard you'd like, but the next CIRC has it placed to the left of&nbsp; **LCD Pin 16**

![adafruit_products_5.png](https://cdn-learn.adafruit.com/assets/assets/000/044/799/medium640/adafruit_products_5.png?1501784531)

Connect one of the outer pins of the potentiometer to the power rail. Connect the other outer pin to the ground rail. It doesn't matter which goes where, the other pins are interchangeable as long as one goes to power and one goes to ground.&nbsp;

The middle of the potentiometer (the wiper) connects to **LCD Pin 3**

![adafruit_products_5.png](https://cdn-learn.adafruit.com/assets/assets/000/044/798/medium640/adafruit_products_5.png?1501784490)

 **LCD Pin 1&nbsp;** connects to the ground rail.&nbsp; **LCD Pin 2&nbsp;** connects to the power rail. These pins are&nbsp;the logic of the LCD.

![adafruit_products_5.png](https://cdn-learn.adafruit.com/assets/assets/000/044/797/medium640/adafruit_products_5.png?1501784423)

Info: 

Before moving on, we'll perform a small test to make sure the wiring is correct. Plug in your Metro or Metro express and twist the potentiometer. You should see black rectangles appear on the&nbsp;first line of the LCD. **If you don't see this, check your wiring before moving on.**

![adafruit_products_IMG_3447.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/786/medium640/adafruit_products_IMG_3447.jpg?1501783863)

## Wiring the&nbsp;Data Bus
The&nbsp; **RW** Pin is not required for this guide, as we are only writing to the display. Connect&nbsp; **LCD Pin 5** to the ground rail.

![adafruit_products_5.png](https://cdn-learn.adafruit.com/assets/assets/000/044/796/medium640/adafruit_products_5.png?1501784350)

Next, we are going to connect the&nbsp; **RS Pin**. We used a blue wire&nbsp;to connect&nbsp; **LCD Pin 4&nbsp;** to&nbsp; **Metro Digital Pin 7**

![adafruit_products_8.png](https://cdn-learn.adafruit.com/assets/assets/000/044/795/medium640/adafruit_products_8.png?1501784316)

The&nbsp; **EN Pin&nbsp;** is next. We used a green wire to connect&nbsp; **LCD Pin 6&nbsp;** to **Metro Digital Pin 8**

![adafruit_products_8.png](https://cdn-learn.adafruit.com/assets/assets/000/044/794/medium640/adafruit_products_8.png?1501784275)

Next is the first of the data pins, DB7. We used a white wire to connect **LCD Pin 14** to **Metro Digital Pin 12**

![adafruit_products_10.png](https://cdn-learn.adafruit.com/assets/assets/000/044/793/medium640/adafruit_products_10.png?1501784229)

&nbsp; **DB6&nbsp;** is up next. We used an orange wire to connect&nbsp; **LCD Pin 13&nbsp;** to&nbsp; **Metro Digital Pin 11**

![adafruit_products_11.png](https://cdn-learn.adafruit.com/assets/assets/000/044/792/medium640/adafruit_products_11.png?1501784188)

Connect **DB5&nbsp;** (we used a purple wire)from&nbsp; **LCD Pin 12&nbsp;** to&nbsp; **Metro Digital&nbsp;Pin 10.**

![adafruit_products_12.png](https://cdn-learn.adafruit.com/assets/assets/000/044/791/medium640/adafruit_products_12.png?1501784139)

Finally, we connect&nbsp; **DB4&nbsp;** with a gray wire from&nbsp; **LCD Pin 11&nbsp;** to&nbsp; **Metro Digital&nbsp;Pin 9**

![adafruit_products_13.png](https://cdn-learn.adafruit.com/assets/assets/000/044/801/medium640/adafruit_products_13.png?1501784702)

Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/044/803/medium800/adafruit_products_CIRC14-LCD_fzz_-_Fritzing_-__Breadboard_View_.png?1501784817)

This is what you should have on your desk, proceed to the code section after double-checking your wiring:

![](https://cdn-learn.adafruit.com/assets/assets/000/044/802/medium800/adafruit_products_13.png?1501784721)

# Experimenter's Guide for Metro

## Code

Copy and paste the code below into a new Arduino sketch. Then, compile and upload it to your Metro or Metro Express.&nbsp;

Danger: 

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC14_CHAR_LCD/CIRC14_CHAR_LCD.ino

# Not Working?
### 

[Double-check the wiring connections you made to the power and backlight pins of the Character LCD is&nbsp;correct](../../../../experimenters-guide-for-metro/wiring-28#wiring-power-and-backlight). Check your soldering joints,[maybe they are problematic.&nbsp;](../../../../adafruit-guide-excellent-soldering/surface-mount?view=all#common-problems)

Also check that you are using&nbsp; **the 5v&nbsp;**** Pin **instead of the&nbsp;** 3.3V&nbsp; ****Pin.&nbsp;**

### 

Try twisting your potentiometer. It's also possible that your [data bus is not hooked up correctly.](../../../../experimenters-guide-for-metro/code-28#wiring-the-data-bus)

### 

Re-wiring your LCD is a good way to get rid of any issues, it takes a lot of time but ensures everything is correct.&nbsp;If all else fails,[&nbsp;post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

## Writing to the second line
If we want to write to the second line, we can use `lcd.setCursor(COLUMN, LINE)` such that the column is 0 and the line is 1:

&nbsp; &nbsp; &nbsp;`lcd.setCursor(0,1);`

```
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}
```

Danger: 

## Writing the light sensor to the LCD
Let's try writing the output of the light sensor to the character LCD.

This will require an extra part:

### **Photo Sensor**

[If you'd like to order another photoresistor from the Adafruit shop, click here!](https://www.adafruit.com/product/2831)

![adafruit_products_Photo_Sensor_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/808/medium640/adafruit_products_Photo_Sensor_White_Background_ORIG.jpg?1501789397)

## Wiring
Info: 

![](https://cdn-learn.adafruit.com/assets/assets/000/044/809/medium800/adafruit_products_CIRC14-LCD-MIB_bb.png?1501789567)

 **Note:** While the rail is connected to 5V, the light sensor is connected to 3V.&nbsp;

## Code
Copy and paste the code below into the Arduino editor. Then, compile and upload it to your board.

```
/* CIRC14 - Make It Better
 * Character LCD + TMP36
 *  
 *  by Brent Rubell for Adafruit Industries.   Support Open Source, buy Adafruit!
 */
 
// include the library code:
#include &lt;LiquidCrystal.h&gt;

// modified wiring for Metro Explorers Guide
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// photo light sensor
int lightPin = A0;

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // print to the first line of the LCD
  lcd.print("Light Value:");
}

void loop() {
  // read the light level
  int lightLevel = analogRead(lightPin);
  // map and constrain the light sensor values
  lightLevel = map(lightLevel, 0, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  
  // set the cursor to column 0, line 1
  lcd.setCursor(0, 1);
  // write lightLevel to the LCD
  lcd.print(lightLevel);
}

```

# What's next?
The Thermometer (CIRC15) gets into the nitty-gritty of the character LCD. You'll learn how to display custom characters, full strings of text, and multi-line data output!

# Experimenter's Guide for Metro

## CIRC15: Thermometer

![](https://cdn-learn.adafruit.com/assets/assets/000/043/219/medium800/adafruit_products_IMG_2311.jpg?1498676866)

What if you want to show more output than a bunch of LEDs can handle? Sure, you could set up a bunch of LEDs to display numbers. But what if there was another way...

Character LCDs are super robust and great for output. _Anything_ you can fit onto the 16 (lines) by 2 (rows) screen can be output by your code when you drop in the&nbsp;_LiquidCrystal&nbsp;_library, a collection of code that let's you add new functionality to your circuits.

We are going to re-create CIRC10. But instead of printing to a serial monitor, we are going to print to an external character LCD.&nbsp;

# Experimenter's Guide for Metro

## Parts

### **16x2 Character LCD**

&nbsp;

[If you'd like to buy a white-on-blue 16x2 character lcd from the Adafruit shop, click here!](https://www.adafruit.com/product/1447)

![adafruit_products_Screen_White_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/876/medium640/adafruit_products_Screen_White_Background.jpg?1499893071)

### **Breadboard Trim Potentiometer - 10k**

&nbsp;

[If you'd like to buy an extra trimpot from the Adafruit store, click here!](https://www.adafruit.com/product/356)

![adafruit_products_Potentiometer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/629/medium640/adafruit_products_Potentiometer_White_Background_ORIG.jpg?1499440826)

Warning: 

## [Am I using a&nbsp; **TMP36 Temperature Sensor&nbsp;** or a&nbsp; **NPN Transistor**](../../../../experimenters-guide-for-metro/electronics-primer-1#identifying-tmp36-and-npn)
### **Analog Temperature Sensor**

&nbsp;

[If you'd like an extra temperature sensor, you can grab one from the Adafruit shop, click here](https://www.adafruit.com/product/165)

![adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/559/medium640/adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg?1499358358)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/637/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499441083)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/696/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695303)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/043/257/medium800/adafruit_products_circ14_bb.png?1498679594)

The&nbsp;wiring for the character LCD may be tricky. [There's a learn guide that walks through each individual wire.](../../../../character-lcds/overview?view=all) If you want to work along with it, **be sure to place the LCD on the&nbsp;right side&nbsp;of the breadboard to ensure you can fit the potentiometer and the TMP36 sensor on the breadboard too.&nbsp;**

# Experimenter's Guide for Metro

## Code

CIRC15 uses code that will work for **both** the Metro and the Metro Express.&nbsp;You'll need to make a&nbsp;_tiny&nbsp;_modification to it to get it working with the Metro you own.&nbsp;[(If you're not sure what board you have, click here!)](../../../../experimenters-guide-for-metro/what-board-do-i-have).&nbsp;

Danger: 

## **Code:**
https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC15_THERMOMETER/CIRC15_THERMOMETER.ino

Danger: 

## Having Trouble?&nbsp;
### 

Try twisting the potentiometer. If that doesn't work, re-check your wiring.&nbsp;

### 

Make sure the pins of the LCD are flush with the breadboard. If that doesn't work, re-upload the sketch from Arduino.&nbsp;

### 

The included code has a line that uses the serial monitor. Pop open the serial monitor and check the number in there against what you think the current temperature is. If the number seems off, double check wiring to **Analog Pin A0.&nbsp;**

### 

The character LCD has a&nbsp;_lot_ of wires and it's hard to keep&nbsp;track.&nbsp;[We have a great guide that takes you step-by-step. Check it out!](../../../../character-lcds/overview?view=all)

# Experimenter's Guide for Metro

## Make It Better

## Using Fahrenheit&nbsp;

We are going to convert the degrees displayed by the example code to in Celsius to Fahrenheit. In `loop()`, change the following lines:

```
       // Degrees C
 //temperature = (temperature - .5) * 100; 
 // Degrees F
 temperature = (((temperature - .5) * 100)*1.8) + 32;
    
```

Then, compile and upload the sketch to your metro and observe&nbsp;the number change.&nbsp;

## Printing new&nbsp;text to the LCD

Did you notice that even though the number changed, the **\*C** was still printed to your display? This is because the \*C is hard-coded into the display.

To change \*C to \*F, change the following line:

` lcd.print("*C");`&nbsp; **-\>&nbsp;** `lcd.print("*F");`

Then, compile and upload to the Metro. Your temperature should display the Fahrenheit unit and temperature symbol.&nbsp;

## Printing to the Second&nbsp;Row

The intro mentioned this LCD was 16x2. It has&nbsp; **two** rows you can print to, but we are only using one. Let's print the&nbsp; **\*F&nbsp;** symbol to the same spot in the second row. To do this, modify&nbsp;the following code in your `loop()`:

```
lcd.setCursor(11,1); // instead of (11,0), we are printing to (11,1), the 2nd row
lcd.print("*F");
```

## Using Custom Characters

The LiquidCrystal library contains a command called `createchar()`_&nbsp;_which&nbsp;can create a custom character (a glyph!) for printing to the LCD. Our code uses an asterisk instead of a degrees symbol. Let's complete the thermostat and have a&nbsp;_real_ degrees symbol.&nbsp;

To do this, add the following code above your` setup()` loop:

```
// Custom Degree Symbol
byte degree[8] = {
    0x7,
    0x5,
    0x7,
    0x0,
    0x0,
    0x0,
    0x0,
};
```

In the `setup()` loop, add the following line:

&nbsp; &nbsp; &nbsp;`lcd.createChar(0,degree);`

Finally, in the` loop()`, modify&nbsp;the following lines:

```
lcd.setCursor(11,1);
lcd.write(byte(0)); // custom degrees character
lcd.setCursor(12,1);
lcd.print("F");
```

After compiling and uploading, you should see the degree symbol next to the F.&nbsp;

# Making your own Custom Character
If you want to add more custom characters, or different ones, there's a great online generator we like. You can add in your own icons, for whatever you want. Let's learn how to do this:

First, [visit the HD44780 graphic generator site](https://www.quinapalus.com/hd44780udg.html). Then, change the&nbsp;character size to **5 by 8**

![](https://cdn-learn.adafruit.com/assets/assets/000/044/810/medium800/adafruit_products_chargen.png?1501790293)

Click the boxes to set pixels. When a pixel is set, it'll turn from green to black. You can un-set pixels by clicking on a black pixel (on) to turn it green (off).

![](https://cdn-learn.adafruit.com/assets/assets/000/044/811/medium800thumb/adafruit_products_face.jpg?1501791127)

Once you have your custom character, copy the values from "In Hex" and paste them into an Arduino sketch as a byte array:

```
// smiley face
byte smile[8] = {
    0x0,
    0x0,
    0x8,
    0x0,
    0x0,
    0x0,
    0x0,
};
```

In the `setup()` loop, add the following line:

&nbsp; &nbsp; &nbsp;`lcd.createChar(0,smile);`

Then, in `loop()` add the following to write your custom character to the LCD:

&nbsp; &nbsp; &nbsp;`lcd.write(byte(0)); // custom degrees character`

# Experimenter's Guide for Metro

## CIRC16: IR Sensor

![](https://cdn-learn.adafruit.com/assets/assets/000/044/593/medium800thumb/adafruit_products_IMG_2795.jpg?1501535544)

IR Receiver Sensors&nbsp;are photocells&nbsp;tuned to receive IR frequencies. The IR frequency is not visible to the human eye, but can be picked up by a webcam or cell phone.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/044/816/medium800thumb/adafruit_products_out.jpg?1501792143)

Try pressing a button on the [Mini Remote Control](https://www.adafruit.com/product/389)&nbsp;or a TV/DVD-player remote and shining it at your **webcam**. The light you see emitted by the remote is **Infrared light.&nbsp;** These Infrared Signals are PWM&nbsp;signals carrying pulses (_marks_) and intervals (_spaces_) carrying 32 bits of data.&nbsp;

The Experimenters Guide uses IRLib, an&nbsp;easy-to-understand Arduino library that de-mystifies the infrared light receiver. In the code section, we will go over installing this library and use it with this circuit.&nbsp;

# Experimenter's Guide for Metro

## Parts

# IR (Infrared) Receiver Sensor

[If you'd like to order an extra IR receiver sensor from the Adafruit shop, click here!](https://www.adafruit.com/product/157)

![adafruit_products_ir-rcv.png](https://cdn-learn.adafruit.com/assets/assets/000/043/818/medium640/adafruit_products_ir-rcv.png?1499870461)

# Mini Remote Control

We suggest using this remote with CIRC15, but you can use any remote

[If you'd like to order an extra Mini Remote Control from the Adafruit Shop, click here!](https://www.adafruit.com/product/389)

![adafruit_products_IR-REMOTE.png](https://cdn-learn.adafruit.com/assets/assets/000/043/821/medium640/adafruit_products_IR-REMOTE.png?1499870588)

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/043/865/medium640/adafruit_products_redled.png?1499881847)

### **560 Ohm Resistor**

**Colors:&nbsp;Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/863/medium640/adafruit_products_560ohm.png?1499881653)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/864/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499881712)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/862/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1499881566)

# Experimenter's Guide for Metro

## Wiring

Danger: 

The wiring for this circuit is the&nbsp; **same** for the Metro and the Metro Express.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/819/medium800/adafruit_products_circ15_bb.png?1501792389)

# Experimenter's Guide for Metro

## Installing the IR Library

## Installing Arduino Libraries
The Experimenters Guide uses&nbsp;[IRLib2](https://github.com/cyborg5/IRLib2), an&nbsp;easy-to-understand Arduino library that de-mystifies the infrared light receiver. It makes writing code for IR Reciever and IR LED much easier.

## Installing the IR Library&nbsp;
[Download the Latest Infrared Library ](https://github.com/cyborg5/IRLib2/archive/master.zip)
To install the IR Library:

1. Download the IR Library by clicking the button above, or [download it directly from&nbsp;the IRLib 2.x Library from Github.](https://github.com/cyborg5/IRLib2)
2. Uncompress the ZIP file after it’s finished downloading.
3. Check that the uncompressed folder contains **five** separate folders. IRLib 2.x contains multiple libraries that work together.&nbsp;
4. Copy all&nbsp; **five&nbsp;** into your Arduino Library folder root directory. The path will typically be in **(home)/Documents/Arduino/Libraries**. If you do not see the /Libraries/ folder, you may need to create this yourself.&nbsp;
5. Restart the Arduino IDE.

# Experimenter's Guide for Metro

## Code

Ensure you followed the&nbsp;_Installing the IR Library&nbsp;_Page. Copy and paste the code below into a blank Arduino Sketch. Then, compile and upload the code to your Metro.

Press button 1 and the LED should turn on. Any other button will turn the LED off.

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC16_IR/CIRC16_IR.ino

# Not Working?
### 

Is your RGB LED wired correctly? Are you using a different remote than the one included in the MetroX or MetroX Express Kit? If so, check out CIRC17 for examples of using different infrared sources.&nbsp;

### 

The IRLib 2.x library was improperly installed. Go back a step and make sure you have it installed.&nbsp;

### 

[A broken circuit is no fun, post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## CIRC17: IR Replay

We are going to build an IR Replay circuit. This circuit uses&nbsp; **both** the IR LED and the IR Sensor (you used this in CIRC15) to construct a circuit that can record and play back infrared signals from any remote control.&nbsp;

A great (and _really_ fun) application of this is the[Adafruit TV-B-Gone Kit,](https://www.adafruit.com/product/73) a way to turn off those annoying&nbsp;televisions in bars, stores, or doctors offices.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/135/medium800/adafruit_products_73-04.jpg?1500672193)

The concept of replaying an infrared signal is also super useful in other areas. Some&nbsp;garage door openers open the garage&nbsp;when a specific IR signal is received. Do some exploring to find&nbsp;out&nbsp;which devices you own are operated by an infrared signal, and take control of them.

Another application would be **building an assistive device** , a device to assist someone not able to perform everyday&nbsp;actions. You can create a great assistive device by combining this circuit, and the FSR, to make a pedal/press operated remote control for anything operated by IR.

**You can even combine this circuit and the relay** used in CIRC11 to receive a signal from a nearby remote and control the relay to switch the power on a DC-powered appliance (like a fan or a lamp).

# Experimenter's Guide for Metro

## Parts

# IR (Infrared) Receiver Sensor

[If you'd like to order an extra IR reciver sensor from the Adafruit shop, click here!](https://www.adafruit.com/product/157)

![adafruit_products_ir-rcv.png](https://cdn-learn.adafruit.com/assets/assets/000/044/122/medium640/adafruit_products_ir-rcv.png?1500671027)

# Super-bright 5mm IR LED

[If you'd like to order an extra 5mm IR LED from the Adafruit shop, click here](https://www.adafruit.com/product/387)

![adafruit_products_ir-led.png](https://cdn-learn.adafruit.com/assets/assets/000/044/123/medium640/adafruit_products_ir-led.png?1500671095)

Warning: 

## [Am I using a **NPN Transistor&nbsp;** or a&nbsp; **TMP36**  **Temperature Sensor**](../../../../experimenters-guide-for-metro/electronics-primer-1#identifying-tmp36-and-npn)
### **Transistor (PN2222 or MPS2222)**

&nbsp;

[If you'd like to order extra NPN transistors from the Adafruit shop, click here!](https://www.adafruit.com/product/756)

![adafruit_products_Transistors_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/130/medium640/adafruit_products_Transistors_White_Background_ORIG.jpg?1500671842)

### **Pushbutton**

### **Qty: x2**

&nbsp;

[If you'd like to order more pushbuttons from the Adafruit shop, click here!](https://www.adafruit.com/product/367)

![adafruit_products_Push_Button_White_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/653/medium640/adafruit_products_Push_Button_White_Background.jpg?1501614485)

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled.png](https://cdn-learn.adafruit.com/assets/assets/000/044/654/medium640/adafruit_products_redled.png?1501614581)

### **560 Ohm Resistor**

**Colors: Green \> Blue \> Brown**

**Qty: x2**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/044/651/medium640/adafruit_products_560ohm.png?1501614335)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

**Qty: x2**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

### &nbsp;
![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/044/652/medium640/adafruit_products_10kohm.png?1501614427)

# Mini Remote Control (OPTIONAL)

You can use&nbsp; **any&nbsp;** remote for this circuit. We will use the Mini Remote for this example, though.

[If you'd like to order an extra Mini Remote Control from the Adafruit Shop, click here!](https://www.adafruit.com/product/389)

![adafruit_products_IR-REMOTE.png](https://cdn-learn.adafruit.com/assets/assets/000/044/124/medium640/adafruit_products_IR-REMOTE.png?1500671258)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/133/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1500672047)

### **Adafruit Metro + Breadboard + Mounting Plate&nbsp;**

&nbsp;

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!

&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/132/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1500671983)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/045/481/medium800/adafruit_products_circ17_bb.png?1503075362)

We spaced a lot of the components out such that they don't overlap on the breadboard. Be careful while wiring up the **NPN&nbsp;** transistor - it has a specific orientation which must be followed.&nbsp;

# Experimenter's Guide for Metro

## Code

**[You'll need the IRLIB2.x Library installed to use CIRC17. &nbsp;If you need to install it, click here!](../../../../experimenters-guide-for-metro/installing-the-ir-library)**

Copy and paste the code below into the Arduino Editor, then compile and upload it to your board.&nbsp;

```
/* CIRC17 - IR Replay
 * Requires: IRLib 2.x Library
 * 
 * record.ino by Chris Young
 * modified by Brent Rubell for Adafruit Industries for the for the Metro (and Metro Express) Experimenters Guide.  Support Open Source, buy Adafruit!
 */

/* IRLib */
#include &lt;IRLibDecodeBase.h&gt;  //We need both the coding and
#include &lt;IRLibSendBase.h&gt;    // sending base classes
#include &lt;IRLib_P01_NEC.h&gt;    //Lowest numbered protocol 1st
#include &lt;IRLib_P02_Sony.h&gt;   // Include only protocols you want
#include &lt;IRLib_P03_RC5.h&gt;
#include &lt;IRLib_P04_RC6.h&gt;
#include &lt;IRLib_P05_Panasonic_Old.h&gt;
#include &lt;IRLib_P07_NECx.h&gt;
#include &lt;IRLib_HashRaw.h&gt;    //We need this for IRsendRaw
#include &lt;IRLibCombo.h&gt;       // After all protocols, include this
// All of the above automatically creates a universal decoder
// class called "IRdecode" and a universal sender class "IRsend"
// containing only the protocols you want.
// Now declare instances of the decoder and the sender.
IRdecode myDecoder;
IRsend mySender;

// Include a receiver either this or IRLibRecvPCI or IRLibRecvLoop
#include &lt;IRLibRecv.h&gt;
IRrecv myReceiver(2); //pin number for the receiver

// Storage for the recorded code
uint8_t codeProtocol;  // The type of code
uint32_t codeValue;    // The data bits if type is not raw
uint8_t codeBits;      // The length of the code in bits

//These flags keep track of whether we received the first code 
//and if we have have received a new different code from a previous one.
bool gotOne, gotNew; 

/* Buttons */ 
// button -&gt; pin number
const int playBtn = 8;
const int recBtn = 9;
// hold the button states 
int playBtnState = 0;
int recBtnState = 0;

// status LED
const int ledPin = 13;

void setup() {
  gotOne=false; gotNew=false;
  codeProtocol=UNKNOWN; 
  codeValue=0; 
  /* BTNS AND LED */
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
  pinMode(playBtn, INPUT);
  pinMode(recBtn, INPUT);
  
  Serial.begin(9600);
  Serial.println(F("Send a code from your remote and we will record it."));
  Serial.println(F("Type any character and press enter. We will send the recorded code."));
  Serial.println(F("Type 'r' special repeat sequence."));
  myReceiver.enableIRIn(); // Start the receiver
}

// Stores the code for later playback
void storeCode(void) {
  gotNew=true;    gotOne=true;
  codeProtocol = myDecoder.protocolNum;
  Serial.print(F("Received "));
  Serial.print(Pnames(codeProtocol));
  if (codeProtocol==UNKNOWN) {
    Serial.println(F(" saving raw data."));
    myDecoder.dumpResults();
    codeValue = myDecoder.value;
  }
  else {
    if (myDecoder.value == REPEAT_CODE) {
      // Don't record a NEC repeat value as that's useless.
      Serial.println(F("repeat; ignoring."));
    } else {
      codeValue = myDecoder.value;
      codeBits = myDecoder.bits;
    }
    Serial.print(F(" Value:0x"));
    Serial.println(codeValue, HEX);
  }
}
void sendCode(void) {
  if( !gotNew ) {//We've already sent this so handle toggle bits
    if (codeProtocol == RC5) {
      codeValue ^= 0x0800;
    }
    else if (codeProtocol == RC6) {
      switch(codeBits) {
        case 20: codeValue ^= 0x10000; break;
        case 24: codeValue ^= 0x100000; break;
        case 28: codeValue ^= 0x1000000; break;
        case 32: codeValue ^= 0x8000; break;
      }      
    }
  }
  gotNew=false;
  if(codeProtocol== UNKNOWN) {
    //The raw time values start in decodeBuffer[1] because
    //the [0] entry is the gap between frames. The address
    //is passed to the raw send routine.
    codeValue=(uint32_t)&amp;(recvGlobal.decodeBuffer[1]);
    //This isn't really number of bits. It's the number of entries
    //in the buffer.
    codeBits=recvGlobal.decodeLength-1;
    Serial.println(F("Sent raw"));
  }
  mySender.send(codeProtocol,codeValue,codeBits);
  if(codeProtocol==UNKNOWN) return;
  Serial.print(F("Sent "));
  Serial.print(Pnames(codeProtocol));
  Serial.print(F(" Value:0x"));
  Serial.println(codeValue, HEX);
}

void loop() {

  recBtnState = digitalRead(recBtn);
  playBtnState = digitalRead(playBtn);
  
  if(recBtnState == HIGH ) {
    digitalWrite(ledPin, LOW);
    myDecoder.decode();
    // Re-enable receiver
    myReceiver.enableIRIn(); 
    digitalWrite(ledPin, HIGH);
  }

  if(playBtnState == HIGH) {
    // check for stored signal
    if(gotOne) {
      // send the IR Code
      sendCode();
      // re-enable receiver
      myReceiver.enableIRIn();
      digitalWrite(ledPin, LOW);
    }
  }
  
  
}

```

# Not Working?
### 

Try opening the Arduino Serial Monitor. There are&nbsp;`Serial.print()` **&nbsp;** statements in this code to help you debug.

### 

Make sure your&nbsp; **NPN Transistor&nbsp;** is hooked up correctly, it is required for this circuit.

### 

[This circuit is especially tricky because the Infrared Sensor and Receiver&nbsp;are kinda finicky, post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Parts

Danger: 

### **Adafruit Metro _Express_ + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[Need an&nbsp;extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro&nbsp;Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop?

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/943/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1500402357)

# Experimenter's Guide for Metro

## Wiring for Metro Express

![](https://cdn-learn.adafruit.com/assets/assets/000/043/925/medium800/adafruit_products_circ18_bb.png?1500312166)

There's nothing to breadboard! The Metro Express has all the circuit required on the board (including the NeoPixel!). The NeoPixel is assigned to **Digital Pin 40** on the Metro Express

# Experimenter's Guide for Metro

## Code

## Installing the NeoPixel Library&nbsp;
Before copying and pasting the code, you'll need to install the NeoPixel Library. This is much easier than the installation of the IR Library - you can install the NeoPixel library directly from&nbsp;the IDE!

![](https://cdn-learn.adafruit.com/assets/assets/000/043/945/medium800/adafruit_products_managelibs.png?1500403353)

In Arduino, go to **Sketch \> Include Library \> Manage Libraries.**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/947/medium800/adafruit_products_neoselect.png?1500403641)

In the library manager, search for **NeoPixel**.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/946/medium800/adafruit_products_neopixellib.png?1500403384)

Then, **find the latest version** (1.1.1 at time of writing) **and click install**.&nbsp;

Once the status bar is finished, r **estart the Arduino IDE**. The NeoPixel library has been installed.&nbsp;

## Code
Copy/Paste the code below.&nbsp;Then,&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).&nbsp;

You should see your Metro's NeoPixels light up red, white, and blue.&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC18_NEOPIXEL/CIRC18_NEOPIXEL.ino

# Having trouble?
### 

Make sure that the NeoPixel library was correctly installed to the right location.&nbsp;

### 

You must have&nbsp;a **Metro** , not a **Metro Express**. This circuit only works with the Metro **Express**.

### 

[Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

## Dimming the NeoPixel
Wow that NeoPixel sure is bright, huh? There is a really simple way to dim it. The NeoPixel takes a value from 0 to 255, 255 being the brightest.&nbsp;

Let's dim it by 100. In your code, change:

`const int RED[] = {255, 0, 0};` **to** `const int RED[] = {155, 0, 0};`

Still too bright? Let's cut it by 1/3rd by changing:

`const int GREEN[] = {128, 255, 0};` to `const int GREEN[]= {128/3, 255/3, 0};`

## NeoPixel Glance Thermometer
We're going to modify the thermometer circuit to use the NeoPixel to assemble a color-coded thermometer. Glance over at this circuit and see the color which corresponds&nbsp;to a specific temperature.

## Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/043/954/medium800/adafruit_products_circ18_MIB_bb.png?1500410754)

The wiring for this circuit is easy - just wire up the temperature sensor.&nbsp;

## Code
Copy/paste the code below. Then, compile and upload it to your Metro Express!

```
/*
 * CIRC18 Make It Better
 * NeoPixel Glance Thermometer - check the weather super quickly!
 * 
 * by Brent Rubell for Adafruit Industries
*/

 // Include the Adafruit Neopixel Library 
#include &lt;Adafruit_NeoPixel.h&gt;

// The default pin for the NeoPixel on the Metro Express is Pin #40
#define METROPIXELPIN            40

// Temperature Sensor
const int temperaturePin = A0; 

// metroPixel takes in both the number of pixels (1, the built-in) and the pin)
Adafruit_NeoPixel metroPixel = Adafruit_NeoPixel(1, METROPIXELPIN);
float temperature = 0;

/* Temperature Colors */
const int RED[ ] = {255, 0, 0};
const int ORANGE[ ] = {255, 153, 51};
const int YELLOW[ ] = {255, 255, 0};
const int LIGHTGREEN[ ] = {128, 255, 0};
const int DARKGREEN[ ] = {76, 153, 0};
const int DARKBLUE[ ] = {0, 0, 255};
const int DARKPURPLE[ ] = {51, 0, 102};
const int BLACK[ ] = {0, 0, 0};

void setup()
{
  // Start the Serial at 9600 baud
  Serial.begin(9600);
  // init the neopixel library   
  metroPixel.begin();
}
 
void loop()                     
{
 temperature = getVoltage3V(temperaturePin);
 // Convert to degrees C
 temperature = (temperature - .5) * 100;          
 // print the temperature in C to the serial                                                
 Serial.println(temperature); 
 // temp &lt;-&gt; color picker       
 if (temperature &gt; 40) {
  // red
  pixelWrite(RED);
 }
 else if (temperature &gt; 35) {
   // orange
   pixelWrite(ORANGE);
 }
 else if (temperature &gt; 30) {
   // yellow
   pixelWrite(YELLOW);
 }
 else if (temperature &gt; 25) {
   // yellow
   pixelWrite(LIGHTGREEN);
 }
 else if (temperature &gt; 20) {
   // dark green
   pixelWrite(DARKGREEN);
 }
 else if (temperature &gt; 5) {
   // dark blue
   pixelWrite(DARKBLUE);
 }
 else {
   // dark purple
   pixelWrite(DARKPURPLE);
 }
 delay(1000);                                     
}

// takes in a pre-defined color (integer array) and sets the pixel to that color
void pixelWrite(const int* color) { 
  metroPixel.setPixelColor(0, metroPixel.Color(color[0],color[1],color[2]));
  // write the pixel color to the Metro's Neopixel
  metroPixel.show(); 
}

// Voltage to temperature if Vs= 3.3V
float getVoltage3V(int pin){
 // 3.3V/1023
 return (analogRead(pin) * 0.003225806452); 
}
```

## Adding the NeoPixel to CIRCs
The Glance Thermometer is a modification of the temperature circuit. Which CIRCs have you completed? How would you add a NeoPixel to the circuit to increase functionality, utility or aesthetic?

# Experimenter's Guide for Metro

## Parts

Info: 

### **Breadboard Trim Potentiometer - 10k**

&nbsp;

[If you'd like to buy an extra trimpot from the Adafruit store, click here!](https://www.adafruit.com/product/356)

![adafruit_products_Potentiometer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/000/medium640/adafruit_products_Potentiometer_White_Background_ORIG.jpg?1500477699)

### **Pushbutton**

&nbsp;

[If you'd like to order more pushbuttons from the Adafruit shop, click here!](https://www.adafruit.com/product/367)

![adafruit_products_12mm_button_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/002/medium640/adafruit_products_12mm_button_iso_White_Background_ORIG.jpg?1502222129)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

### &nbsp;
![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/044/003/medium640/adafruit_products_10kohm.png?1500477921)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/002/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1500477812)

### **Adafruit Metro _Express_ + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[Need an&nbsp;extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro&nbsp;Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop?

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/005/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1500478013)

# Experimenter's Guide for Metro

## Wiring

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/999/medium800/adafruit_products_circ19_bb.png?1500476222)

# Experimenter's Guide for Metro

## Code

The USB-HID Library is built into Arduino, there is no external installation required. Verify that you have a Metro Express, then copy and paste the code below into the Arduino Editor. Then, compile and upload.

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/CIRC19_USB_BLOG_BUDDY/CIRC19_USB_BLOG_BUDDY.ino

# Using USB Blog Buddy
[Head over to the Adafruit Blog to test your circuit out!](https://blog.adafruit.com/)

When you press the push button, the Metro Express will take control of your mouse and start scrolling the mouse wheel.&nbsp;

 **Scroll Page Up:&nbsp;** Move the potentiometer such that the arrow on it faces towards the top of the breadboard

**Scroll Page Down:&nbsp;** Move the potentiometer such that the arrow on it faces towards the bottom&nbsp;of the breadboard

# Not Working?
### 

Check your wiring, the library for USB interfacing&nbsp;is built into Arduino and should automatically start when you upload this code.&nbsp;

### 

[Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Parts

## **If you're using a Metro Classic:**
You'll need a&nbsp; **1M Ohm Resistor.&nbsp;**

## **If you're using a Metro M0 Express:**
You're dont need any new parts, the M0 Express the capacitive sensor stuff managed completely inside the chip!

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275),&nbsp;[Adafruit Metro](https://www.adafruit.com/product/2488),&nbsp;[Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or&nbsp;[Mini-Breadboard](https://www.adafruit.com/product/64)&nbsp;from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/471/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1503073716)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/472/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1503073802)

# Experimenter's Guide for Metro

## Wiring

## Wiring for the Metro Classic
![](https://cdn-learn.adafruit.com/assets/assets/000/045/468/medium800/adafruit_products_CIRC20_bb.png?1503073224)

Warning: 

You'll want to be using a&nbsp; **1M Ohm Resistor&nbsp;** for this Circuit. The pin extending from the sensor pin (in our case, it's&nbsp; **Digital Pin 2** ), should ideally be&nbsp;a short pin from the Breadboarding Bundle.

 **1M Ohm Resistor Color Band:&nbsp;Brown \> Black \> Green \> Silver**

# Wiring for the Metro Express
![](https://cdn-learn.adafruit.com/assets/assets/000/045/470/medium800/adafruit_products_CIRC20-express.png?1503073569)

You **don't** need a&nbsp; **1M Ohm&nbsp;** resistor for this circuit, just a smaller value (like the 560 ohm included in the MetroX Classic and MetroX Express kits). The Metro Express has 1M Ohm pull-up resistor values on-board. &nbsp;

# Experimenter's Guide for Metro

## Wiring for Metro Express

![](https://cdn-learn.adafruit.com/assets/assets/000/045/504/medium800/adafruit_products_CIRC20-express_bb.png?1503087805)

# Experimenter's Guide for Metro

## Code

You'll need to download install the CapacitiveSensor Library.

Open up the Arduino library manager:

![](https://cdn-learn.adafruit.com/assets/assets/000/083/168/medium800/adafruit_products_library_manager_menu.png?1572316263)

Search for&nbsp; **capacitivesensor&nbsp;** and install it

![](https://cdn-learn.adafruit.com/assets/assets/000/083/171/medium800/adafruit_products_capacitive_sensor_%281%29.png?1572317628)

# Code
After downloading and installing the CapacitiveSensor Library, copy and paste the code below into the Arduino IDE. Then, compile and upload it to your Metro (or Metro Express).

```
/*
 * CIRC20 - Capacitive Sensing with the Metro and Metro M0 Express
 * 
 * by Brent Rubell for Adafruit Industries.     Support Open Source Hardware, Buy Adafruit!
 */
#include &lt;CapacitiveSensor.h&gt;

// piezo speaker pin
int piezoPin = 9;

// 10M resistor between pins 4 &amp; 2, pin 2 is sensor pin, add a wire and or foil if desired
// put a 10M resistor between pins 4 &amp; 2, pin 2 is the sensor pin, 4 is the receiver 
CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);        

void setup()                    
{
   cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);
   Serial.begin(9600);
   // set the piezo as an output
   pinMode(piezoPin, OUTPUT);
}

void loop()                    
{
    long start = millis();
    long pinTone =  cs_4_2.capacitiveSensor(30);

    Serial.print("sensor value: ");        // check on performance in milliseconds
    Serial.print("\t");                    // tab character for debug windown spacing
    Serial.print(pinTone);                  // print sensor output 1
    Serial.print("\n");

    // map the tone value to frequencies between 500 and 2000
    long mapTone = map(pinTone, 0, 40, 500, 2000);
    // play the mapped tone
    playTone(int(mapTone), 100);
    delay(10);
}

void playTone(int tone, int duration) {
  for (long i = 0; i &lt; duration * 1000L; i += tone * 2) {
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(tone);
  }
}

```

# I'm having problems with this CIRC
### 

Open up the Arduino Serial Monitor. What do you see as the largest&nbsp;`sensor value` when you press the pin? The smallest? In the lien below, replace the values for&nbsp;`MIN_SENSOR_VALUE` and `MAX_SENSOR_VALUE` with the two&nbsp;_numeric_ values you found:

&nbsp; &nbsp; &nbsp;`long mapTone = map(pinTone, MIN_SENSOR_VALUE, MAX_SENSOR_VALUE, 500, 2000);`

### 

When you open the Arduino Serial Monitor, do you see values of **0** or - **2**? The resistor you're using might be too small. We advise using a 1M Ohm resistor, not the 10K Ohm Resistor. That's **one** &nbsp; **million** &nbsp; **ohms.&nbsp;** If you don't have any 1M Ohm resistors, you can use any other similar (really large) resistor.&nbsp;

### 

[Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

## Using Different Input Types
You can use many different types of inputs for the capacitive sensor. Among these are everything from Apples, salt water, and utensils (depending on the material). You can also use some of the different conductive materials from the Adafruit shop like [Conductive Rubber,](https://www.adafruit.com/product/519) [Woven Conductive fabric (try using this for wearable projects)](https://www.adafruit.com/product/1168), or even [conductive paint pens to turn any material into a conductive one](https://www.adafruit.com/product/1306).

## Adding Sensor Inputs
Need more inputs? You can continue using&nbsp; **Digital Pin 4&nbsp;** for your receiver pin and any other digital pin can be used to create a capacitive sensor. &nbsp;

To do this, just add a line in your code:

&nbsp; &nbsp; &nbsp;`CapacitiveSensor   cs_4_# = CapacitiveSensor(4,#);` &nbsp; &nbsp;&nbsp;

You'll need to replace `#` with the&nbsp; **Digital Pin Number&nbsp;** you want used as a sensor.

We're using&nbsp; **Digital&nbsp;Pin 4&nbsp;** as the Receiver and **Digital Pin 8** as the new sensor, so here's&nbsp;is how your breadboard should look:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/475/medium800/adafruit_products_CIRC20_bb0moar-sensors.png?1503074927)

# Experimenter's Guide for Metro

## PROJ01: Theremin

![](https://cdn-learn.adafruit.com/assets/assets/000/044/592/medium800thumb/adafruit_products_1080p.jpg?1501535435)

You are going to become a **Thereminist**! One of the stranger instruments out there is a&nbsp;[Theremin](https://en.wikipedia.org/wiki/Theremin), an electronic instrument where you can wave your hands and make music! You are going to make one of your own, using your knowledge from previous CIRCs to guide you.

# Experimenter's Guide for Metro

## Parts

### **Photo Sensor**

&nbsp;

[If you'd like to order another photoresistor from the Adafruit shop, click here!](https://www.adafruit.com/product/2831)

![adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/003/medium640/adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg?1502222150)

### **Piezo&nbsp;**** Buzzer**

&nbsp;

[If you'd like to order another Pizeo Buzzer from the Adafruit shop, click here!](https://www.adafruit.com/product/160)

![adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/772/medium640/adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg?1499704116)

### **560 Ohm Resistor**

**Colors:** &nbsp; **Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/774/medium640/adafruit_products_560ohm.png?1499704309)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/773/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499704143)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/877/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1499893058)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/043/779/medium800/adafruit_products_quest01_bb.png?1499704659)

# Experimenter's Guide for Metro

## Wiring for Metro Express

![](https://cdn-learn.adafruit.com/assets/assets/000/043/777/medium800/adafruit_products_quest01_bb.png?1499704406)

# Experimenter's Guide for Metro

## Code

## Setting Pins
```
int piezoPin = 9;
int photoLightSensorPin = A0;
```

The pins for both the piezo and the photo light sensor are both declared as&nbsp;_integer_ types. The A in front of the photo light sensor stands for&nbsp;_analog.&nbsp;_

## Reading the photo light sensor
```
void loop() {
  //  get photo sensor value
  int photoVal = analogRead(photoLightSensorPin);
}
```

The photo light sensor is read within the `loop().` We restricted the `photoVal` to integer values only (no decimal points). Then, an `analogRead()` was called on the photo light sensor pin to read pin data.

## Creating the Pitch
```
int pitch = map(photoVal, 190, 1100, 150, 1500);
```

The pitch variable is created to store the resulting pitch. Then, map() is called. This function takes in photoVal and photoVal's lower and upper values. Then, it maps that range to a range within 150Hz and 1500Hz

## Playing the Pitch
```
// play tone 
tone(piezoPin, pitch);
```

Tone() is passed both the pin with the Piezo and the pitch integer generated before.

The complete&nbsp;theremin code is below. Copy and paste it into a blank Arduino sketch, then compile and upload!

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ01_THEREMIN/PROJ01_THEREMIN.ino

Move your hand around the circuit to play music with your theremin! Congrats, you just built your first quest circuit.

Bored of this theremin? Let's **Make It Better!**

# Wait...my PROJect doesn't work!
### 

Check the wiring of both the piezo and the light sensor. You might find flipping the light sensor around will fix it.

### 

[We'll help you out! Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

## Modifying the pitch

Taking a look at how `map()` works in the Theremin quest circuit, you&nbsp;can start to understand how map works:

`map(value, fromLow, fromHigh, toLow, toHigh); `to&nbsp;`map(photoVal, 190, 1100, 150, 1500);`

The first two values correspond to the photo light sensor, while the last two are the pitch. Try modifying the last two values (150 and 1500) up and down. You'll get different sounds every time!

## Stop the Music!

You may have gotten annoyed with the spooky sounds coming out of your theremin. There are two ways to stop this sound.

One way to do this is with&nbsp;a push-button. Plug one into your breadboard and wire it up to&nbsp; **Digital Pin 2:**

![](https://cdn-learn.adafruit.com/assets/assets/000/043/482/medium800/adafruit_products_quest01-pushbutton_bb.png?1499285626)

Next, modify the Arduino code to call&nbsp;NoTone()&nbsp;when the button is pressed. We'll leave this up to you to figure out. One hint is to look at both the [NoTone() documentation](https://www.arduino.cc/en/Reference/NoTone) and CIRC07's code.

# Experimenter's Guide for Metro

## PROJ02: MetroPOV Display

![](https://cdn-learn.adafruit.com/assets/assets/000/043/794/medium800/adafruit_products_ada.png?1499782217)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/809/medium800thumb/adafruit_products_IMG_2730.jpg?1500954101)

 **Persistence of vision** refers to the optical illusion that occurs when visual perception of an object does not cease for some time after the rays of light proceeding from it have ceased to enter the eye ([more about persistence of vision here](https://en.wikipedia.org/wiki/Persistence_of_vision)).&nbsp;

One of the cool kits made by Adafruit is the [MiniPOV 4](https://www.adafruit.com/product/1776), a DIY Full-Color POV Display. The MiniPOV creates&nbsp;this illusion and allows you to paint&nbsp; **with light** in mid-air. In this quest, you are going to create the **MetroPOV** , a circuit that uses Persistence of Vision and the Adafruit Metro. You'll learn about persistence-of-vision, optical illusions, and create your own drawings.&nbsp;

Let's paint the sky with the Metro!

# Experimenter's Guide for Metro

## Parts

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_greenled_(1).png](https://cdn-learn.adafruit.com/assets/assets/000/043/748/medium640/adafruit_products_greenled_%281%29.png?1499700911)

### **560 Ohm Resistor**

**Colors: Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/750/medium640/adafruit_products_560ohm.png?1499701238)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/782/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499709528)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/697/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695452)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/043/757/medium800/adafruit_products_QUESTPOV.png?1499701890)

The breadboard circuitry is similar to CIRC02's layout. We suggest either using the Red 5mm LEDs or Green 5mm LEDs. Pick your favorite color and use that!

![](https://cdn-learn.adafruit.com/assets/assets/000/043/810/medium800thumb/adafruit_products_IMG_2731.jpg?1500953615)

The 9V battery + clip is very handy for this circuit. You can stick&nbsp;it on the back of the mounting plate with double-sided tape.&nbsp;

# Experimenter's Guide for Metro

## Code

Copy and paste the code below into the Arduino IDE. Then,&nbsp;[compile and upload it to your metro](../../../../experimenters-guide-for-metro/parts-2#compile-and-upload).

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ02_METROPOV/PROJ02_METROPOV.ino

# I need help
### 

Try checking the next section of&nbsp;this guide. We suggest some techniques, and even an app.&nbsp;

### 

Check your wiring, the led's are connected to pins&nbsp;2, 3, 4, 5, 6, 7, 8, and 9 on the Metro or Metro Express

### 

Don't fear,&nbsp;[post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Using MetroPOV

## Taking Photos
It's a bit tricky to get photos of the MetroPOV in-action. We have a few tricks and tips to help photograph your MetroPOV:

 **Stability and Shutter Speed:&nbsp;** Leave the shutter open (we found 2" to 4" is a good time-frame) or look for long-exposure apps on the app store.&nbsp;Since your camera's sensor/shutter is open, it's important to keep the camera stable. Use a tripod, or leave it on a sturdy desk.

 **Keep the light down:&nbsp;** It's very hard to get good photos of the MetroPOV operating in a bright environment. Wait for night-time or find a dark room (we used a room with all of the lights off when taking photos for this guide).&nbsp;

## GIF'ing your MetroPOV Text
You can make animated GIFS by combining multiple long-exposure pictures together in the photo editor of your choice. We also found success using Pablo, a fantastic light-painting application for [iOS](https://itunes.apple.com/us/app/pablo/id1114954184?mt=8) and [Android](https://play.google.com/store/apps/details?id=com.hipablo.pablo&hl=en). Tinker around with settings (specifically shutter speed and exposure) until you find one that looks great.

## Light Painting with MetroPOV
![](https://cdn-learn.adafruit.com/assets/assets/000/043/796/medium800/adafruit_products_light3.png?1499785700)

Mistakes while taking photos can often produce beautiful art. Try drawing letters with the MetroPOV and move it around. Ride a skateboard while someone takes a picture of you, spin in a chair.&nbsp;Experiment and try different techniques and ideas!

# Experimenter's Guide for Metro

## PROJ03: Music Box

![](https://cdn-learn.adafruit.com/assets/assets/000/043/781/medium800thumb/adafruit_products_IMG_2690.jpg?1499709272)

Music boxes are clockwork mechanical instruments that play music when opened. **You are going to take the Music Box into the 21st Century** - instead of programming the music box by modifying a metal cylinder, you will be programming a beautiful song to the Metro. **When opened** , the music box will play a song and the LCD will show the notes as they&nbsp;play.

This project&nbsp;is customizable&nbsp;in a few ways: you can use your own box (maybe you have a jewelry box, an old cigar box, or an Adafruit box) and/or program your own music.

# Experimenter's Guide for Metro

## Parts

### **Photo Sensor**

&nbsp;

[If you'd like to order another photoresistor from the Adafruit shop, click here!](https://www.adafruit.com/product/2831)

![adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/484/medium640/adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg?1503076194)

### **16x2 Character LCD**

&nbsp;

[If you'd like to buy a white-on-blue 16x2 character lcd from the Adafruit shop, click here!](https://www.adafruit.com/product/1447)

![adafruit_products_Screen_White_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/645/medium640/adafruit_products_Screen_White_Background.jpg?1501608568)

### **Piezo&nbsp;**** Buzzer**

&nbsp;

[If you'd like to order another Pizeo Buzzer from the Adafruit shop, click here!](https://www.adafruit.com/product/160)

![adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/798/medium640/adafruit_products_Piezo_Buzzer_White_Background_ORIG.jpg?1499788812)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/045/465/medium640/adafruit_products_10kohm.png?1503069928)

### **Breadboard Wiring Bundle**

&nbsp;

[&nbsp;If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/799/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499788867)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/698/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695479)

# Experimenter's Guide for Metro

## Wiring

## Diagram
![](https://cdn-learn.adafruit.com/assets/assets/000/043/804/medium800/adafruit_products_quest05_bb.png?1499790234)

# Assembly
If you want to use an Adafruit box (or any other cardboard box),&nbsp;there are modifications to make your circuit fit better.

First, place the circuit in the center of the box. You can tape it down to temporarily keep it in place.

&nbsp;

![adafruit_products_IMG_2742.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/806/medium640/adafruit_products_IMG_2742.jpg?1499791855)

Warning: 

Next, cut a small rectangle into the side to fit the USB cable. Be careful while cutting

![adafruit_products_IMG_2747.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/807/medium640/adafruit_products_IMG_2747.jpg?1499791931)

Finally, pull the wire through the hole you cut and connect it to the Metro.

![adafruit_products_IMG_2749.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/808/medium640/adafruit_products_IMG_2749.jpg?1499791979)

# Experimenter's Guide for Metro

## Code

# Calibrating the Music Box
In order to get an accurate reading, close the music box and run the code below. Then, open your serial monitor. It should output the light level, this is the darkest the box will get so we'll calibrate this value. &nbsp;

**In your code, change the following line:**

**`int dark = 650;` -\> `int dark = your measured value`**

When you re-run the code, the serial monitor should print _"box closed.."_ when the box is closed. If you wired the backlight to Pin 13, the LCD backlight should also turn off.

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ03_MUSIC_BOX/PROJ03_MUSIC_BOX.ino

# Encountering Problems?
### 

Check the LCD Wiring guide in CIRC14 to double-check everything is wired correctly.&nbsp;

### 

 **`int dark`&nbsp;** directly controls how dark or bright the environment inside your music box is. If you find it triggering too easily, decrease its value.&nbsp;

### 

[We'll help you out! Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

Bored of your Music Box? Want to go add onto this circuit? Here's some ideas for you to springboard off of and learn new skills in the process

# Music Composer
Write your own melody and become a composer, or adapt an older song to play on the piezo. (_tip_:&nbsp;Check CIRC06's Make It Better section for more details on the piezo speaker)

# Unconventional Enclosures
There are _thousands_ of ways to enclose your electronics projects! Using non-conventional enclosures, such as cigar boxes, are a way to both protect your project and make it look nicer. Try using a different box to hold your music box. &nbsp;

 **Hint** : What should you change in order to use a new box with a light sensor? Take a look at the code section.

**Answer** : Re-calibrating the light sensor is required. Change the value of int dark to the new darkness value.

# Annoy-a-Box
Want to annoy your friends and family with this circuit? Change the code to use a high pitched whine, or make the whine go between pitches like a bee. Make it portable and throw it under a couch.&nbsp;

# Secret Message&nbsp;Box
You need to deliver a secret message to somebody, but writing too permanent. The time-sensitive box is a box to deliver to a friend, classmate, or an international spy containing a secret message on the character lcd.

**How it works:** Once the box is opened, the timer starts to count down the time remaining on the second line of the LCD while the message is displayed. Once the timer runs out, the character lcd clears the message and you cant show the message again.&nbsp;

# Experimenter's Guide for Metro

## PROJ04: Fidget Spinner Tachometer

![](https://cdn-learn.adafruit.com/assets/assets/000/043/898/medium800thumb/adafruit_products_IMG_2861.jpg?1501747766)

Fidget spinners are fun toys that help relieve stress. They spin on a bearing, and can reach&nbsp;_really_ high _revolutions per minute_ (RPM). We are going to build a _Tachometer_, an instrument which measures RPM, for your fidget spinner.

We included some fun features into [Tony D's original Circuit Playground fidget spinner code](../../../../fidget-spinner-tachometer)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/899/medium800/adafruit_products_IMG_2855.jpg?1499979277)

Like a RPM high score game&nbsp;to compete with your friends (or to pit different spinners against each other)

![](https://cdn-learn.adafruit.com/assets/assets/000/043/897/medium800thumb/adafruit_products_IMG_2862.jpg?1501746666)

And a countdown clock to let you time your spins better.

# Experimenter's Guide for Metro

## Parts

### **5mm Red LED**

&nbsp;

[If you'd like to order more red LEDs (they make great indicator lights!) from the Adafruit shop, click here!](https://www.adafruit.com/product/299)

![adafruit_products_redled_(1).png](https://cdn-learn.adafruit.com/assets/assets/000/043/891/medium640/adafruit_products_redled_%281%29.png?1499977656)

### **Photo Sensor**

&nbsp;

[If you'd like to order another photoresistor from the Adafruit shop, click here!](https://www.adafruit.com/product/2831)

![adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/004/medium640/adafruit_products_2831_light_sensor_iso_White_Background_ORIG.jpg?1502222171)

### **560 Ohm Resistor**

**Colors:** &nbsp; **Green \> Blue \> Brown**

&nbsp;

[If you'd like to order more resistors from the Adafruit shop click here! (they&nbsp;are 470ohm but they'll be fine)](https://www.adafruit.com/product/2781)

![adafruit_products_560ohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/893/medium640/adafruit_products_560ohm.png?1499977859)

### **10K Ohm Resistor**

**Colors: Brown \> Black \> Orange**

&nbsp;

[If you'd like to order more 10k ohm pull-up resistors from the Adafruit shop, click here!](https://www.adafruit.com/product/2784)

![adafruit_products_10kohm.png](https://cdn-learn.adafruit.com/assets/assets/000/043/894/medium640/adafruit_products_10kohm.png?1499977967)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/043/895/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1499978010)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), [Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/699/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501695501)

# Experimenter's Guide for Metro

## Wiring

## Diagram
![](https://cdn-learn.adafruit.com/assets/assets/000/043/887/medium800/adafruit_products_quest02_bb.png?1499967061)

## Assembly Tips
Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/043/888/medium800/adafruit_products_IMG_2847.jpg?1499967165)

There is a bit of clean-up involved with this wiring. Spinners snag onto wires. We tried to make the clean-up as simple as possible by utilizing&nbsp;the parts from your&nbsp;kit.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/889/medium800/adafruit_products_IMG_2848.jpg?1499967314)

First, let's clean up the Spin Zone. The area in-between the light-sensor and the LED is the area for the spinner to move around. We suggest using the&nbsp; **long wires&nbsp;** included in the breadboard wiring bundle. Tuck the wires in underneath the board and use a piece of tape (or in our case, a quality control sticker) to pin them down.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/043/890/medium800/adafruit_products_IMG_2845.jpg?1499967415)

Next, take a shorter breadboarding wire and wrap it around the wires for the LCD. You can also use a zip-tie for a more permanent hold. Plug the ends of this wire into the breadboard.&nbsp;

# Experimenter's Guide for Metro

## Code

Copy/Paste the following code into a blank Arduino sketch. Then, compile and upload it to your Metro. If you see the LED running through the script, continue to the next page. If you're not seeing it work properly, check the FAQ below for help.

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ04_TACHOMETER/PROJ04_TACHOMETER.ino

## Not Working?
### 

Make sure all your wires are both plugged in correctly and not loose. During the assembly step where you tied everything together, make sure everything is snugly plugged into both the Metro and the breadboard.&nbsp;

### 

Check the LED wiring. Possibly you have a wrong resistor value.

### 

Post up on our community support forums!

# Experimenter's Guide for Metro

## Parts

Info: 

# **IR Sensor**

**How it's used:&nbsp;** The IR Sensor&nbsp; **receives and decodes incoming infrared signals** from the Adafruit Mini Remote.&nbsp;

&nbsp;

[If you'd like to order an extra IR receiver sensor from the Adafruit shop, click here!](https://www.adafruit.com/product/157)

![adafruit_products_ir-rcv.png](https://cdn-learn.adafruit.com/assets/assets/000/044/573/medium640/adafruit_products_ir-rcv.png?1501511138)

# Mini Remote Control

How it's used: The Mini Remote control will&nbsp; **send** &nbsp; **ir signals&nbsp;** to the ir sensor connected to the Metro M0 Express.

[If you'd like to order an extra Mini Remote Control from the Adafruit Shop, click here!](https://www.adafruit.com/product/389)

![adafruit_products_IR-REMOTE.png](https://cdn-learn.adafruit.com/assets/assets/000/044/577/medium640/adafruit_products_IR-REMOTE.png?1501511814)

# Mini-USB Cable

Make sure the Mini-USB cable you're using is&nbsp; **charge + data&nbsp;** and not just charge only.

[If you'd like to order a Mini-USB Cable from the Adafruit shop click here](https://www.adafruit.com/product/592)

![adafruit_products_Micro_USB_Cable_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/005/medium640/adafruit_products_Micro_USB_Cable_White_Background_ORIG.jpg?1502222244)

### **Breadboard Wiring Bundle**

**How it's used:** We are going to connect a power, ground, and data wire to the 3 pins on the IR sensor.

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/576/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1501511559)

### **Adafruit Metro _Express_ + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[Need an&nbsp;extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro&nbsp;Express](https://www.adafruit.com/product/3505), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop?

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/575/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501511527)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/044/578/medium800/adafruit_products_PROJ08-VLC.png?1501512350)

# Experimenter's Guide for Metro

## Code

We are going to use both the IRLib and Keyboard libraries for this project, so let's figure out how to combine them. This section is self-guided, as in we are going to give you the code piece-by-piece and you can follow along.

First, we want to include both the IRLibAll and Keyboard Libraries:&nbsp;

```
#include &lt;IRLibAll.h&gt;
#include &lt;Keyboard.h&gt;
```

Then, we are going to include the button codes. Since these are long numbers, they[&nbsp;are encoded as hexadecimal values - Colin has a great video about this topic here](../../../../collins-lab-binary-and-hex?view=all).

```
/* Remote Codes */
#define VOLUMEUP      0xfd40bf
#define VOLUMEDOWN    0xfd00ff
#define RIGHT_ARROW   0xfd50af
#define LEFT_ARROW    0xfd10ef
#define PLAYPAUSE     0xfd807f
#define SELECT_BUTTON 0xfd906f

```

We are going to define NEC as the protocol used by the Adafruit Mini remote, then create a receiver on digital pin 2. After that, create a decoder object and an integer to hold the previous code for NEC repeat codes.

```
// Adafruit Mini-Remote uses NEC, change this if you're using a different remote
#define MY_PROTOCOL NEC
// receiver on pin 2
IRrecv myReceiver(2);
// Decoder object
IRdecode myDecoder;
// NEC repeat codes for Adafruit Mini-Remote
uint32_t Previous;
```

Lastly, we are going to create a LED object on Pin #13, which is the builtin LED. We are going to use this a way to visually debug our circuit without printing out to the serial monitor.&nbsp;

```
const int ledPin = 13;
```

In the `setup()` loop, we are going to tell the Metro to begin&nbsp;control over the keyboard, start the IR Receiver, and configure the led as an output.&nbsp;

```
void setup() {
  // initialize control over the keyboard
  Keyboard.begin();
  // start the IR receiver
  myReceiver.enableIRIn();
  // configure status LED
  pinMode(LED_BUILTIN, OUTPUT);
}
```

The `loop()` is quite complicated, but we'll break it down to make it easier. We are going to first detect if the receiver gets an input from the remote with `myReceiver.getResults()`. Then, we are going to decode it with a call to `myDecoder.decode()`.&nbsp;

Next, we want to check if the protocol is the same as what's used by the Mini Remote, NEC, by checking `if(myDecoder.protocolNum==MY_PROTOCOL)`. Finally, we are going to detect&nbsp;the repeat codes, and set the current value to the previous decoded value `if(myDecoder.value==0xFFFFFFFF {myDecoder.value=Previous;}`

```
void loop()
{
    if (myReceiver.getResults()) {
       myDecoder.decode();
       if(myDecoder.protocolNum==MY_PROTOCOL) {
         if(myDecoder.value==0xFFFFFFFF)
           myDecoder.value=Previous;

            // handle everything in here
```

Phew, now the fun part begins. [We are going to use a programming concept called a SwitchCase](https://www.arduino.cc/en/Reference/SwitchCase). This will let us take in one value (the value decoded by the decoder -`myDecode.value`) and perform different actions depending on what the value is.&nbsp;

In our case, we are going to switch based on `myDecoder.value`. The first case will be if the PLAYPAUSE button is detected (already #define'd above). We want to send the spacebar key to pause VLC playback.

```
  switch(myDecoder.value) {
           case PLAYPAUSE:
            // key-play-pause
            // send the spacebar key

```

We are going to send 0x20, the spacebar ascii value, to the keyboard with `Keyboard.write().` Then, we are going to turn the LED to signal the key was sent (a&nbsp;_really easy&nbsp;_way to visually debug your code). Next, we are going to delay, then call `Keyboard.releaseAll();` to release the key(s) pressed. Then, we are going to `break;` out of that case and finish execution.

```
            Keyboard.write((char)0x20);
            digitalWrite(LED_BUILTIN, HIGH);
            delay(100);
            // release the keys pressed
            Keyboard.releaseAll();
            break;
```

Now that you get the idea, we are going to provide you with the code. Try the&nbsp;_Make It Better_ section if you'd like to try your hand at understanding this project better.

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ05_IR_MEDIA_CONTROLLER/PROJ05_IR_MEDIA_CONTROLLER.ino

# I'm having trouble with this&nbsp; **Proj** ect
### 

The IRLib 2.x library was improperly installed. Check CIRC16's "Installing the IR Library" page&nbsp;for correct installation instructions.

### 

If you're using the Adafruit Mini-Remote, make sure you un-comment (remove the slashes) the `char ctrlKey`&nbsp;variable for which operating system you're using:

`// use this option for OSX:`  
`char ctrlKey = KEY_LEFT_GUI;`  
`// use this option for Windows and Linux:`  
`// char ctrlKey = KEY_LEFT_CTRL;`

If you're using your own remote control, you'll need to make modifications to the code. Check out this guide on [Sending IR Codes](../../../../using-an-infrared-library/sending-ir-codes?view=all) for more info. &nbsp;

### 

[Post up in the Adafruit Support Forums and we will get back to you as soon as we can.&nbsp;](https://forums.adafruit.com/viewforum.php?f=25)

# Experimenter's Guide for Metro

## Make It Better

We added in some extra buttons for you in the code provided on the last page:

```
// These are some extra button codes...not used in the PROJ.
// if you want to create more functions in VLC or any other app, use these!
#define UP_ARROW      0xfda05f
#define DOWN_ARROW    0xfdb04f
#define BUTTON_0      0xfd30cf
#define BUTTON_1      0xfd08f7
#define BUTTON_2      0xfd8877
#define BUTTON_3      0xfd48b7
#define BUTTON_4      0xfd28d7
#define BUTTON_5      0xfda857
#define BUTTON_6      0xfd6897
#define BUTTON_7      0xfd18e7
#define BUTTON_8      0xfd9867
#define BUTTON_9      0xfd58a7
```

If you'd like to use these for different commands within VLC, or maybe control Netflix or Youtube, check out the [Arduino Modifier Keys Documentation](https://www.arduino.cc/en/Reference/KeyboardModifiers). Implement new keys, or modify your pre-existing cases within the SwitchCase to use different keys.

# Experimenter's Guide for Metro

## PROJ06: IR Laser Pet Toy

![](https://cdn-learn.adafruit.com/assets/assets/000/044/591/medium800thumb/adafruit_products_out.jpg?1501534311)

Do you want to annoy your (or your family's) pets? Maybe you want to exercise your pet in the laziest way possible? You are going to build a laser pet toy controlled by your IR remote and the Adafruit Metro.

Here's how it's going to work: a cheap-o laser pointer is affixed to the servo horn. You'll mount the servo to your breadboard with double-sided tape to give it a solid base. Then, you'll wire up your infrared sensor along with the servo and code a program that lets you annoy/exercise your pets from a safe distance

Danger: 

The laser pointer dot can drive both cats&nbsp;and dogs towards obsessive&nbsp;behavior because it can seek&nbsp;out the "prey" instinct in your pet. We strongly suggest&nbsp;hiding a few food treats around the room, and then letting the IR Laser Pet Toy move in the direction of the food. **Your dog/cat needs to be rewarded for chasing what they consider to be their prey.&nbsp;**

We also advise both you and your pet to avoid any direct eye exposure with the laser. Keep the laser on during play with the animal to avoid them looking at the light (switching it off/turning it on will make them turn around quickly). &nbsp;

# Experimenter's Guide for Metro

## Parts

Info: 

This PROJect requires a laser **pointer**. We do&nbsp; **not** recommend using the Laser **Diodes** we sell in the Adafruit shop. Your corner store, or Amazon, sells a very low-powered laser **pointer**.

The IR Receiver is used to receive infrared signals from the remote. These signals will then be sent to the Metro, which will tell the servo where to move.

![adafruit_products_ir-rcv.png](https://cdn-learn.adafruit.com/assets/assets/000/044/454/medium640/adafruit_products_ir-rcv.png?1501276852)

The Mini Remote contains an IR LED to transmit signals to the IR Receiver connected to the Metro M0.&nbsp;

![adafruit_products_IR-REMOTE.png](https://cdn-learn.adafruit.com/assets/assets/000/044/455/medium640/adafruit_products_IR-REMOTE.png?1501276998)

The Hobby Servo will be used as a platform to rotate the laser pointer left and right.&nbsp;

![adafruit_products_Servo_White_BackgroundORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/579/medium640/adafruit_products_Servo_White_BackgroundORIG.jpg?1501515043)

### **Breadboard Wiring Bundle**

&nbsp;

[&nbsp;If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/581/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1501515228)

### **Adafruit Metro + Breadboard + Mounting Plate&nbsp;**

&nbsp;

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275), [Adafruit Metro](https://www.adafruit.com/product/2488), or [Mini-Breadboard](https://www.adafruit.com/product/64) from the Adafruit Shop click here!

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/044/580/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1501515177)

# Experimenter's Guide for Metro

## Wiring

There are two routes for assembly: we can either put a laser pointer on top of the servo and tape the button to turn it on, or we can disassemble it and solder some leads on it so it can be controlled by the Metro.&nbsp;

This wiring is for the first option (non-controlled laser).

![](https://cdn-learn.adafruit.com/assets/assets/000/044/583/medium800/adafruit_products_PROJ06_bb-no-opt.png?1501519124)

This wiring is for the laser controlled by the IR Remote. We are controlling the laser by sending it a voltage from Pin #13.

![](https://cdn-learn.adafruit.com/assets/assets/000/044/584/medium800/adafruit_products_PROJ06_bb-OPT.png?1501519250)

# Experimenter's Guide for Metro

## Assembly

This project&nbsp;requires some assembly (like the music box) for you to get really good performance out of it.&nbsp;

# Servo Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/044/587/medium800/adafruit_products_IMG_3354.jpg?1501531187)

We are going to wire the servo such that the longer wires in your breadboard wiring bundle are used. We want to mount the Servo on&nbsp;

# Base Assembly
![](https://cdn-learn.adafruit.com/assets/assets/000/044/588/medium800thumb/adafruit_products_out.jpg?1501531221)

Take a piece of tape and fold it into itself (or roll it up).

![](https://cdn-learn.adafruit.com/assets/assets/000/044/589/medium800thumb/adafruit_products_out.jpg?1501531282)

Then, place it on the mounting plate. Press down so it retains a firm grip (servos move really forcefully).

![](https://cdn-learn.adafruit.com/assets/assets/000/044/590/medium800thumb/adafruit_products_out.jpg?1501531328)

Take a twist-tie (like the ones you can get at your local supermarket) or a zip-tie and affix the Laser Pointer to the horn of the servo. We like using zip-ties and twist-ties because they're super inexpensive and non-permanent.&nbsp;

# Experimenter's Guide for Metro

## Code

The code for this is going to look very similar to PROJ05 - it uses a similar structure to handle IR remote button presses, but with the servo instead of USB HID. We are also going to introduce three&nbsp;new concepts that you might've seen in previous CIRCs - `random()`, `min()` and `max()`.&nbsp;

First, let's import both IRLib&nbsp;and Servo:

```
#include &lt;IRLibAll.h&gt;
#include &lt;Servo.h&gt;
```

Then, we are going to include all of the remote-specific code. This is going to include #define's for remote values,&nbsp;the receiver pin assignment, the decoder object, and the ir protocol used.&nbsp;

```
      /* Adafruit Mini Remote */
#define MY_PROTOCOL NEC
#define RIGHT_ARROW   0xfd50af 
#define LEFT_ARROW    0xfd10ef 
#define SELECT_BUTTON 0xfd906f 
#define BUTTON_0 0xfd30cf  
#define BUTTON_1 0xfd08f7 
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7
// pin number for the receiver
IRrecv myReceiver(2); 
IRdecode myDecoder;
// handles nec repeat codes
uint32_t Previous;
    
```

Next, we are going to create a servo object myServo, a variable to store the servo position and a variable to hold the angle (in degrees) of the servo.

```
      /* Servo */
// create a servo object 
Servo myServo;  
// stores the servo position
int16_t pos;        
// angle (degrees) to move the servo left/right
int16_t Speed;      
    
```

**(Optional)&nbsp;**If you're using a laser and are able to control it from the metro (see: _assembly_), we are going to connect the power to pin 11. We are also going to make a boolean, `laserToggle`, to turn the laser on and off. `laserToggle` holds one of two values -&nbsp;_true_ or&nbsp;_false_. Depending on the button pressed and the current state, we can easily toggle the laser.

```
      /* Laser */
// connect laser PWR to a pin 11
const int laserPin = 11;
// toggle the laser
bool laserToggle = false;
    
```

Our **setup()&nbsp;**code needs to set the laser pin as an output, attach a servo to pin 9, set the initial `pos` to 90, the initial `pos` to 90 and the initial `Speed` to 5. Then, we are going to write&nbsp;`pos` to the servo and start the IR receiver.&nbsp;

```
      void setup() { 
  // randomizes a seed for random() calls
  randomSeed(analogRead(0));
  // set the laser pin as an output
  pinMode(laserPin, OUTPUT);
  // attach servo to pin 9
  myServo.attach(9);      
  // set initial position
  pos = 90;              
  // set initial speed 
  Speed = 5;             
  // write initial pos to servo at startup
  myServo.write(pos);     
  // Start the IR receiver
  myReceiver.enableIRIn();
} 
    
```

As previously mentioned, this code is similar to PROJ05:

The `loop()` is quite complicated, but we'll break it down to make it easier. We are going to first detect if the receiver gets an input from the remote with `myReceiver.getResults()`. Then, we are going to decode it with a call to `myDecoder.decode()`.&nbsp;

Next, we want to check if the protocol is the same as what's used by the Mini Remote, NEC, by checking `if(myDecoder.protocolNum==MY_PROTOCOL)`. Finally, we are going to detect&nbsp;the repeat codes, and set the current value to the previous decoded value `if(myDecoder.value==0xFFFFFFFF {myDecoder.value=Previous;}`

```
void loop() 
{ 
    if (myReceiver.getResults()) {
       myDecoder.decode();
       if(myDecoder.protocolNum==MY_PROTOCOL) {
         if(myDecoder.value==0xFFFFFFFF)
           myDecoder.value=Previous;
         switch(myDecoder.value) {
```

This time, though, we are going to&nbsp;_set the position of the servo&nbsp;_before writing to it. Hobby servos are incredibly particular with how far they can rotate, and can break if you rotate them too far. Let's prevent this with the [min()](https://www.arduino.cc/en/Reference/Min)&nbsp;function. This function will set the position of the servo to _pos+Speed_, but it'll keep the value underneath or at 180 degrees so that it won't go past that point.

```
case LEFT_ARROW:    
	// move servo 
	pos=min(180,pos+Speed); 
	break;
```

Similarly if we want to constrain the right side, we set `pos` to&nbsp;`max(0, pos-Speed).`&nbsp;Max is the opposite of min, it constrains the lower-ends of the value.

```
case RIGHT_ARROW:   
	pos=max(0,pos-Speed);
	break;
```

One of the cool&nbsp;things Arduino lets you do is generate[&nbsp;a random number.](https://www.arduino.cc/en/Reference/Random) We can generate a random number between 0 and 180 if we call `random(0, 180)`. Let's set one of the buttons to set the pos to call to random.&nbsp;

```
case BUTTON_0:      
	pos=random(0,180); 
	break;
```

After the case statements, you'll want to:

1. Write to the servo,

2. Handle the NEC repeat code: `Previous=myDecoder.value; `

3. Re-enable the IR Receiver

```
myServo.write(pos); 
Previous=myDecoder.value;
myReceiver.enableIRIn();

```

The full code is below&nbsp;

https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ06_IR_PET/PROJ06_IR_PET.ino

# This project isn't working properly
### 

Make sure your servo is attached to&nbsp; **Digital Pin 9** on your Metro or Metro Express. Also make sure you have the servo library included in your sketch (at the top of your sketch, you should see `#include `).&nbsp;

### 

The code for this project only works with the Adafruit Mini Remote. [If you want to use another remote, please check this guide for more information.](../../../../using-an-infrared-library)

### 

[Post up in the Adafruit Support Forums and we will get back to you as soon as we can](https://forums.adafruit.com/viewforum.php?f=25)&nbsp;:)

# Experimenter's Guide for Metro

## PROJ08: Analog Thermometer Gauge

![](https://cdn-learn.adafruit.com/assets/assets/000/045/401/medium800thumb/adafruit_products_moving.jpg?1502980826)

One of the cool products in the Adafruit Store is the [Automotive Gauge Stepper Motor](https://www.adafruit.com/product/2424), a stepper motor with a needle indicator attached to it. This gauge can be used for a physical-feel, similar to a&nbsp;tachometer on a car.

Since we already have a Servo motor, we can build an analog gauge to measure temperature. This PROJ can also be re-purposed to create a physical output gauge for anything you can measure!

# Experimenter's Guide for Metro

## Parts

### **Mini Servo**

&nbsp;

[If you'd like to order an extra mini servo from the Adafruit shop, click here!](https://www.adafruit.com/product/169)

[There are&nbsp;many other servo sizes and types in the Adafruit store, check out our offerings](https://www.adafruit.com/?q=servo&)

![adafruit_products_Servo_White_BackgroundORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/133/medium640/adafruit_products_Servo_White_BackgroundORIG.jpg?1502386782)

Warning: 

### **Analog Temperature Sensor**

&nbsp;

[If you'd like an extra temperature sensor, you can grab one from the Adafruit shop, click here](https://www.adafruit.com/product/165)

![adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/136/medium640/adafruit_products_Analog_Temperature_Sensor_White_Background_ORIG.jpg?1502386919)

### **Breadboard Wiring Bundle**

&nbsp;

[If you'd like to order more wires from the Adafruit shop click here!](https://www.adafruit.com/product/153)

![adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/134/medium640/adafruit_products_Breadboard_Wire_Bundle_White_Background_ORIG.jpg?1502386857)

### **Adafruit Metro (or Metro Express) + Breadboard + Mounting Plate&nbsp;**

[If you have not assembled this, we have a handy guide!](../../../../arduino-prototyping-mounting-plate)

&nbsp;

[If you'd like to order an extra plastic mounting plate](https://www.adafruit.com/product/275),&nbsp;[Adafruit Metro](https://www.adafruit.com/product/2488),&nbsp;[Adafruit&nbsp;Metro Express](https://www.adafruit.com/product/3505), or&nbsp;[Mini-Breadboard](https://www.adafruit.com/product/64)&nbsp;from the Adafruit Shop click here!&nbsp;

![adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg](https://cdn-learn.adafruit.com/assets/assets/000/045/135/medium640/adafruit_products_Metro_Breadboard_Routing_Plate_RedoWhite_Background.jpg?1502386883)

# Experimenter's Guide for Metro

## Wiring

![](https://cdn-learn.adafruit.com/assets/assets/000/045/132/medium800/adafruit_products_PROJ05_bb.png?1502385624)

Note there are&nbsp; **two** &nbsp;power connections: the **TMP36 is connected to&nbsp;3.3V Pin&nbsp;** and the **Servo is connected to the 5V Pin.&nbsp;** If you're using a regular metro, both can be connected to the&nbsp; **5V&nbsp;** pin and controlled in code.

# Experimenter's Guide for Metro

## Assembly

Our assembly process for this can differ for how&nbsp; **you&nbsp;** want to make your circuit. The enclosure can be different, and you might even want to [try other servos from the Adafruit&nbsp;store](https://www.adafruit.com/?q=servo). The calibration, though, is very important and you'll want to "dial in" your servo to make sure it's going to display perfectly.

## Dialing in your Servo
First, we should move our servo to its center location. Download and run this small Arduino code. It'll move the servo to it's center location:

```
/* 
 *  Servo Centering Script
 *  
*/

#include &lt;Servo.h&gt;

Servo myservo;  


void setup() {
  myservo.attach(9);  
}

void loop() {
  // change this depending on where you're centering
  myservo.write(90);              
  delay(15);                    
}

```

You should see your servo horn move to the center. Take the horn off your servo (if you screwed it on, you'll have to unscrew it), and mark the tip of it with a marker. This will be your indicator:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/137/medium800/adafruit_products_IMG_3784_%281%29.jpg?1502388478)

Reattach the horn onto your servo (which should now be in the 90 degrees position) and you're ready to roll!

![](https://cdn-learn.adafruit.com/assets/assets/000/045/138/medium800/adafruit_products_IMG_3785.jpg?1502388543)

## Assembling an enclosure&nbsp;
Let's build an enclosure so that you can use this on your desk at work, or somewhere in a room.&nbsp;The ever so talented [Dano Wall&nbsp;](https://www.instagram.com/danowall/)whipped up a printable, cut-out, design which&nbsp;fits on top of the box that your metroX kit came in. It's a dual-dial design that works both with Fahrenheit and Celsius . You can download the design below (it's open-source and totally modifiable):

[Celsius_Farenheit_dial_A4_horizontal.pdf](https://cdn-learn.adafruit.com/assets/assets/000/103/278/original/Celsius_Farenheit_dial_A4_horizontal.pdf?1625081751)
Test-fit the printed dial against your MetroX box, then cut it out along the outer black line

![](https://cdn-learn.adafruit.com/assets/assets/000/045/402/medium800thumb/adafruit_products_cut.jpg?1502980912)

Tape the four corners (we only taped two in the gif below) of the paper to the inside of the box. Use transparent tape if you can, it'll look much cleaner:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/403/medium800thumb/adafruit_products_tape.jpg?1502980928)

Use a box-cutter or the edge of a pair of scissors to cut out the servo cut-out (the rectangle) on your printed design. It might take a few cuts to get through the box completely:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/404/medium800thumb/adafruit_products_boxcut.jpg?1502980951)

Clean up any residual cardboard from the hole you cut. Tape the servo in the rectangular hole, facing outward:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/405/medium800thumb/adafruit_products_place.jpg?1502980978)

Finally, you'll need a pointing device. We used the inside of a disposable&nbsp;pen since they're inexpensive, and a lot of people have them lying around:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/406/medium800thumb/adafruit_products_pen.jpg?1502981006)

Great job! Close up the box and get ready to program:

![](https://cdn-learn.adafruit.com/assets/assets/000/045/407/medium800thumb/adafruit_products_moving.jpg?1502981020)

# Experimenter's Guide for Metro

## Code

The code for this is a mix between code for&nbsp; **CIRC04: Servo** and **CIRC10: Temperature**. What we're doing is attaching the value for the temperature, to a value of the servo. Let's walk through some parts of it:

Inside, the loop, we're going to read in a voltage from the pin using the `getVoltage()` function from CIRC04. We are then going to pass this value to a new function, `convertToF()`, which is generated from the voltage value, to convert the voltage to a degrees Fahrenheit&nbsp;temperature:

```
  // read the voltage from the pin
  float voltage = getVoltage(temperaturePin);
  // convert the voltage to a temperature value
  float temperature = convertToF(voltage);
```

Then, we're going to constrain&nbsp;the temperature values. This is totally up to you, you can use any number, but we are using -10F and 100F as our minimum and maximum temperature accepted by the TMP36:

`map((int(temperature)), -10, 100`

We still need to **map** the temperature values to servo values. The minimum&nbsp;degrees a servo can move is **0 degrees&nbsp;** and the maximum degrees is **180** , so let's set the servo to map: -10 to 0 and 100 to 180:

```
servoPos = map((int(temperature)), -10, 100, 0, 180);
```

Then, write `servoPos` to the servo!

```
// write servoPos to the servo
 metroServo.write(servoPos);
 // poll every 0.5sec
 delay(500);
```

Here's the full code, with all the helpers built in:

# Code
https://github.com/adafruit/METROX-Examples-and-Project-Sketches/blob/master/arduino/PROJ07_RGB_MIXER/PROJ07_RGB_MIXER.ino

# Experimenter's Guide for Metro

## Code


## Featured Products

### Adafruit MetroX Classic Kit - Experimentation Kit for Metro 328

[Adafruit MetroX Classic Kit - Experimentation Kit for Metro 328](https://www.adafruit.com/product/170)
Interested in making neat stuff with an Arduino-compatible board but not sure where to start? This kit includes all the pieces needed to complete over 20 different circuit and projects. Basically everything you need to be playing within minutes of its arrival. **No soldering required,...**

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/170)
[Related Guides to the Product](https://learn.adafruit.com/products/170/guides)
### Adafruit MetroX Classic Kit - Experimentation Kit for Metro 328

[Adafruit MetroX Classic Kit - Experimentation Kit for Metro 328](https://www.adafruit.com/product/3588)
Interested in making neat stuff with an Arduino-compatible board but not sure where to start? This kit includes all the pieces needed to complete over 20 different circuit and projects. Basically everything you need to be playing within minutes of its arrival. **No soldering required,...**

In Stock
[Buy Now](https://www.adafruit.com/product/3588)
[Related Guides to the Product](https://learn.adafruit.com/products/3588/guides)
### Budget Pack for Metro 328 - with Assembled Metro ATmega328P

[Budget Pack for Metro 328 - with Assembled Metro ATmega328P](https://www.adafruit.com/product/193)
This budget pack is an optimized collection of parts and pieces to experiment with **Adafruit Metro 328** and the Arduino IDE at home, school or work. Great for students and those that want to get their feet wet, no soldering required!  
  
**Includes the Adafruit...**

In Stock
[Buy Now](https://www.adafruit.com/product/193)
[Related Guides to the Product](https://learn.adafruit.com/products/193/guides)
### Adafruit METRO 328 without Headers

[Adafruit METRO 328 without Headers](https://www.adafruit.com/product/2466)
We sure love the ATmega328 here at Adafruit, and we use them _a lot_ for our own projects. The processor has plenty of GPIO, Analog inputs, hardware UART SPI and I2C, timers and PWM galore - just enough for most simple projects. When we need to go small, we use a <a...></a...>

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/2466)
[Related Guides to the Product](https://learn.adafruit.com/products/2466/guides)
### Adafruit METRO 328 - Arduino Compatible - with Headers

[Adafruit METRO 328 - Arduino Compatible - with Headers](https://www.adafruit.com/product/2488)
This is the&nbsp; **Adafruit METRO Arduino-Compatible - with&nbsp;headers.&nbsp;** It's a fully assembled and tested microcontroller and physical computing board with through-hole headers attached.&nbsp; If you don't want a&nbsp;Metro with the headers attached for...

In Stock
[Buy Now](https://www.adafruit.com/product/2488)
[Related Guides to the Product](https://learn.adafruit.com/products/2488/guides)

## Related Guides

- [Ladyada's Learn Arduino - Lesson #0](https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-0.md)
- [Adafruit BMP388 and BMP390 - Precision Barometric Pressure and Altimeter](https://learn.adafruit.com/adafruit-bmp388-bmp390-bmp3xx.md)
- [IR Sensor](https://learn.adafruit.com/ir-sensor.md)
- [All About Arduino Libraries](https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use.md)
- [Mystery Box: NeoMatrix Mk I](https://learn.adafruit.com/mystery-box-neomatrix-mk-i.md)
- [Fake TV Light for Engineers](https://learn.adafruit.com/fake-tv-light-for-engineers.md)
- [Motorized Camera Slider MK3 ](https://learn.adafruit.com/motorized-camera-slider-mk3.md)
- [Adafruit MSA301 Triple Axis Accelerometer](https://learn.adafruit.com/msa301-triple-axis-accelerometer.md)
- [Ladyada's Learn Arduino - Lesson #2](https://learn.adafruit.com/ladyadas-learn-arduino-lesson-number-2.md)
- [Arduin-o-Phone](https://learn.adafruit.com/arduin-o-phone-arduino-powered-diy-cellphone.md)
- [Internet of Things Printer](https://learn.adafruit.com/internet-of-things-printer.md)
- [Adafruit VCNL4040 Proximity Sensor](https://learn.adafruit.com/adafruit-vcnl4040-proximity-sensor.md)
- [Echo 2-XL](https://learn.adafruit.com/echo-2-xl.md)
- [Arduino GPS Clock](https://learn.adafruit.com/arduino-clock.md)
- [LOVE Light](https://learn.adafruit.com/love-light.md)
