Top Banner
60
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Design Guide Book
Page 2: Design Guide Book

2

Page 3: Design Guide Book

Design Guide for Home Automation

Imagine, Design and Build your Own Home AutomationSystems based on the Arduino Platform

Marco Schwartz, PhD

Page 4: Design Guide Book

ii

Page 5: Design Guide Book

Contents

Legal v

Introduction vii

0.1 Why Should You Design Your Own Systems? . . . . . . . . . vii

0.2 How is the Book Organized? . . . . . . . . . . . . . . . . . . viii

0.3 What Will you Learn? . . . . . . . . . . . . . . . . . . . . . . ix

0.4 Prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . ix

1 Building an Arduino System From Scratch 1

1.1 Hardware & Software Requirements . . . . . . . . . . . . . . 2

1.2 Hardware Configuration . . . . . . . . . . . . . . . . . . . . 3

1.3 Testing the Project . . . . . . . . . . . . . . . . . . . . . . . 8

1.4 How to Go Further . . . . . . . . . . . . . . . . . . . . . . . 8

2 Optimize Arduino for Low-Power Operation 9

2.1 Hardware & Software Requirements . . . . . . . . . . . . . . 10

2.2 Hardware Configuration . . . . . . . . . . . . . . . . . . . . 11

2.3 Testing the Project . . . . . . . . . . . . . . . . . . . . . . . 13

iii

Page 6: Design Guide Book

iv CONTENTS

2.4 How to Go Further . . . . . . . . . . . . . . . . . . . . . . . 15

3 Designing an Arduino Shield 17

3.1 Hardware & Software Requirements . . . . . . . . . . . . . . 18

3.2 Designing the Shield . . . . . . . . . . . . . . . . . . . . . . 18

3.3 Fabrication . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.4 Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

3.5 How to Go Further . . . . . . . . . . . . . . . . . . . . . . . 27

4 Designing Your Own Arduino Board 29

4.1 Hardware & Software Requirements . . . . . . . . . . . . . . 29

4.2 Designing the Board . . . . . . . . . . . . . . . . . . . . . . 31

4.3 Fabrication . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.4 Result . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

4.5 How to Go Further . . . . . . . . . . . . . . . . . . . . . . . 41

5 Conclusion 43

5.1 What did you Learn in This Book? . . . . . . . . . . . . . . . 43

5.2 How to go Further . . . . . . . . . . . . . . . . . . . . . . . . 44

6 Resources 45

6.1 General Information on PCB Design & Arduino . . . . . . . . 45

6.2 PCB Design Tools . . . . . . . . . . . . . . . . . . . . . . . . 45

6.3 Components . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

6.4 PCB Manufacturers . . . . . . . . . . . . . . . . . . . . . . . 46

Page 7: Design Guide Book

CONTENTS v

6.5 Suggested Readings . . . . . . . . . . . . . . . . . . . . . . . 46

Page 8: Design Guide Book

vi CONTENTS

Page 9: Design Guide Book

Legal

Copyright ©2014 by Marc-Olivier Schwartz

All rights reserved. No part of this book may be used or reproduced in anymanner whatsoever without permission except in the case of brief quotationsembodied in critical articles or reviews.

vii

Page 10: Design Guide Book

viii LEGAL

Page 11: Design Guide Book

Introduction

0.1 Why Should You Design Your Own Systems?

In the Home Automation with Arduino book, all the projects we did were madedirectly on a breadboard. The breadboard next to your Arduino board, withsensors & other components connected to Arduino. However, this is not veryconvenient if you really want to be serious about building your own home au-tomation system.

Indeed, on a board like the Arduino Uno, you will always have componentsthat you do not need, like extra LEDs and pin headers that just take space &power. This is why at some point we need to build our own Arduino systemfrom scratch, so we can have exactly the components we need in our homeautomation systems.

At some point, you also want something that looks better and is more robustthan just some components plugged into a breadboard. And a very convenientway to do this is to build your own systems based on Arduino, and especiallyArduino shields.

Using a shield allows you to extend the functionalities of your Arduino boardjust by plugging in the shield to the board. And this is exactly what I proposeto do in the last part of this book: designing your own Arduino shield! Thenice thing is that if you are careful about the design of your shield, you will beable to stack several shield together, for example use your own shield with theArduino WiFi shield to transfer data wirelessly from your sensors.

ix

Page 12: Design Guide Book

x INTRODUCTION

0.2 How is the Book Organized?

You will find all the code of this book inside the dedicated GitHub repositoryof the book. You will find the link to this GitHub repository in every chapter ofthis book, or if you want to have a look right now, the link is:

https://github.com/openhomeautomation/pcb-book

Note that all chapters were designed to be completely independent from eachother, so you can start with the chapter you like in the book without being lost.However, especially if you are a beginner on the topic it is highly recommendedto follow the chapters of this book one by one.

In Chapter 1, you will learn how to build a completely functional Arduinosystem on a breadboard. To do so, we will be using the minimal number ofcomponents required. This will be the foundation of every other design we aregoing to do in this book.

In Chapter 2, we will continue the work we did in the first chapter. We willintroduce low-power modes of the Arduino microcontroller. We will be able toreduce the power consumption our minimal Arduino systems by several ordersof magnitude. Therefore, we will be able to build systems like motion sensorsthat work for years on batteries.

Chapter 3 will be our first chapter where we will do some PCB design. As anintroduction, we are going to design a shield dedicated to home automation andthat you can use with existing Arduino boards.

Finally, Chapter 4, we will design something slightly more complex: our ownintegrated Arduino system. We will use everything we saw in the previouschapter and apply it to the design of a brand new Arduino board for homeautomation.

Page 13: Design Guide Book

0.3. WHAT WILL YOU LEARN? xi

0.3 What Will you Learn?

Before diving into the heart of this book, and building your first Arduino sys-tem from scratch, I wanted to spend a few moments to explain what you willactually learn in this book.

Of course, you will learn about PCB design. You will learn how to use aprofessional PCB design software, Eagle. We will design two boards usingEagle, an Arduino shield and a brand new Arduino board from scratch. Thiswill give you a very good knowledge of the Eagle software, which you canapply in other projects than just home automation.

You will also learn about the Arduino platform, in much more detail than whatwe saw in the Home Automation with Arduino book. Because we will buildour own Arduino systems from scratch, you will get a much deeper knowledgeinto how the Arduino platform is working.

You will also learn about electronics in general, as we will choose varioussensors & other components to integrate into our Arduino PCB designs.

0.4 Prerequisites

First of all, you could just read this book from start to finish without actuallydoing any of the projects you will read about. And still, you would learn alot about Arduino, PCB design and electronics. However, I really recommendspending time doing the projects yourself, you will learn some much more bydoing so.

To follow the projects that you will find this book, you will need to have somebasic knowledge about software development, electronics and the Arduino plat-form. I really recommend reading the main book, Home Automation with Ar-duino, before doing the projects of this book.

Page 14: Design Guide Book

xii INTRODUCTION

Page 15: Design Guide Book

Chapter 1

Building an Arduino SystemFrom Scratch

Maybe you have an idea about an home automation system you want to build,for example designing your own autonomous motion sensor based on Arduino.And for that, it is just unrealistic to use an official Arduino board like the Ar-duino Uno.

Why ? Simply because there are many things you don’t need when buildingyour own system: the USB port, LEDs, the reset button, the extension headersAll these parts just take extra space and consume power for nothing when youwant to build a system that does a specific task only.

In this chapter, we are going to see how to build an Arduino board from scratchon a breadboard. To do so, we will only use the minimal number of requiredcomponents for the task. Based on what you will learn in this chapter, you willbe able to customize this design to suit your needs. Later, you will be able touse this to build your own boards based on Arduino.

1

Page 16: Design Guide Book

2 CHAPTER 1. BUILDING AN ARDUINO SYSTEM FROM SCRATCH

1.1 Hardware & Software Requirements

You need several components to build your own Arduino system on a bread-board.

The main piece of this project is of course the microcontroller that will runyour Arduino sketches. There are many microcontrollers that can run Arduinosketches, but we will keep it simple and use the chip from the Arduino Unoboard: the AtmelaATmega328.

You will need a chip with the Arduino bootloader. A bootloader on a microcon-troller is some code that is written (“burned”) into the chip’s ROM. Nowadaysit is easy to buy a chip with the Arduino bootloader, so buy it with it, it willmake your life easier. This way, you will be able to use our project with theArduino IDE without any additional steps.

You will also need several components around the chip. You will need two10uF capacitors, two 22pF capacitors, one 10K Ohm resistor, two 220 Ohm(or 330 Ohm) resistors, one red LED, one green LED, and one 16MHz crystalclock.

You will also need a FTDI breakout board to program the Arduino chip directlyon the breadboard. If you are using another Arduino board to program themicrocontroller, for example an Arduino Uno, you can just skip this part.

Finally, you will need a breadboard and some jumper wires.

This is a list of all components that were used for this project:

• AtmelaATmega328 (https://www.sparkfun.com/products/10524)• 2 x 10uF capacitors (https://www.sparkfun.com/products/523)• 2 x 22pF capacitors (https://www.sparkfun.com/products/8571)• 10k Ohm resistor (https://www.sparkfun.com/products/8374)• 2 x 220 Ohm or 330 Ohm resistors (https://www.sparkfun.com/products/8377)• One red LED (https://www.sparkfun.com/products/9590)• One green LED (https://www.sparkfun.com/products/9592)• 16 MHz crystal clock (https://www.sparkfun.com/products/536)

Page 17: Design Guide Book

1.2. HARDWARE CONFIGURATION 3

• FTDI breakout board (https://www.sparkfun.com/products/9716)• Breadboard (https://www.sparkfun.com/products/12002)• Jumper wires (https://www.sparkfun.com/products/12795)

On the software side, you will need the usual Arduino IDE.

You also need the FTDI drivers for the FTDI breakout board. It might bealready installed on your system, but it was missing from my computer. Youcan find them by following this link:

http://www.ftdichip.com/FTDrivers.htm

I personally chose the Virtual COM Port (VCP) drivers.

1.2 Hardware Configuration

This project is quite complex to build, so make sure to carefully follow theinstructions. You have to place the microcontroller in the upper part of thebreadboard, so you still have some place for the FTDI board. You should endup with something like this:

Page 18: Design Guide Book

4 CHAPTER 1. BUILDING AN ARDUINO SYSTEM FROM SCRATCH

The next step is to take care of the power. You have to connect power linestogether on the breadboard, for the ground and the positive power supply. Then,connect the Arduino VCC, AREF and AVCC to the positive power supply line,and the two GND pins to the ground lines.

I also added a 220 Ohm resistor in series with a red LED between the twopower lines to see if the power is correctly connected. Finally, add a 10 uFcapacitor between the two power lines to stabilize the voltage supplied to themicrocontroller. This is the result:

Page 19: Design Guide Book

1.2. HARDWARE CONFIGURATION 5

Now, we will focus more on the microcontroller itself. You have to connect a10K Ohm resistor between the reset pin and the positive power supply line, sothe chip doesn’t reset itself. Then, connect the crystal clock between the X1and X2 pins. Finally, connect each of these pins to the ground line via 22pFcapacitors.

You can also connect a green LED in series with a 220 Ohm resistor on Pin13 of the microcontroller, because this is the pin connected to an LED on theArduino Uno board, so it will allow you to easily see if your project is workingcorrectly:

Page 20: Design Guide Book

6 CHAPTER 1. BUILDING AN ARDUINO SYSTEM FROM SCRATCH

If you are programming your chip via another board, for example with an Ar-duino Uno board, you can just stop there. Just connect some power supply(even a set of batteries) to the power lines and your project will work. You canuse a voltage range from 1.8 to 5.5V to power the microcontroller.

But if you want to program the chip in place, you need a final step. First, placethe FTDI breakout board at the bottom of the breadboard. Then, connect VCCand GND of the breakout board (we’ll power the project with USB in this case)to the corresponding power lines.

After that, connect the TX and RX pins from the breakout board to RX andTX on the microcontroller (pin 1 and 2). Finally, connect the DTR pin of thebreakout board to the reset pin of the microcontroller via a 10uF capacitor. Thisshould be the result:

Page 21: Design Guide Book

1.2. HARDWARE CONFIGURATION 7

Finally, to help you out, this is the complete schematics of this project:

Page 22: Design Guide Book

8 CHAPTER 1. BUILDING AN ARDUINO SYSTEM FROM SCRATCH

1.3 Testing the Project

We are now ready to test what you’ve just built. Let’s assume that you wantto program your microcontroller on the breadboard, using the FTDI breakoutboard. You can now just plug your computer to the board via a USB cable. Ifyou wired the power lines correctly, the red LED should turn on. This meanthat there is power flowing through the project.

You can now open the Arduino IDE as usual, and select the correct serial port(in my case it was something beginning with usbserial).

For the board, I just selected Arduino Uno. Depending on which chip youare using, you might need to select “[Optiboot] Arduino Duemilanove” in theBoard menu. To quickly see if the project is working, you can chose the “Blink”sketch which is included by default in the Arduino IDE.

Upload the sketch, and if everything is alright, the green LED should now blink.Congratulations, you now know how to build your own Arduino system fromscratch!

1.4 How to Go Further

In this chapter, we saw how to build a fully functional Arduino system fromscratch. We selected the minimal number of components to make an Arduinosystem on a breadboard, built this system, and tested it with a very simpleArduino sketch.

The best you can do at this point is repeat the steps of this first chapter fromscratch and try to build your own Arduino system again. You can also alreadyadd some functionalities or sensors, like a PIR motion sensor. In the next chap-ters, we are going to build Arduino systems on our own Printed Circuit Boards(PCBs). Therefore, knowing how an Arduino system works is crucial for therest of this book.

Page 23: Design Guide Book

Chapter 2

Optimize Arduino forLow-Power Operation

For most of the Arduino projects you can find on the web, power is usuallynot an issue. Indeed, the Arduino board is nearly always powered by the USBcable coming from the computer.

However, sometimes you want to build systems that are going to be autonomousand powered by a battery. For example, you want to power a wireless motionsensor by using just a set of batteries.

The first idea would be to connect directly an Arduino board like the ArduinoUno R3 to a battery. Easy, right ? Well, it would work, but your battery wouldbe depleted in a matter of days or even hours because some components likevoltage regulators are always drawing power. So we need something better.

In this chapter, we are going to build a project which is quite similar to the onewe saw in the previous chapter. Then, we are going to see how to optimize theenergy consumption of the project so it can last for years on a battery.

9

Page 24: Design Guide Book

10 CHAPTER 2. OPTIMIZE ARDUINO FOR LOW-POWER OPERATION

2.1 Hardware & Software Requirements

You need several components to build you own Arduino system. The mainpiece of this project is of course the microcontroller that will run your Arduinosketches, like theaAtmelaATmega328. You will need a chip with the Arduinobootloader. Buy your chip with it, it will make your life easier.a

In the previous section we used anaFTDI breakout boardato program the Ar-duino chip directly on the breadboard. But for this project I won’t have anyexternal power running on the breadboard so I will just use an Arduino Unoboard to program the microcontroller.

To power the Arduino, you will need a battery. The best is to power the Ar-duino directly from the battery, so you don’t have to use any voltage regulatorsthat will draw power. I used a set of two AA batteries (1.5V each) with a bat-tery holder thus powering the microcontroller with around 3V, which is fineaccording to the ATmega328 documentation.

You will also need several components around the chip. You will need one10uF capacitor,atwo 22pF capacitors, one 10K Ohm resistor, one 220 Ohmresistor,aone green LED, and onea16MHz crystal clock.

Finally, you will need aabreadboard and some jumper wires.

This is a list of all components that were used for this project:

• AtmelaATmega328 (https://www.sparkfun.com/products/10524)• 10uF capacitor (https://www.sparkfun.com/products/523)• 2 x 22pF capacitors (https://www.sparkfun.com/products/8571)• 10k Ohm resistor (https://www.sparkfun.com/products/8374)• 1 x 220 Ohm or 330 Ohm resistor (https://www.sparkfun.com/products/8377)• One LED (https://www.sparkfun.com/products/9592)• 16 MHz crystal clock (https://www.sparkfun.com/products/536)• Breadboard (https://www.sparkfun.com/products/12002)• Jumper wires (https://www.sparkfun.com/products/12795)

On the software side, I tested many solutions to really reduce the power to the

Page 25: Design Guide Book

2.2. HARDWARE CONFIGURATION 11

lowest value possible, and the best I found was theaJeeLib library. You can justdownload it by following this link:

https://github.com/jcw/jeelib

To install this library, you can place the library folder in your Arduino/libraries/folder.

2.2 Hardware Configuration

This project is a bit complex to build, like in the previous chapter, so be sure tofollow the instructions carefully. To help you out, this is the complete schemat-ics of the project:

Page 26: Design Guide Book

12 CHAPTER 2. OPTIMIZE ARDUINO FOR LOW-POWER OPERATION

First, place the microcontroller in the center of the breadboard. You can thentake care about the power: connect power lines on each side, connect the neg-ative power rail to the two GND pins of the microcontroller, and the positivepower rail to VCC, AVCC, and AREF. Also, add the 10uF capacitor betweentwo power rails. Finally, add the battery to the system.

You also have to add the crystal between the X1 and X2 pins, with 22pF ca-pacitors going from each pin to the ground. Also, you need to connect the RSTpin to the positive power rail using a 10K Ohm resistor. To see if the system isworking, connect the green LED in series with a 220 Ohm resistor to the digitalpin 13 of the Arduino board, the other side going to the ground.

This is how it should look like at the end:

Page 27: Design Guide Book

2.3. TESTING THE PROJECT 13

2.3 Testing the Project

We will now write a sketch to test the low-power functions of the JeeLib library.This is the sketch I used:

// Low power functions library#include <JeeLib.h>

// LED pinint led_pin = 13;

// Setup the watchdogISR(WDT_vect) { Sleepy::watchdogEvent(); }

void setup() {

// Set LED pin to outputpinMode(led_pin, OUTPUT);

}

void loop() {

// Turn the LED on and sleep for 5 secondsdigitalWrite(led_pin, HIGH);Sleepy::loseSomeTime(5000);

// Turn the LED off and sleep for 5 secondsdigitalWrite(led_pin, LOW);Sleepy::loseSomeTime(5000);

}

Let’s now see the details of this sketch. You basically just have to include theJeeLib library with:

#include <JeeLib.h>

Then, we can initialize the watchdog with:

ISR(WDT_vect) { Sleepy::watchdogEvent(); }

Page 28: Design Guide Book

14 CHAPTER 2. OPTIMIZE ARDUINO FOR LOW-POWER OPERATION

Finally, you can put the Arduino to sleep for a given period of time with:

Sleepy::loseSomeTime(5000);

Note that you can find the complete code inside the GitHub repository of thebook:

https://github.com/openhomeautomation/pcb-book

Upload the sketch with the Arduino IDE and replace the chip on the bread-board. You should see your Arduino having the same behavior as in the previ-ous chapter (with 5 seconds intervals). But the difference is that now when theLED is off, the Arduino chip doesn’t use a lot of power, as it would do with adelay() function.

We are now going to check how much current does the project actually draw.You can do so by placing a multimeter between one of the power lines. Forexample, I connected the positive pin of the battery to one pin of my multime-ter, and the other pin to the red power rail of the breadboard. To have somereference numbers, I also tested the project with the Blink example sketch thatcomes with the Arduino IDE. Here are the results:

• LED off, without the JeeLib library: 6.7 mA• LED on, without the JeeLib library: 8.8 mA• LED off, with the JeeLib library: 43 uA• LED on, with the JeeLib library: 2.2mA

From these results, we can see that our Arduino system on the breadboardconsumes 6.7 mA when doing nothing with the Arduino Blink example. Withthe sleep functions, the current consumption can be reduced to 43 uA, which isa 150 times improvement.

Let’s do some calculations to see how it will impact a real project, for example atemperature sensor. Let’s say it takes about 500 ms to perform a measurement,at about 2.5 mA of current. Then, the systems sleeps for 10 seconds and theloop starts again. The “mean” current consumption is then 0.16 mA over a

Page 29: Design Guide Book

2.4. HOW TO GO FURTHER 15

complete loop. With batteries rated at 2500 mAh, it means in theory the systemwill last . . . nearly 2 years without changing the batteries!

Of course, some other effects will actually modify this number, but it gives youan idea. Really, you can adapt this idea to every system where the active time issmall compared to the sleep time, and make your Arduino system last for yearswithout changing the battery.

2.4 How to Go Further

In this chapter, we saw how to optimize an Arduino system for low-poweroperation. This is really important in case you want to build any system thathas to operate on a battery or a solar cell.

You can now use what you learned in this chapter to build your own low-powerArduino system. For example, you can couple the project we saw in this chapterwith a simple motion sensor & a small loudspeaker to make an alarm systemthat will work for months or even years on a set of batteries.

Page 30: Design Guide Book

16 CHAPTER 2. OPTIMIZE ARDUINO FOR LOW-POWER OPERATION

Page 31: Design Guide Book

Chapter 3

Designing an Arduino Shield

Now that we know how an Arduino system is working, we can start designingour own systems. And we are going to start with something simple: an Arduinoshield. Shields are add-ons for Arduino boards, that extend the functionalitiesof an Arduino board. They do so by adding sensors and other components toan Arduino board.

There are several advantages of having your own shield over building projectson a breadboard. The main advantage is that you can plug & play a shield onyour boards instead of having many cables around.

In this chapter, I will show you how to design and build your own Arduinoshield for home automation applications. We will see the complete process,from the initial idea to the manufacturing of the shield.

I will mostly describe the design flow, and sometimes not detail the small de-tails of the design process. The goal is to show you how to design your boardfrom your own idea, and not how to show you how to design this specific designI used as an example.

17

Page 32: Design Guide Book

18 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

3.1 Hardware & Software Requirements

Depending on what you want to put on your shield, you will need to get all theindividual components to put on the PCB. These components will be requiredwhen the PCB comes back from the manufacturer. In the case of the homeautomation shield that I will take as an example in this chapter, you will need:

• 5V relay (https://www.sparkfun.com/products/100)• ACS712 current sensor (http://goo.gl/nRrvqp)• DHT11 sensor + 4.7k Ohm resistor (https://www.adafruit.com/product/386)• Photocell (https://www.sparkfun.com/products/9088)• 2 x 10k Ohm resistor (https://www.sparkfun.com/products/8374)• Rectifier diode (https://www.sparkfun.com/products/8589)• 0.1 nF capacitor (http://goo.gl/wEQFVK)• 1 uF polarized capacitor (http://goo.gl/sMmYrH)• 3 pins header (https://www.sparkfun.com/products/116)• 3 pins screw header (https://www.sparkfun.com/products/8433)• Arduino shield headers (https://www.sparkfun.com/products/10007)

On the software side, you will need the latest version of Eagle to design thePCB. You can grab it at:

http://www.cadsoftusa.com/download-eagle/

You will also need the SparkFun Eagle libraries. You can get them at:

https://github.com/sparkfun/SparkFun-Eagle-Libraries

To install an Eagle library, just place it inside the /lbr folder inside your mainEagle installation folder.

3.2 Designing the Shield

The first step when you want to create a new shield is to define the specificationsof your shield. I just wanted a shield that includes many components that are

Page 33: Design Guide Book

3.2. DESIGNING THE SHIELD 19

used in home automation systems. Therefore, I planned to include:

• A relay with a current sensor to control lamps & measure their energyconsumption at the same time

• A temperature & humidity sensor• A light level sensor• The possibility to connect a motion sensor & a contact sensor if needed

What you also have to consider is the compatibility of your shield with othershields. For example, if you want to use your shield with a shield that is com-mercially available. I wanted my shield to be compatible with the AdafruitCC3000 WiFi shield:

https://www.adafruit.com/products/1491

Therefore, I made sure that I didn’t use the same pins as the WiFi shield Iwanted to use.

The first step is the design of the schematic of the shield. The first thing youneed to do is to place the main component that will contain the different pinsof the shield. Luckily for us, the SparkFun library has this component:

Page 34: Design Guide Book

20 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

You can now place the shield in the schematic editor:

The next step is to place the different components you want to use inside yourshield in the schematic editor. Then, you have to connect them together. This iscompletely dependent of the components you chose for your own project, butyou simply have to go through the ‘Add’ menu for each component. This is thecompleted schematic:

Page 35: Design Guide Book

3.2. DESIGNING THE SHIELD 21

The next step is to make the layout for our shield. Remember that this is an Ar-duino shield that needs to be compatible with existing Arduino boards. There-fore, you are pretty much constrained in space. This is a picture the layout withall components placed on the board:

Page 36: Design Guide Book

22 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

After using the autorouter included in Eagle, I routed my Arduino shield. Thisis a picture with the routing completed:

Page 37: Design Guide Book

3.2. DESIGNING THE SHIELD 23

Finally, to end the design phase, we have to verify the design against a givennumber of rules. This will make sure that the PCB can be produced reliably.This step is called Design Rule Checking (DRC) and can be done automati-cally by Eagle. For the rules themselves, I recommend using the rules fromSparkFun:

http://www.sparkfun.com/tutorial/Eagle-DFM/SparkFun.dru

Simply download this file and put it in the /dru folder of Eagle. Then, go toTools>DRC, and from there load the file that you just downloaded. Then, clickon Check to launch the verification. If there are any errors, you will be notifiedwith a basic description of each error. After this step, you will have to iterateyour layout design again till all the errors are gone.

Note that you can find the complete design inside the GitHub repository of thebook:

https://github.com/openhomeautomation/pcb-book

Page 38: Design Guide Book

24 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

3.3 Fabrication

It is now time to manufacture our Arduino shield. There are many services youcan use for this step, and this is completely up to you. However, as this is ourfirst PCB project, I will recommend you to use the service from OSH Park asthey have a very simple process to produce your PCB. The first step is to goover to their website:

https://oshpark.com/

You will be prompted to upload your layout file. The nice thing about OSHPark is that you can directly upload Eagle files, without having to export themin another format:

After a while, the OSH Park website will detect the different layers of yourboard and generate a preview on their website:

Page 39: Design Guide Book

3.4. RESULT 25

At this stage, you will also be able to enter the name of your project, and yourpersonal information. After that, you will be prompted to pay in order to startthe manufacturing of the board.

After you ordered the board, also make sure to order all the components thatyou will need to assemble your shield. There is nothing more frustrating thannot being able to assemble the PCB because you are missing some components.

3.4 Result

After two weeks, I received the PCB in my mailbox:

Page 40: Design Guide Book

26 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

I then assembled it with the components I ordered. This is the result:

Page 41: Design Guide Book

3.5. HOW TO GO FURTHER 27

Now, the last important step is to have something in place to test the board. Iused a simple Arduino sketch to test the different functionalities of the shieldautomatically. This way, I can quickly identify bugs on your board.

This step is very important as most of the time you will have one bug or two onyour board. Based on this step, you will need to iterate with the feedback youget from this initial test phase.

3.5 How to Go Further

Let’s summarize what we learned in this chapter. We learned how to designyour own Arduino shield for home automation purposes. We saw the wholeprocess, from the design of the board, to the manufacturing process, and finallyto the test of the board.

Page 42: Design Guide Book

28 CHAPTER 3. DESIGNING AN ARDUINO SHIELD

You can use what you learned in this chapter to build your own Arduino shieldsfor home automation applications. You can for example use the example designof this chapter as a reference. You can add other sensors on the shield, or othercomponents like LCD displays or components to connect DC motors.

Page 43: Design Guide Book

Chapter 4

Designing Your OwnArduino Board

In this last chapter of the book, we are going to use everything we learned inthis book so far and make our own Arduino board. We will see how to definethe characteristics of our board, and then how to design it and how to build it.Finally, we are going to test the board when it comes back from the factory.

As an example, we are going to build a smaller version of the Arduino Proboard. We will get some inspiration from the Arduino Pro board design, andmake our own board from it.

As with the previous chapter, I will mainly describe the design flow over thesmall details of the design process. The goal is to show you how to design yourboard from your own ideas, and not to show you how to design this specificboard.

4.1 Hardware & Software Requirements

On the hardware side, you will need pretty much nothin. Indeed, we are goingto use an online service that will take care of all the hardware parts for use.

29

Page 44: Design Guide Book

30 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

We are going to use the PCB assembly service of SeeedStudio to automaticallybuild and assemble our boards.

However, this also means we will have to pick our components in a defined list,but this will not be a problem for our project. You can already have a look atthis list here:

http://www.seeedstudio.com/wiki/Open_parts_library

On the software side, you will need the latest version of Eagle to design thePCB. You can grab it at:

http://www.cadsoftusa.com/download-eagle/

You will also need to install the Eagle library for the Open Parts Library, so wecan be sure to only use the allowed components for the board:

http://www.seeedstudio.com/wiki/File:OPL_eagle_library.zip

To install the library, simply place it in the /lbr folder inside your Eagle mainfolder. To activate the library and use it in a new project, you have to be sure toclick on “Use all” when starting Eagle:

Page 45: Design Guide Book

4.2. DESIGNING THE BOARD 31

You will also need the SparkFun CAM file for Eagle. We will use this file laterto export the design files from Eagle & send them to the manufacturer. You canget the file here:

http://www.sparkfun.com/tutorial/Eagle-DFM/sfe-gerb274x.cam

To install this file, simply place it in the /cam folder inside your Eagle mainfolder.

4.2 Designing the Board

We are now going to design the board itself. As I mentioned before, I used theArduino Pro board design as the reference for my own design:

http://arduino.cc/en/Main/ArduinoBoardPro

Page 46: Design Guide Book

32 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

The Arduino Pro is basically a board that removes what is not needed fromthe Arduino Uno board. I wanted to have a similar board, but I also wanted tomake some small changes:

• First, I wanted to be able to program the board directly by plugging it viaa microUSB cable, and not using any external components

• I also wanted to have a “low-power” mode, meaning being able to discon-nect the programming part from the microcontroller part to save power

• I also wanted to squeeze down the design as much as possible whilekeeping the compatibility with existing Arduino shields

I wanted to have this board to test low-power home automation projects basedon Arduino, like low-power wireless motion sensors.

Remember, all the components used for this project have to be picked insidethe Open Parts Library:

http://www.seeedstudio.com/wiki/Open_parts_library

The first step is to make the schematic of our board, using only componentsfrom the OPL library. You can click on ‘Add’ to place a new component insidethe schematic, and look for the OPL library:

Page 47: Design Guide Book

4.2. DESIGNING THE BOARD 33

You can then place the different components, and connect them together. AsI want to insist on the design flow in this chapter, I won’t detail how I picked& placed every single components. This completely depends on the board youwant to design. This is a screenshot with the completed schematic:

Page 48: Design Guide Book

34 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

Let’s now move to the layout of the board. The goal here is to place the differentcomponents to minimize the space of the final board. However, as I wanted tokeep the compatibility with existing Arduino shields I was constrained by theconnectors to connect an Arduino shield.

This is a screenshot of the layout, which is not routed at this point:

Page 49: Design Guide Book

4.2. DESIGNING THE BOARD 35

Finally, I used the autorouter module of Eagle to route the board. This is ascreenshot of the final layout for this board:

Page 50: Design Guide Book

36 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

Note that you can find the complete design inside the GitHub repository of thebook:

https://github.com/openhomeautomation/pcb-book

Finally, to end the design phase, we have to verify the design against a givennumber of rules to make sure that the PCB can be produced reliably. Thisstep is called Design Rule Checking (DRC) and can be done automatically byEagle. For the rules themselves, I recommend using the rules from SparkFun:

http://www.sparkfun.com/tutorial/Eagle-DFM/SparkFun.dru

Simply download this file and put it in the /dru folder of Eagle. Then, goto Tools>DRC, and from there load the file that you just downloaded. Then,click on “Check” to launch the verification. If there are any errors, you will

Page 51: Design Guide Book

4.3. FABRICATION 37

be notified with a basic description of each error. After this step, you have toiterate your layout design again till all the errors are gone.

4.3 Fabrication

Now that our design is ready, we can fabricate the board. The first step is toexport the design to a format that can be understood by the PCB fabricationservice. Most of the online PCB manufacturers require the designs to be in theGerber format. Luckily for us, Eagle makes it very easy to export our design inthe Gerber format.

First, in your layout view go to File>CAM Processor. This should open a newwindow, where we can decide how we are going to export the design files tothe Gerber format. We also don’t have to do that ourselves: some companiesalready did an excellent job in creating templates for the Eagle CAM Processor.I recommend downloading the CAM settings from SparkFun:

http://www.sparkfun.com/tutorial/Eagle-DFM/sfe-gerb274x.cam

Then, go to File>Open>Job to open the file you just downloaded. Everything isalready setup for you, so you can just click on ‘Process Job’ to start exportingfiles in the Gerber format. Finally, you can collect all the files that were createdin the same folder as your design, and create a ZIP file from them. This is thefile we are going to send to the manufacturer.

As mentioned before, we will use the PCB assembly service of SeeedStudio tofabricate the boards. To start the process, you can go over to the following link:

http://www.seeedstudio.com/service/index.php?r=site/pcbService&type=pcba

You will be taken to a page that will ask you some basic information about yourproject:

Page 52: Design Guide Book

38 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

Enter these information carefully, you won’t be able to change them after that.The next step is to actually upload the ZIP file that contains all the design filesin Gerber format:

The next step is then to create the BOM of your project:

Page 53: Design Guide Book

4.4. RESULT 39

BOM stands for bill of materials, and contains all the information about whichcomponents were used in our design. You can upload it from Eagle, but usu-ally that doesn’t work so well and it still requires a lot of work after the upload.What I really recommend is using the online BOM creator provided by Seeed-Studio:

Finally, after this step you will be taken to the confirmation page where youcan enter the delivery address & pay.

4.4 Result

After some time, you will receive the board from the manufacturer. This is aside view of one of the board I received:

Page 54: Design Guide Book

40 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

This is a top view of the same board:

Page 55: Design Guide Book

4.5. HOW TO GO FURTHER 41

It is now time to run some tests. This step will of course greatly depend onyour own project. For the board I used as an example in this chapter, I simplyrun my usual Arduino sketches as a test. I did so because this board is a fullyfunctional Arduino board that you can just use as an Arduino Uno.

4.5 How to Go Further

Let’s summarize what we learned in this chapter. We learned about the differ-ent steps to completely design an Arduino system from scratch, from the initialidea of the board to the manufacturing. We learned how to use Eagle to designa board from scratch, by getting inspiration from already existing open-sourcehardware projects. We also saw how to export the board in format that can besent to a manufacturer. Finally, we learned how to use an online PCB manufac-turing and assembly service, so you don’t have to order your own components

Page 56: Design Guide Book

42 CHAPTER 4. DESIGNING YOUR OWN ARDUINO BOARD

& solder them on the boards.

You can use what you learned in this chapter to build your own home automa-tion boards based on Arduino. You can simply modify the design of the ex-ample board I used in this chapter and build your own system from it. Forexample, you can eliminate some components like the pin headers and reducethe size of the board. By doing so, you can build a low-power motion sensorboard that can be used in home automation. You can also start from scratch,and design your own system from one of your ideas.

Page 57: Design Guide Book

Chapter 5

Conclusion

5.1 What did you Learn in This Book?

Let’s first summarize what you learned in this book. In the first chapter, welearned how to build an Arduino system from scratch on a breadboard. Thisgave you a good knowledge about how Arduino systems are built, and how tore-create an Arduino system on a breadboard.

In the second chapter of the book, we saw how to drastically reduce the powerconsumption of the Arduino system we built earlier. This allowed a reductionof the energy consumption by several orders of magnitude. This is perfect ifyou want to design your own motion sensors for example.

In the third chapter of the book, we designed our own Arduino shield usingthe Eagle PCB design software. The goal of this chapter was to give you thebasics of PCB design. You also learned how to get your PCB manufacturedand assembled.

Finally, in the last chapter of the book, we designed a more complex board witheverything we learned so far. We saw how to leverage the advantage of Open-Source Hardware to re-use an existing design in order to create a new board forhome automation.

43

Page 58: Design Guide Book

44 CHAPTER 5. CONCLUSION

5.2 How to go Further

There are many ways to go further with what you learned in this book. Thefirst thing I would recommend is to do all the projects of this book yourself,and especially produce your own PCBs from the design to the assembly of thecomponents on the PCB.

Then, when you are comfortable with the process, I would recommend start-ing designing your own boards for home automation and experiment with theprocess. There is something fun and really gratifying in the process of makingyour own boards. I really recommend experimenting, experimenting and ex-perimenting, and building your own home automaton systems that are tailoredto your needs. And of course, don’t forget to have fun in the process.

Page 59: Design Guide Book

Chapter 6

Resources

This last chapter of the book is a list of the best resources concerning PCBdesign for open-source home automation systems. I organized this chapter indifferent categories so you it is easier for you to find the information you need.

6.1 General Information on PCB Design & Arduino

• Arduino: The reference website of the Arduino platform. Especiallygo over to their fantastic forums to find help on your Arduino relatedprojects.

• Instructables: A website containing step-by-step projects. Search therefor “PCB” or “PCB design” and you will find a lot of exciting projects.

6.2 PCB Design Tools

• EAGLE: The most used PCB design software in the open-source hard-ware community. Most of the shared open-source PCB designs are madeusing this software.

45

Page 60: Design Guide Book

46 CHAPTER 6. RESOURCES

• KiCad: An open-source software PCB design tool. It is not at the levelof EAGLE yet, but it is continuously improving.

• Upverter: An online PCB design tool. Because this tool is 100% online,it is very easy to share designs with other users.

6.3 Components• SparkFun: A website selling many Arduino related products. All their

products are open-source and you can download the source files directlyfrom their product descriptions.

• Farnell/Element14: A large online reseller of electronic components.

6.4 PCB Manufacturers• OSH Park: My favorite place to go to have my PCB manufactured. You

can directly upload your Eagle PCB design files, and you get your PCBin your mailbox two weeks later.

• SeeedStudio: Another PCB manufacturer, they also propose a PCB as-sembly service to get your components assembled on your board as well.

6.5 Suggested Readings• Make Your Own PCBs with EAGLE: A very good introduction to PCB

design using Eagle.• The Circuit Designer’s Companion, Third Edition: The reference for

PCB design.• EEVblog Electronics Resource Wiki: A fantastic online resource on PCB

design & electronics in general.