/* ============================== * This code, which assumes you're using the official Arduino Ethernet shield, * updates a Pachube feed with your analog-in values and grabs values from a Pachube * feed - basically it enables you to have both "local" and "remote" sensors. * * Tested with Arduino 14 * * Pachube is www.pachube.com - connect, tag and share real time sensor data * code by usman (www.haque.co.uk), may 2009 * copy, distribute, whatever, as you like. * * v1.1 - added User-Agent & fixed HTTP parser for new Pachube headers * and check millis() for when it wraps around * * =============================== */ #include #include #undef int() // needed by arduino 0011 to allow use of stdio #include // for function sprintf #define SHARE_FEED_ID 8281 // Pachube: "Canberra Indoor Weather" by Sirleech #define REMOTE_FEED_ID 8281 // this is the ID of the remote Pachube feed that you want to connect to #define REMOTE_FEED_DATASTREAMS 3 // make sure that remoteSensor array is big enough to fit all the remote data streams #define UPDATE_INTERVAL 10000 // if the connection is good wait 10 seconds before updating again - should not be less than 5 #define RESET_INTERVAL 10000 // if connection fails/resets wait 10 seconds before trying again - should not be less than 5 #define PACHUBE_API_KEY "5df9aa3f6623b1958a43632ea16397046f0affd89393649257a3039e6f854b6a" // fill in your API key //byte mac[] = { 0xCC, 0xAC, 0xBE, 0xEF, 0xFE, 0x91 }; // make sure this is unique on your network //byte ip[] = { 192, 168, 0, 144 }; // no DHCP so we set our own IP address //23 canning st router setup //An unused IP address as found in the DHCP table byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = { 192, 168, 1, 21 }; // BILLION ADSL MODEM ROUTER //gateway = router ip,gateway //subnet = netmask byte gateway[] = { 192, 168, 1, 254 }; byte subnet[] = { 255, 255, 255, 0 }; //173.203.98.29 change to this post jun 30, 2010 //byte remoteServer[] = { 173,203,95,29 }; // pachube.com byte remoteServer[] = { 209,40,205,190 }; // pachube.com float remoteSensor[REMOTE_FEED_DATASTREAMS]; // we know that feed 256 has floats - this might need changing for feeds without floats ////temperature // These constants won't change. They're used to give names // to the pins used: const int analogInPin = 1; // Analog input pin that the potentiometer is attached to const int analogOutPin = 13; // Analog output pin tha2b357d16t the LED is attached to int sensorValue = 0; // value read from the pot int outputValue = 0; // value output to the PWM (analog out) int i = 0; int n; int sample = 30; float rawArray[30]; float raw; float averageRaw; float sumRaw; float referenceVoltage; float volts; float voltDivisor; float millivolts; float kelvin; float celcius; float celciusAvg; float f; //// void setup() { Serial.begin(57600); //setupEthernet(); Ethernet.begin(mac, ip, gateway, subnet); pinMode(1, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT); //arduino duemilanove atmega328 4.98v referenceVoltage = 4980; } void loop() { clrScr(); /////////////////////// //Average calculation raw = analogRead(analogInPin); ///////////////////////////// rawArray[i] = raw; for (int i = 0; i < 30; i++) sumRaw = sumRaw + rawArray[i]; averageRaw = sumRaw/sample; //Arduino analogReads in a value 0-1024 voltDivisor = 1024/referenceVoltage; millivolts = averageRaw/voltDivisor; kelvin = millivolts/10; volts = millivolts / 1000; celciusAvg = kelvin - 273.15; Serial.print("averaged="); Serial.print(celciusAvg); Serial.print("C"); ////////////////////// //Direct calculation //////////////////// // voltage divisor = 1024/5v = 204.8 millivolts = raw/voltDivisor; kelvin = millivolts/10; // convert to kelvin: [°C] = [K] − 273.15 celcius = kelvin - 273.15; // Tf = (9/5)*Tc+32; Tc = temperature in degrees Celsius, Tf = temperature in degrees Fahrenheit // 9/5 = 1.8 f = 1.8 * celcius; f = f + 32; Serial.print(" instantTemp="); Serial.print(celcius); Serial.print("C"); Serial.println(""); Serial.print("kelvin="); Serial.print(kelvin); Serial.print("K "); Serial.print("farenheit="); Serial.print(f); Serial.println(""); Serial.print("v="); Serial.print(volts); Serial.print(" mV="); Serial.print(millivolts); Serial.println(""); Serial.print("analog");Serial.print(analogInPin);Serial.print(":"); Serial.print(raw); // call 'pachube_in_out' at the beginning of the loop, handles timing, requesting // and reading. use serial monitor to view debug messages pachube_in_out(); // then put your code here, you can access remote sensor values // by using the remoteSensor float array, e.g.: // analogWrite(3, (int)remoteSensor[3] * 10); // remoteSensor is a float // analogWrite(5, (int)remoteSensor[1]); // you can have code that is time sensitive (e.g. using 'delay'), but // be aware that it will be affected by a short pause during connecting // to and reading from ethernet (approx. 0.5 to 1 sec). // e.g. this code should carry on flashing regularly, with brief pauses // every few seconds during Pachube update. i++; if (i >= sample) { i = 0; } sumRaw = 0; // digitalWrite(6, HIGH); delay(100); // digitalWrite(6, LOW); delay(100); } void clrScr(){ #define CHAR_ESC '\x1B' Serial.print( CHAR_ESC ) ; Serial.print( 'E' ) ; // clear screen } void getTemp() { i++; if (i >= sample) { i = 0; } sumRaw = 0; }