Arduino+Data+Logger

=Why are Arduinos useful?=  Arduinos are small, programmable computers that can interact with and control electronic circuits. They provide a pathway to achieving two goals: data collection, and energy management.

Changing how we use our energy requires knowledge of how we use it to begin with. Simple, inexpensive circuits can be designed to give the Arduino the ability to measure important values such as voltage, power, and temperature. The data can then be stored and later evaluated. This method of data logging is especially important for projects such as the Photovoltaic Cookstove.

Utilizing less fossil fuel in favor of renewables, such as solar, will require us to make choices on how to use a limited supply of power. Once our choices are made, informed by information gathered through data logging, a program can be easily written and uploaded onto an Arduino to implement our preferences. (See Electrical Priority Switchboard) =How can Arduinos take and record measurements?=

Arduinos have digital and analog channels it uses to interact with circuits and electrical devices. These channels can output or receive an input voltage between 0 and 5 volts.

Using these channels the Arduino can measure voltage directly through the use of a voltage divider, measure temperature indirectly by communicating with an external temperature sensor (such as the MAX31855), and record the data onto an SD card with an SD Shield.

=Measuring Voltage To Determine Power=

Power in an electrical circuit is given by:

As long as you know 2 of the 3 important values that characterize a circuit (voltage, current, and resistance) you can calculate the power. Often times the resistance value will already be known, especially when working with devices that use resistive heating such as the Photovoltaic Cookstove. Therefore all you need is either the current or the voltage to calculate power. Since the Arduino is already equipped to measure voltage, that is often the easier value to find. Keep in mind that the Arduino channels can only handle up to 5 volts. Anything higher will almost certainly damage the Arduino. To measure anything greater than 5 volts, a voltage divider will be necessary.

__DC Power__
For DC (Direct Current) circuits voltage is constant and easily measured. Connect the voltage divider //in parallel// with the electrical device of interest:

[[image:appropriatetechnology/filepage1.jpg width="800" height="389"]]
The voltage divider should have a total resistance (R1 + R2) at least 10,000 times greater than that of the electrical device so that as little current as possible is drawn to the Arduino. Furthermore the ratio of R1 to R2 should be chosen so that the voltage between them never exceeds 5 volts. To determine the voltage across the entire divider, simply multiply the voltage measured by the Arduino by the conversion factor [(R1 + R2) / R2].

__AC Power__
For AC (Alternating Current) circuits voltage is constantly changing from positive, to negative, to positive again in a sine wave fashion. Power is calculated using the //Root Mean Squared (RMS)// voltage, or RMS current. This is equal to the peak voltage or current divided by the square root of 2.

To measure this voltage will require the extra step of rectifying (converting) the current to DC using a diode. Once this is done the voltage divider can be used as before so the Arduino can measure voltage. This process also requires an additional conversion factor so the Arduino can calculate the RMS voltage using the rectified voltage.



= = = Taking Other Measurements =

Additional measurements can be made through the purchase of inexpensive devices such as the MAX31855 Temperature Sensor. This device has the ability to measure air temperature, as well as some external temperature (such as the inside of an oven or a glass of water) through the use of a thermocouple.

There is a broad selection of devices that can be found which measure everything from gravitational acceleration to ambient brightness.


 * __User's Guide- how to set u__ **** __p for data__ ** __ **collection** __

** (Builder's guide can be found below) **
The first thing is to decide is what features you need for the measurements you want to take. Your options include: If you want instructions on building the device from scratch check out the Builder’s Guide
 * 1) Using a Display or Low Power Mode
 * 2) Oven Temperature
 * 3) Air Temperature
 * 4) Set Temperature
 * 5) Power Supplied by the Panel
 * 6) Time Stamping the Data

Quick Start: If you already have the device built and programmed just power it (by putting 5-20 V across pins Vin and Gnd) and it will start taking temperature data right away. Just ignore the year column of recorded data and if you want to take power data you should really read the relevant section so you don’t damage the Arduino. The buttons on the LCD control set temp and when the oven temp is larger than the set temp pin D0 will go high which could be used to disconnect the heating element with a relay.

note: All temperatures are in C˚

>>> >>
 * 1.) Display or Low power - This is fairly self explanatory, do you want a live display with an adjustable set temp or low power record only setup for extended battery life
 * For the display use the code “PVEOvenDataLogger_Improved.ino”
 * Records data every 5 sec
 * For the display use the code “PVEOvenDataLogger_LowPower.ino”
 * Records data every 8 sec
 * If you already have the code on the board you are ready to move on but it not you can upload it by:
 * Opening the file you want to upload in Arduino Software (IDE)
 * Which can be downloded free at [|__https://www.arduino.cc/en/Main/Software__] if you haven’t already
 * Plug in the Arduino board via USB
 * Go to the menu bar and find Tools>>Port>> …(Arduino Uno) it will probably be the only non bluetooth option (Mac version pictured)
 * If you have not downloaded the extra libraries (you only have to do this and the next step once per computer) go to each of the following sites and do so by clicking on “Clone or download” then “Download ZIP”[[image:https://lh4.googleusercontent.com/Has5daBmwAfJXQmUny6ZR7fDwD8HkhL_OYVM6xGsvmWz9Y7Wog06iyql_6eMgCoB6nQnpEp-ktm5Mcb9mHOVWmOOjcgdUSmiUIPx1EKaFnn0BZXEYnGv-W0KN5O-hND_5y7G29rS width="394" height="228"]]
 * LCD- [|__https://github.com/adafruit/Adafruit-RGB-LCD-Shield-Library__]
 * Time- [|__https://github.com/PaulStoffregen/Time__]
 * Thermocouple- [|__https://github.com/adafruit/Adafruit-MAX31855-library__]
 * Low power- [|__https://github.com/rocketscream/Low-Power__]
 * Next you extract the files to the right place but the Arduino Software will do that for you if you go to Sketch>>Include Library>> Add .ZIP Library and find where you initially downloaded the .ZIP file (do this for each) [[image:https://docs.google.com/drawings/d/s0Pd8O3NBfEBWKQzrhW3WlQ/image?w=621&h=188&rev=18&ac=1 width="621" height="188"]]
 * Finally click the upload button, it’s the right pointing arrow in the upper right (also shown boxed above)
 * If you get an error check that you have the right type of board selected and then look online for Arduino’s Troubleshooting guide
 * 2.) Oven Temp (C˚)- This will be displayed at the bottom of the LCD and in the third column of the data file and serial output (the serial output can be seen by pressing command+shift+M on a Mac immediately after uploading or going to the tools dropdown and clicking Serial Monitor)
 * For all data logging functions you should make sure there is a file called “DATALOG.CSV” outside of any folders on the SD card since that is where the data is written. Though if it doesn't exist the Arduino will make one so don’t worry about this too much.
 * To help keep the columns straight in order they are: Power, Air Temp, Oven Temp, Year, Month, Day, Hour, Minute, Second, Set Point
 * The only other thing you need to do to set this up is make sure the TC wires are properly attached to TC (MAX31855) and the interpreter is connected to the arduino
 * These need to be K-type wires and sometimes red(-) and yellow(+) can be labeled backwards so it is worth checking if the temp goes up when it should go down
 * The pins for the interpreter to the Arduino are Vin to 5V, 3Vo to nothing, Gnd to Gnd, D0 to D8, CS to D9, CLK to D10[[image:https://lh6.googleusercontent.com/l134BMa9zN9xK4dU1lmdGFOiX4Pyq1widHHsWUzKRZzw2bGNRiDpzflsKZqxgv8_XbAjsGE1DxVKBAV-a3vBDAKICmFznpE76pa-7ZrfVOzs3Qd_QnT06W7UQI5QD1m7IJFjsdTo width="287" height="234"]]
 * 3.) Air Temp (C˚)- This is not sent to the LCD but is recorded on the SD card. It is output in the second column of the data file and serial output
 * This is recorded by the TC interpreter (MAX31855) and so should work as long as that is connected (whether or not there are TCs)
 * 4.) Set Temp (C˚)- This is only on the version with a display but can easily be re-added to the low power version (see Builder’s guide). It is shown in the upper right of the LCD and recorded in the last column of the data file.
 * The starting value is 100 C˚
 * And can be changed by 10˚ with the up and down arrows as well as by 1˚ with the right and left arrows (the select button on the LCD board currently does nothing)
 * When the oven temp is above the set point pin D0 will be high which can be used to trip a relay and disconnect the load
 * 5.) Power (W) - This is displayed in the top right of the LCD as well as the first column of the data file and serial output. It is the one you might have to change some code for.
 * The arduino can only handle 5V so you need to make sure you are never sending more than that to a pin in this case it is the A0 pin to worry about
 * This can be done by making a voltage divider with 2 resistors where the voltage at A0 is V*(R2/(R1+R2)) and should be kept under 5 using the panel’s “open circuit voltage” for V, Also values in the hundreds of kΩ should be used since you want as little current as possible to flow through this branch.
 * Because of division, in the code there is a line to account for it that will need to be changed if you are using a different divider:
 * power = power * 6.1; //divider voltage
 * Change 6.1 to your divider ratio


 * Also the next line assumes a heater element resistance of 12Ω
 * power = power*power/12.0; // V^2/Rload
 * Change 12.0 to your element’s resistance


 * If you are not using a relay to disconnect the load when the oven temperature is above the setpoint add 2 forward slashes to the beginning of (or just delete) the line power = 0;
 * 6.) Time Stamp - This is displayed in the 4th - 9th column of the data file and serial output.
 * It defaults to a time t value of 0 which corresponds to new year's 1970 and you can see the time the device has been on simply by ignoring the year column. It should be noted though that the time library handles things like month length and leap days and whatnot so it will be wrong over long periods of time if you don’t set the time as below.
 * The time t value can be set by including a file called “Time.txt” that only contains the number of seconds since 1970.
 * This can be found on a Mac (or other unix system) by going to the terminal and typing:
 * //date +"%s"//
 * And pressing enter
 * Once you have it just copy the value it gives in to the .txt file and you are good to go (there is obviously going to be a delay between when you save the file and when you move the SD card to the Arduino and begin measurements but it is likely these few seconds don’t matter for this application)
 * There is a line of code that can be used to set the time zone if it is re-added (this will give bogus times in the 2100s if you are starting at 0 because time t will underflow)
 * //adjustTime(3600 * (-8));// adjust for time zone
 * Remove the first 2 slashes and change the -8 to your time zone


 * __ Builder's Guide- how to make and modify the device __**

First you need to find all of the parts: Arduino -The official one is pretty much guaranteed to work ( [|__http://store-usa.arduino.cc/products/a000066__] ) but you can find clones for almost a fith the price that should be fine (the first one I got would only connect to windows computers but the rest have been fine) [|__http://www.gearbest.com/development-boards/pp_62975.html?currency=USD&gclid=CjwKEAjwya-6BRDR3p6FuY2-u3MSJAD1paxTVj_vxpQaFiKS0AFDgGW09ufyoBxF7BeqG8IbHVMdthoCwPTw_wcB__] or at any of a number of simalar sites (shop around) SD shield- the Seeed SD Card Shield is easy to set up and can be found at radioshack though there exist much cheaper versions that you will have to wire up to the a Arduino yourself. I recomend starting with the easy one then looking at one of the smaller SPI ones (which are super cheap) for your second model- [|__https://www.seeedstudio.com/item_detail.html?p_id=492__] SD Card- any will work (even micro) you should be able to find 8GB for $5 and 16GB for not too much more - [|__http://www.adorama.com/IDSSDHC8G.html?gclid=CjwKEAjwya-6BRDR3p6FuY2-u3MSJAD1paxTraW55u3mRRwZCCknCgn5gbBxs1guSZLYtg1erRYrxBoCoqHw_wcB__] (shop around) LCD- You could use a more basic LCD but this one only uses 2 pins so you can add a bunch more TC interpreters (you’d probably max out at 8-10 of the SPI ones below) - [|__https://www.adafruit.com/products/772__] Thermocouple interpreter- [|__https://www.adafruit.com/product/269__] TC Wire- [|__http://www.omega.com/pptst/SPIR.html__] Jumper Wires (or anything conductive)- [|__http://www.amazon.com/dp/B017NEGTXC/ref=pd_lpo_sbs_dp_ss_3?pf_rd_p=1944687442&pf_rd_s=lpo-top-stripe-1&pf_rd_t=201&pf_rd_i=B0040DEI9M&pf_rd_m=ATVPDKIKX0DER&pf_rd_r=1YP6AVETNFT201QGYPME__] *These are all possible sources but if you find a cheaper version go for it.

Once you have all the parts, there is some assembly and soldering to do. Soldering the thermocouple interpreter is pretty straight forwards but here is a page that goes over all the nuances that could occur- [|__https://learn.adafruit.com/thermocouple?view=all__]. The LCD has a similar guide here [|__https://learn.adafruit.com/rgb-lcd-shield/assembly__] but the important parts are: the buttons can be put in either way that they easily fit, there is only one way to put in the potentiometer and it’s ovious, for the resisters R1=4.7kΩ, R2=4.7kΩ, RED=220Ω, BLUE=220Ω, & GREEN=330Ω, the I2C expander chip (MCP23017) shloud be placeed with pin 28 closest to the reset button (the text on the chip will probably be “upsidedown”), and for the header pins it is a good idea to place them in the ardino before soldering them to make sure they will be straight. Also if you can find extra long leg headers you won’t have to solder on extra connections to the top level stubs (this kit comes with enough extra header pins that you can [extra soldering connections pictured below] but it is a pain).  The final bit of soldering is optional but you can remove the ON indicator LED (boxed below) to save battery life (about 3mA as detailed in this article) [|__http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/__] 

Moving on to programming; you can look at the User's Guide for how to put a program on the board, and how to include the proper libraries (they can be downloaded at these links). LCD- [|__https://github.com/adafruit/Adafruit-RGB-LCD-Shield-Library__] Time- [|__https://github.com/PaulStoffregen/Time__] Thermocouple- [|__https://github.com/adafruit/Adafruit-MAX31855-library__] Low power- [|__https://github.com/rocketscream/Low-Power__]

Things you might want to change- the code is pretty thoroughly annotated and worth playing around with but there were a couple of points I wanted to add more detail to. // if (oven_temp > thermostat) { check against set temp // // digitalWrite(0, HIGH); trip the relay to disconnect the load // // power = 0; load is disconnected so set power to zero. // // } // //else {// // digitalWrite(0, LOW);relax the relay to reconnect the load // }// // int thermostat = 100; //set temp = 100C to start//
 * Time stamping
 * instead calling (String) year + "," + (String) month + "," + etc to make a string with the date, you could use division and modulo functions to represent the time since start up just as a number of days, hours, etc. This would handle using default time of 0 better
 * This would be the better way to keep track of the time since first light for a version unpowered at night.
 * Or you could use a low power clock with a small battery to check the time
 *  Data collection rate
 *  On the LCD version you can take data points pretty much as often as you want down to the resolution of how quickly you are polling the buttons (currently 10 Hz but this is also changeable). To do this just change the comparison value in this if statement if(currentMillis - previousMillis >= 5000) it is in milliseconds
 * On the low power version the sleep timer from this library can only run for: 15ms, 30ms, 60ms, 120ms, 250ms, 500ms, 1s, 2s, 4s, or 8s (also forever until it gets a external interrupt but you can find more info on that elsewhere). If you absolutely need a specific time in between data points you can chain these together one after the other. Just make sure you adjust your timestamp appropriately as time t does not increment while in low power mode
 * Set Temp
 * This can easily be re added to the low power version by un commenting out the relevant if statement
 * <span style="font-family: Arial; font-size: 14.6667px; line-height: 1.38; list-style-type: circle; margin-bottom: 0pt; margin-top: 0pt; vertical-align: baseline; white-space: pre-wrap;">There is no live control for the low power version (you could add some buttons[I’d recommend looking at using an external interrupt from the low power library]) but you can change the max temp before hand with this line

<span style="font-family: Arial; font-size: 14.6667px; line-height: 1.38; margin-bottom: 0pt; margin-top: 0pt; vertical-align: baseline; white-space: pre-wrap;">Resource links- some of these have already been referenced but these are a good place to start if you want to learn more about a specific part of this project: LCD- [|__https://learn.adafruit.com/rgb-lcd-shield__] Thermocouple- [|__https://learn.adafruit.com/thermocouple/__] Time- [|__http://www.pjrc.com/teensy/td_libs_Time.html__] SD- there are more functions that have been inherited from file I/O stuff (like parseInt ) but this is a good start- [|__https://www.arduino.cc/en/Reference/SD__] Low power mode and timer wakeup- [|__http://www.home-automation-community.com/arduino-low-power-how-to-run-atmega328p-for-a-year-on-coin-cell-battery/__]


 * **Garrett O'Neill - 5th year Physics student with interests in Arduinos and renewable energy technology.**