<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Bed_Data &#187; Arduino</title>
	<atom:link href="http://beddata.com/blog/?feed=rss2&#038;cat=7" rel="self" type="application/rss+xml" />
	<link>http://beddata.com/blog</link>
	<description>Bed Behavior Research</description>
	<lastBuildDate>Tue, 30 Mar 2010 04:03:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Arduino code for Bed_data</title>
		<link>http://beddata.com/blog/?p=57</link>
		<comments>http://beddata.com/blog/?p=57#comments</comments>
		<pubDate>Tue, 30 Mar 2010 04:03:23 +0000</pubDate>
		<dc:creator>mustafa</dc:creator>
				<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false">http://beddata.com/blog/?p=57</guid>
		<description><![CDATA[int sensorValue[80];  // an array to store the sensor values
// the address pins will go in order from the first one:
#define firstAddressPin 8
#define ThermistorPIN 0   // Analog Pin 0
double temp;
//////////////////////////////temperature alg
#include

//Schematic:
// [Ground] &#8212;- [10k-Resister] &#8212;&#8212;-&#124;&#8212;&#8212;- [Thermistor] &#8212;- [+5v]
//               [...]]]></description>
			<content:encoded><![CDATA[<p>int sensorValue[80];  // an array to store the sensor values</p>
<p>// the address pins will go in order from the first one:<br />
#define firstAddressPin 8</p>
<p>#define ThermistorPIN 0   // Analog Pin 0<br />
double temp;</p>
<p>//////////////////////////////temperature alg</p>
<p>#include<br />
<math.h>
//Schematic:<br />
// [Ground] &#8212;- [10k-Resister] &#8212;&#8212;-|&#8212;&#8212;- [Thermistor] &#8212;- [+5v]<br />
//                                     |<br />
//                                Analog Pin 0</p>
<p>double Thermistor(int RawADC) {<br />
  // Inputs ADC Value from Thermistor and outputs Temperature in Celsius<br />
  //  requires: include<br />
<math.h>
  // Utilizes the Steinhart-Hart Thermistor Equation:<br />
  //    Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3}<br />
  //    where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08<br />
  long Resistance;<br />
  double Temp;  // Dual-Purpose variable to save space.<br />
  Resistance=((10240000/RawADC) &#8211; 10000);  // Assuming a 10k Thermistor.  Calculation is actually: Resistance = (1024/ADC)<br />
  Temp = log(Resistance); // Saving the Log(resistance) so not to calculate it 4 times later. // &#8220;Temp&#8221; means &#8220;Temporary&#8221; on this line.<br />
  Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));   // Now it means both &#8220;Temporary&#8221; and &#8220;Temperature&#8221;<br />
  Temp = Temp &#8211; 273.15;  // Convert Kelvin to Celsius                                         // Now it only means &#8220;Temperature&#8221;</p>
<p>  // Uncomment this line for the function to return Fahrenheit instead.<br />
  //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit<br />
  return Temp;  // Return the Temperature<br />
}</p>
<p>double printDouble(double val, byte precision) {<br />
  // prints val with number of decimal places determine by precision<br />
  // precision is a number from 0 to 6 indicating the desired decimal places<br />
  // example: printDouble(3.1415, 2); // prints 3.14 (two decimal places)</p>
<p>  if( precision > 0) {</p>
<p>    unsigned long frac, mult = 1;<br />
    byte padding = precision -1;<br />
    while(precision&#8211;) mult *=10;<br />
    if(val >= 0) frac = (val &#8211; int(val)) * mult;<br />
    else frac = (int(val) &#8211; val) * mult;<br />
    unsigned long frac1 = frac;<br />
    while(frac1 /= 10) padding&#8211;;</p>
<p>    if(frac > 0.5){<br />
      val = val+1;<br />
    }<br />
    else{<br />
      val = val;<br />
    }</p>
<p>    Serial.print((int) val);<br />
  }<br />
}</p>
<p>////////////////end of temp</p>
<p>int analogInput = 0;<br />
int sensorNum = 0;</p>
<p>void setup() {<br />
  Serial.begin(115200);<br />
  // set the output pins:<br />
  for (int pinNumber = firstAddressPin; pinNumber < firstAddressPin + 4; pinNumber++) {<br />
    pinMode(pinNumber, OUTPUT);<br />
  }<br />
}</p>
<p>void loop() {</p>
<p>  // iterate once for every multiplexer (called muxes for short):<br />
  for (int mux = 0; mux < 5; mux++) {</p>
<p>    for (int channelNum = 0; channelNum < 16; channelNum ++) {<br />
      // determine the four address pin values from the channelNum:<br />
      setChannel(channelNum);</p>
<p>      // read the analog input and store it in the value array:<br />
      sensorValue[channelNum] = analogRead(analogInput+mux);</p>
<p>      if(analogInput+mux == 4&#038;&#038; channelNum == 14){<br />
        //////temp </p>
<p>        temp=sensorValue[channelNum]; </p>
<p>        temp = Thermistor(temp);      // read ADC and convert it to Celsius<br />
        //Serial.print(", Celsius: "); printDouble(temp,3);     // display Celsius</p>
<p>        temp = (temp * 9.0)/ 5.0 + 32.0;                      // converts to Fahrenheit</p>
<p>        // Serial.print("Fahrenheit: ");<br />
        printDouble(temp,3);  // display Fahrenheit<br />
        Serial.print(",");</p>
<p>      }<br />
      else{<br />
        // print the values as a single tab-separated line:<br />
        Serial.print(sensorValue[channelNum], DEC);<br />
        Serial.print(",");<br />
      }<br />
    }<br />
  }<br />
  // print a carriage return at the end of each read of the mux:<br />
  Serial.println();  </p>
<p>}</p>
<p>void setChannel(int whichChannel) {<br />
  for (int bitPosition = 0; bitPosition < 4; bitPosition++) {<br />
    // shift value x bits to the right, and mask all but bit 0:<br />
    int bitValue = (whichChannel >> bitPosition) & 1;<br />
    // set the address pins:<br />
    int pinNumber = firstAddressPin + bitPosition;<br />
    digitalWrite(pinNumber, bitValue);<br />
  }<br />
}</p>
]]></content:encoded>
			<wfw:commentRss>http://beddata.com/blog/?feed=rss2&amp;p=57</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
