uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size...

11
The Green Building Research Lab @ Portland State University Director, Elliott T. Gall www.pdx.edu/green-building 1 Build instructions for Arduino CO 2 Monitor, Logger and Display The following instructions are provided to assist you in developing a CO2 sensor that can: Measure CO 2 levels in air and record it to a memory card Record CO2 according to the frequency you set in a program (i.e., store a value and timestamp every 1 second, every 5 minutes, etc.) Display the current CO 2 level being measured on a LCD screen. o The brightness of the screen can be adjusted with a potentiometer Be powered independently from your computer, that is, can operate from a normal wall outlet Optional: a real-time clock provides a means of measuring the absolute time (useful if you leave the sensor for long periods of time and are trying to interpret your data) It is recommended that before attempting this build you have completed the circuit builds #1 (Blinking and LED), #2 (Reading a potentiometer), and #6 (reading a photoresistor) from the Sparkfun Inventor’s Kit (SIK). While working on this circuit, try to enjoy the process and know that troubleshooting is an important part building circuits and research in general! Even individuals very experienced with microcontrollers and circuits will spend a lot of time debugging – in fact, the debugging process is central to the learning objectives of this exercise, as it embodies problem-solving skills that are best achieved through a methodical isolation of the various components of your system. These are important skills in science and research! Acknowledgements: This project was supported the BUILT Lab Faculty Fellowship program at Portland State University. Many individuals have contributed to the evolution of this project: Craig Lardiere, Kalina Vanderpoel, Samuel Salin, David Pleshakov, and Corey Griffin. Materials Inventory your materials. Between the Sparkfun Inventor’s Kit (SIK) and the bag of CO 2 sensor parts you have received, you should have the following parts necessary for this build: Arduino Pro Mini 328 3.3V/8MHz This is the “brain” of the operation. It works similarly to the RedBoard used for the SIK circuits, but is a little more compact. It’s good to get used to different versions of microcontrollers and see how they are similar and how they are different.

Transcript of uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size...

Page 1: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

The Green Building Research Lab @ Portland State University Director, Elliott T. Gall www.pdx.edu/green-building

1

Build instructions for Arduino CO2 Monitor, Logger and Display

The following instructions are provided to assist you in developing a CO2 sensor that can:

Measure CO2 levels in air and record it to a memory card

Record CO2 according to the frequency you set in a program (i.e., store a value and timestamp

every 1 second, every 5 minutes, etc.)

Display the current CO2 level being measured on a LCD screen.

o The brightness of the screen can be adjusted with a potentiometer

Be powered independently from your computer, that is, can operate from a normal wall outlet

Optional: a real-time clock provides a means of measuring the absolute time (useful if you leave

the sensor for long periods of time and are trying to interpret your data)

It is recommended that before attempting this build you have completed the circuit builds #1 (Blinking

and LED), #2 (Reading a potentiometer), and #6 (reading a photoresistor) from the Sparkfun Inventor’s

Kit (SIK). While working on this circuit, try to enjoy the process and know that troubleshooting is an

important part building circuits and research in general! Even individuals very experienced with

microcontrollers and circuits will spend a lot of time debugging – in fact, the debugging process is

central to the learning objectives of this exercise, as it embodies problem-solving skills that are best

achieved through a methodical isolation of the various components of your system. These are important

skills in science and research!

Acknowledgements: This project was supported the BUILT Lab Faculty Fellowship program at Portland

State University. Many individuals have contributed to the evolution of this project: Craig Lardiere,

Kalina Vanderpoel, Samuel Salin, David Pleshakov, and Corey Griffin.

Materials Inventory your materials. Between the Sparkfun Inventor’s Kit (SIK) and the bag of CO2 sensor parts you

have received, you should have the following parts necessary for this build:

Arduino Pro Mini 328 3.3V/8MHz This is the “brain” of the operation. It works similarly to the RedBoard used for the SIK circuits, but is a little more compact. It’s good to get used to different versions of microcontrollers and see how they are similar and how they are different.

Page 2: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

2

K-30 10,000ppm CO2 sensor The sensor itself. The sensor contains circuity and onboard firmware out of the box. As we will see, there is also code provided by the manufacturer to read from the sensor. The white enclosure contains the infrared emitter and infrared detector that allow us to observe CO2 levels in air. microSD Transflash breakout and memory card Similar to the SD card in your phone or camera – this provides a means of storing the output from your CO2 sensor, along with a timestamp. The timestamp may be relative (from a counter that counts milliseconds on the Arduino) or from a real-time clock add-on to give absolute time.

Header pins These have likely already been connected to your components for you– but it’s important to know what these are. These are connections that allow you to easily connect components on the breadboard or directly via jumper cables.

DC Barrel jack adapter – breadboard compatible This provides a way to take power from the wall and apply it to your board. Pay attention to the installation and note where positive and negative leads should go! This is shown later in the instructions.

Wall Adapter power supply – 5V DC 2A Arduino has current (A, or amps) and voltage (V or volts) limits for what it can directly power. If you connect your Arduino directly to the DC Barrel Jack (which you will), you’ll need to make sure the input voltage is maximum of between 7-12 V (here it’s 5 V, so we’re good) or you risk frying your board.

FTDI Basic Breakout 3.3V Unlike the RedBoard, the pro mini does not have a permanent USB connection. This part will allow us to connect a USB cable to “talk” to our microcontroller and upload a program for it to run.

Full-size breadboard The SIK provides you a half-size breadboard, which is a little crowded for the build we’re doing here. You have been provided a longer breadboard – you’re welcome to use a smaller one if you prefer! 10K potentiometer A potentiometer is a variable resistor. You will use this potentiometer (similar to SIK Build #2) to vary the voltage powering the LCD that allows the backlight to be adjusted.

220 ohm resistor (or 330 ohm) Needed to provide the correct current to the LCD – you’ll see the wiring diagram later. Note that a 330 ohm resistor will work as well!

Page 3: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

3

2 female-female jumper cables There are two pins on your Arduino Pro Mini that will be much easier to connect to with a female jumper wire. These are the SCL and SDA pins labeled on your Arduino. For now, it’s enough to know that these are essential for communication between your CO2 sensor and the microcontroller via a protocol called I2C (pronounced “eye squared cee”)

Wires as necessary You will also need a number of male jumper wires. These can be obtained from your SIK, your bag of CO2 build parts, or spools of wire and pre-bent jumper cables available to you. This is largely up to you and how you want to lay out your circuit – some people like to be very neat, some people are less concerned about that. It’s better to spend the time and make things neat… You can strip wire from the spools to the exact length you want if you’re very particular. Also note the wire colors are there for your organizational benefit – It is customary to make power red and ground black, but color does not indicate a wire is different from any other (at least for the range of parts were working with here).

LCD display This component will let you see in real-time what your CO2 sensor is doing.

Part 1: Solder header pins onto components for assembly. NOTE: This is here for completion. Soldering has already been done for you! This section is included for

reference so that you are aware of what subsequent references to header pins are and where header

pins are soldered in the circuit. It also should illustrate that if, for example, you are later working on a

new project where you have ordered parts, you may need to conduct some prep work to use them on a

prototyping, solderless breadboard. By “prototyping, solderless breadboard” we mean that we are not

attempting to build a permanent, soldered circuit in this build, but rather want to be able to connect

and disconnect wires and components relatively easily as we build and troubleshoot the circuit.

Solder the header pins

Start with the Arduino Pro-mini. The side pins we want facing down (away from the numbered side) and

the top and middle pins facing up (opposite of previous, see Fig. 1 and 2 for details).

Page 4: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

4

Figure 1. Soldering pins onto the Arduino pro mini. Note that, for this build, you may or may not have

header pins connected to all four of the “internal” pins (the groups of two near the processor). You will

only need header pins to the group of two that are labeled “SCL” and “SDA”.

It is recommended to use a third arm and a fine-tip iron to accomplish all header soldering. Be careful

not to heat and potentially damage components on the boards or accidently bridge any connections.

Additional header pins need to be added to the SD-breakout and the K-30 CO2 sensor. Note that the CD

pin on the SD breakout is not used, however it is a good idea to attach a pin anyways. There are only 4

pins required to read the CO2 sensor out of dozens and so soldering only the 4 needed is recommended

on the K-30.

Figure 2. Soldered pins on the microSD breakout and the CO2 sensor

Part 2: CO2 sensor, SD card, and barrel-jack Build the circuit that allows the CO2 sensor to communicate with the Arduino pro mini and store data via

the microSD breakout.

Starting with a breadboard, place the microcontroller, SD breakout, sensor, and barrel jack spread out so

none of the pins will overlap, see Figure 3 for example. Note that if you’re using a full size breadboard,

you will have even more space to work with. On the barrel jack there is a third grounding leg which can

be cut off to better fit onto the breadboard. The positive and negative terminals of the barrel jack are

also labeled in the Figure 3.

Page 5: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

5

Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack

connector, and SD card.

A schematic that is known as a wiring diagram is shown below in Figure 4. This schematic allows you to

observe what connections need to be made to allow your components to be powered, grounded, and

communicate with each other as needed. Use jumper cables or wires as available. It is imperative that

you follow this diagram precisely! This part of building circuits is a pass/fail sort of operation, getting the

wiring almost correct will probably not result in a working circuit! It’s a bit like dialing a telephone

number – each digit must be correct or you won’t get the intended result. Note that the barrel-jack

connector in this diagram is not necessarily representative of the barrel-jack you are using (Figure 3) –

this schematic is stylized for convenience and to be able to show connections in a 2-D view.

Figure 4. Wiring diagram for CO2 sensor, SD cared, and barrel jack connector

Page 6: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

6

Pin connections can be also double checked by reviewing the sample Arduino code which lists the pin

connections required at the beginning of the code (see the link to a website containing the code at the

end of this document).

Also note that the wiring diagram above shows the barrel jack connecting directly to the Arduino RAW

pin. Given that more components than just the Arduino will draw from the wall power (note how the

CO2 sensor + and – pins intersect with the + and – from the barrel jack), you will be better served by

sending + and – leads from the barrel jack to the appropriate rails on the breadboard, as shown in Figure

5:

Figure 5. Suggested power wiring to make for easier connections to power other components (now the

entire rail labeled with a red plus sign is at +5 V and the rail labeled with a blue negative minus sign is at

ground (0 V)).

Make connections from the CO2 sensor to SCL and SDA pins using the female to female jumper cables

provided. Note that you will need to connect one side of the jumper cable from SCL or SDA (female

connector) to the board pin (male connector) aligned with the correct CO2 sensor pin. You can do this by

taking a small piece of wire and creating a female – male jumper cable as shown in Figure 6:

Figure 6. Modified female-female jumper cable that is now female-male.

Make the rest of the connections as indicated in Figure 4. In the end you should have something looking

like Figure 7. Try powering on your circuit as a test – if your circuit is powered correctly, you should see a

small red LED turn on embedded in the Arduino Pro Mini, and a green LED should flash once during

bootup. An orange LED should flash on your CO2 sensor periodically.

Page 7: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

7

Figure 7. Example of circuits containing barrel jack, CO2 sensor, Arduino pro mini, and SD card. Note – it

is a good idea to have your 5 in a row header pins on the Arduino pro mini facing the exterior of your

breadboard – this way, you will have unobstructed access for when we connect the FTDI breakout that

will let you connect the USB cable to the Arduino Pro Mini.

Part 3: Connecting the LCD Wire the LCD to the circuit – if you have a larger breadboard than pictured in Figure 8, there should

be plenty of room. If you are using a half-size breadboard, you may need to connect longer wires to

your CO2 sensor to free up space on the half-size breadboard to be able to connect the LCD panel

directly to the breadboard. An example on a half-sized breadboard is shown in Figure 8.

Figure 8. CO2 sensor circuit including LCD display.

The wiring diagram for connecting the LCD is shown in Figure 9. Note that you will need to hook up

your LCD to a potentiometer to adjust the backlight – this is very similar to the circuit you

constructed from the SIK Circuit #2!

Page 8: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

8

Figure 9. Wiring diagram for connecting the LCD display to the circuit. GND = ground. MINI_X are the

numbered pins on the Arduino Pro Mini. MINI RAW is the power rail as shown in Figure 5.

A few things to note about Figure 9. Start off by determining which LCD pin is pin 1. This can often

be accomplished by flipping your part over – see Figure 10 - and looking to the left and right of the

pins for numbering. It is possible that only the 16th pin will be labeled but if this is the case you

know that pin one is the pin farthest from pin 16. It’s also possible that the number will not be a

different color from the rest the hardware. There should be a raised outline if that is the case. Since

you are using the LCD panel provided with the SIK, the – and + should be clearly indicated –

however, you can see from Figure 9 that both pairs of pins at the ends require GND (-) and RAW (+).

So, unfortunately, this LCD is a bit trickier to determine. Google and you will eventually find a

detailed pinout or you can simply look at the labels on Figure 10.

Don’t worry that some pins are left unused; it’s supposed to be that way.

Figure 10. Order of pins on Sparkfun LCD required for wiring diagram shown in Figure 9.

Pin 1Pin 16

Page 9: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

9

Congrats! Your circuit is now constructed. It should look something like Figure 11 if you’ve used a

full-size breadboard (or like Figure 8 if you opted for the half-size):

Figure 11: Completed CO2 sensor, logger, and display

The code includes a status indicator light that will be useful to allow you to observe when the

monitor is taking a measurement. Build in an LED circuit (similar to SIK #1) on Pin 13 as shown below

in Figure 12. When we look at the code, it will make sense why this is here.

Figure 12. LED indicator light (yellow) that will pulse with each reading.

All the hardware should now be in place, and it’s time to work on getting the code onto the Arduino

so that it knows how to operate all those components!

Page 10: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

10

Part 4: Connecting the Arduino Install the Arduino IDE which can be found at [https://www.arduino.cc/en/Main/Software]. Consult

the readme or the Arduino website for issues installing the software.

Attach the FTDI breakout to the supplied micro-USB cable and then attach to the top header pins of

the Arduino (Figure 13). To ensure it is attached properly there is BLK and GRN printed on the

breakout and microcontroller which should be matched up on the same sides with each other.

Figure 13. FTDI breakout allows for a micro-USB to connect your Arduino pro mini to your computer.

When this is completed attach the USB to a computer with the Arduino IDE installed.

Part 5: Uploading the code Open the Arduino software.

The code for the circuit build can be downloaded at https://www.pdx.edu/green-building/nsf-

lsamp-and-bridge-day. Assuming you followed the indicated wiring diagrams and pinout

instructions, this could should be ready to operate your CO2 sensor.

Initially check to ensure the libraries Wire.h, SD.h, and LiquidCrystal.h are installed. This can be

accomplished by navigating to:

Sketch -> Include Library -> Manage Libraries…

Search for “wire” and “sd” and make sure the appropriate libraries have an “INSTALLED” message

next to them. The SD library may be a few from the top when searched for. If either library is not

installed, simply click on it and click the “Install” button on the right.

When both libraries are confirmed as installed navigate to:

Tools -> Board: “…”-> Arduino Pro or Pro Mini

When Pro or Pro Mini is selected navigate a few options down in the Tools menu to:

Page 11: uild instructions for Arduino O Monitor, Logger and … Figure 3. Example layout on half-size breadboard of the CO2 sensor, Arduino pro mini, barrel jack connector, and SD card. A

11

Tools -> Port: “…” -> COM#

If you are properly connected to the microcontroller and the correct board is selected there should

be one port option available.

Check to select that you have the correct processor selected (Figure 14). Double check the hardware

and ensure you have the correct voltage and clock speed of your processor (it should be 3.3 V and 8

Mhz if you are using the Pro Mini provided to you).

Figure 14. Selection of correct processor, necessary for ensuring the correct version of the Pro/Pro

Mini is recognized for the compiler.

Locate where you downloaded the code and click File…Open and navigate to the code.

When the new code is in place click the checkmark in the IDE to Verify the code. This will check to

make sure the libraries are installed and see if there are any errors in the code.

When finished compiling, upload the code to the microcontroller by clicking the arrow next to the

verify button. A series of rapidly blinking lights should be seen on the FTD breakout. When complete

the code is uploaded and the FTD breakout can be unplugged from the Arduino.

The data logger is now ready to be used! Plug in the 5V supply and the SD card into the card-slot and

readings will begin to be taken. Functionality of the K-30 can be confirmed by a blinking LED within

the sensor housing. The SD card will record readings every two seconds (variable, based on your

code) in a .csv file according the provided code. Consult the code notations for questions concerning

how to change the output of the sensor readings or any of the other workings of the data logger.

Part 6: Explore with your sensor You’re now ready to conduct experiments with your CO2 sensor.

Build a responsive circuit that uses the CO2 sensors output to actuate custom circuit you

build. The example provided in class takes the reading from the CO2 sensor, and if the value

is above a threshold (1000 ppm), then it turns on an LED. Use your imagination and the

components from the SIK to develop a custom, responsive circuit.