Where do I put libraries?

I've got Arduino 0022 on my Mac and I'm trying to compile some example code I got from http://code.google.com/p/xbee-arduino/. There are two libraries I need: xbee.h and NewSoftSerial.h. I downloaded the zip files and extracted them to /Users/Scott/Documents/Arduino/libraries/NewSoftSerial/ /Users/Scott/Documents/Arduino/libraries/XBee

But Arduino can't find them, I get an error when I compile. How do I get my sketch to compile?


Are your Sketches in this directory... /Users/Scott/Documents/Arduino/

Did you restart the Arduino IDE?

The pde files are in subdirectories of the /Arduino/ directory, for example

/Users/Scott/Documents/Arduino/Xbee_Read_IO/Xbee_Read_IO.pde /Users/Scott/Documents/Arduino/Ethernet_Shield_Webserver/Ethernet_Shield_Webserver.pde

You put the libraries in the correct place.

I get an error when I compile

What is the error message?

I’m not at my home computer, but it’s something to the effect it can’t find the files. It doesn’t find either NewSoftSerial.h or xbee.h. I tried #include <xbee.h> and I tried #include “xbee.h”
Isn’t the <> for libraries that are in the xbee ‘package’ and “” is for libraries in the sketch directory? When I get home, I’ll copy the error messages exactly.


I tried it on my laptop and got the same error. I’m trying to compile the sample sketch that came with xbee.h. I got it from http://code.google.com/p/xbee-arduino/. The sample sketch is called Series1_IoSamples

I uploaded a screen shot of my Arduino directories.

The errors I’m getting are:

Series1_IoSamples.cpp:20:18: error: XBee.h: No such file or directory
Series1_IoSamples.cpp:21:27: error: NewSoftSerial.h: No such file or directory
Series1_IoSamples:40: error: ‘NewSoftSerial’ does not name a type
Series1_IoSamples:42: error: ‘XBee’ does not name a type
Series1_IoSamples:44: error: ‘Rx16IoSampleResponse’ does not name a type
Series1_IoSamples.cpp: In function ‘void setup()’:
Series1_IoSamples:49: error: ‘xbee’ was not declared in this scope
Series1_IoSamples:51: error: ‘nss’ was not declared in this scope
Series1_IoSamples.cpp: In function ‘void loop()’:
Series1_IoSamples:56: error: ‘xbee’ was not declared in this scope
Series1_IoSamples:61: error: ‘RX_16_IO_RESPONSE’ was not declared in this scope
Series1_IoSamples:62: error: ‘ioSample’ was not declared in this scope
Series1_IoSamples:64: error: ‘nss’ was not declared in this scope
Series1_IoSamples:103: error: ‘nss’ was not declared in this scope
Series1_IoSamples:108: error: ‘nss’ was not declared in this scope

Here’s the sketch:

 * Copyright (c) 2009 Andrew Rapp. All rights reserved.
 * This file is part of XBee-Arduino.
 * XBee-Arduino is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * XBee-Arduino is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with XBee-Arduino.  If not, see <http://www.gnu.org/licenses/>.

#include "XBee.h"
#include "NewSoftSerial.h"

This example is for Series 1 XBee Radios only
Receives I/O samples from a remote radio with 16-bit addressing.
The remote radio must have IR > 0, at least one digital or analog input enabled
and DL set to the 16-bit address of the receiving XBee (the one connected to the Arduino).
This example uses the NewSoftSerial library to view the XBee communication.  I am using a 
Modern Device USB BUB board (http://moderndevice.com/connect) and viewing the output
with the Arduino Serial Monitor.    
You can obtain the NewSoftSerial library here http://arduiniana.org/libraries/NewSoftSerial/

// Define NewSoftSerial TX/RX pins
// Connect Arduino pin 9 to TX of usb-serial device
uint8_t ssRX = 9;
// Connect Arduino pin 10 to RX of usb-serial device
uint8_t ssTX = 10;
// Remember to connect all devices to a common Ground: XBee, Arduino and USB-Serial device
NewSoftSerial nss(ssRX, ssTX);

XBee xbee = XBee();

Rx16IoSampleResponse ioSample = Rx16IoSampleResponse();
// 64-bit response is same except api id equals RX_64_IO_RESPONSE and returns a 64-bit address
//Rx64IoSampleResponse ioSample = Rx64IoSampleResponse();

void setup() { 
  // start soft serial

void loop() {
  //attempt to read a packet    

  if (xbee.getResponse().isAvailable()) {
    // got something

    if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {

      nss.print("Received I/O Sample from: ");
      nss.println(ioSample.getRemoteAddress16(), HEX);  

      nss.print("Sample size is ");
      nss.println(ioSample.getSampleSize(), DEC);

      if (ioSample.containsAnalog()) {
        nss.println("Sample contains analog data");

      if (ioSample.containsDigital()) {
        nss.println("Sample contains digtal data");
      for (int k = 0; k < ioSample.getSampleSize(); k++) {
        nss.print("Sample "); 
        nss.print(k + 1, DEC);   
        for (int i = 0; i <= 5; i++) {
          if (ioSample.isAnalogEnabled(i)) {
            nss.print("Analog (AI");
            nss.print(i, DEC);
            nss.print(") is ");
            nss.println(ioSample.getAnalog(i, k));  
        for (int i = 0; i <= 8; i++) {
           if (ioSample.isDigitalEnabled(i)) {
            nss.print("Digtal (DI");
            nss.print(i, DEC);
            nss.print(") is ");
            nss.println(ioSample.isDigitalOn(i, k));
    else {
      nss.print("Expected I/O Sample, but got ");
      nss.print(xbee.getResponse().getApiId(), HEX);
  else if (xbee.getResponse().isError()) {
    nss.print("Error reading packet.  Error code: ");  

The #include <blah.h> syntax is right for libraries, if its not finding them it is looking in the wrong place (I don’t have an installation on a Mac, but if you go to File → Preferences menu it should tell you where it wants sketches and I believe libraries go in the libraries sub-folder there. The preferences.txt file doesn’t seem to help with this either. It might be that the system is using “./libraries” as the library directory rather than an absolute pathname. To test this place your sketch one folder up in /Users/Scott/Documents/Arduino/.

A workaround then might be #include "../libraries/blah.h"

From your screen print of your arduino directory, I don't see a libraries subfolder to hold your various libraries. That is what the IDE wants to see. Here is a copy of my arduino folder library directory:

C:\Documents and Settings\Primary Windows User\My Documents\Arduino\libraries

10 Folders:

Button DS1307 Flash MsTimer2 Playtune Streaming String Tone WString __MACOSX

0 Files:


I have a Mac. To be able to use the *.h files they must be included
in a Library. I had to go to Terminal to create the necessary directories
because Finder masks these directories from our prying eyes.
In Terminal you will find the Library files in:


*Note the lower case “libraries”.

You need to create directories in the libraries directory called say
NewSoftSerial and Xbee. Then copy the respective .h files into their
Now start or restart the IDE. It will not see the new libraries if you don’t.
In the IDE in the Sketch menu click import Library. You should see your libraries
in the drop down list. Click on the Library your created and the IDE will include
it into your sketch with the “#include <Xbee.h>”.
That should compile.

From your screen print of your arduino directory, I don’t see a libraries subfolder to hold your various libraries. That is what the IDE wants to see. Here is a copy of my arduino folder library directory

The screenshot of my directories was from my Windows laptop (where I’m having the same problem as on my Mac). But my Mac directory has the library directory (see attached screenshot). But, I solved the problem. It was as simple as needing to restart the IDE (as suggested by rustleaf). I had created the libraries directory and put the xbee.h and NewSoftSerial.h files in there while my IDE was open.

I included the libraries with the <> around the name, not double quotes; everything compiles fine now.
#include <XBee.h>
#include <NewSoftSerial.h>

Thanks for everyone’s help.


Arduino Directory Scnreenshot.png