All times are UTC + 8 hours




Post new topic Reply to topic  [ 155 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11  Next
Author Message
 Post subject: Re: Arduino DataLogger
PostPosted: Jan 31st, '13, 00:52 
Bordering on Legend
Bordering on Legend

Joined: Jun 28th, '12, 22:36
Posts: 301
Gender: Male
Are you human?: YES
Location: Nashville, Tennessee
This week should give some interesting readings due to the wild temperature swings we've had. Tests with the photodiode suggest it will be better as a sunrise/sunset indicator than a fine discriminator of light levels. I have to leave town for a few days tomorrow, so I'll pull the card and grab the data when I get back.

I'll post my code if anyone is interested, though it's a hack job of pasted example code from several sources and I don't know enough to heavily modify it. Seems to work, though, which is what I'm aiming for.

Sources for the major components:

Nano (price went up a little, looks like): http://www.amazon.com/gp/product/B00761NDHI

SD shield with real time clock: https://www.adafruit.com/product/1141

Waterproof DS18B20: http://dx.com/p/diy-ds18b20-stainless-s ... ack-151327

The Hong Kong suppliers take a few weeks to deliver, but you can't beat the price. I did pick up a few super-cheap extras at the same time and they do seem to work (so far).


Top
 Profile  
Reply with quote  
    Advertisement
 
 Post subject: Re: Arduino DataLogger
PostPosted: Jan 31st, '13, 05:29 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
I'd be keen to see the code.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Jan 31st, '13, 10:07 
Bordering on Legend
Bordering on Legend

Joined: Jun 28th, '12, 22:36
Posts: 301
Gender: Male
Are you human?: YES
Location: Nashville, Tennessee
Enjoy. Suggestions welcome.

Code:
#include <SD.h>
#include <Wire.h>
#include "RTClib.h"
#include <OneWire.h>
#include <DallasTemperature.h>
#include <stdio.h>

// A simple data logger for the Arduino analog pins

// how many milliseconds between grabbing data and logging it. 1000 ms is once a second
#define LOG_INTERVAL  600000 // mills between entries (reduce to take more/faster data)
#define ONE_WIRE_BUS 8

// how many milliseconds before writing the logged data permanently to disk
// set it to the LOG_INTERVAL to write each time (safest)
// set it to 10*LOG_INTERVAL to write all data every 10 datareads, you could lose up to
// the last 10 reads if power is lost but it uses less power and is much faster!
#define SYNC_INTERVAL 600000 // mills between calls to flush() - to write data to the card
uint32_t syncTime = 0; // time of last sync()

#define ECHO_TO_SERIAL   1 // echo data to serial port
#define WAIT_TO_START    0 // Wait for serial input in setup()

// the digital pins that connect to the LEDs
#define redLEDpin 2
#define greenLEDpin 3

// The analog pins that connect to the sensors
#define photocellPin 0           // analog 0
#define tempPin 1                // analog 1

#define aref_voltage 3.3         // we tie 3.3V to ARef and measure it with a multimeter!

byte maxsensors = 0;
float celsius, fahrenheit;

OneWire  ds(ONE_WIRE_BUS);
DallasTemperature sensors(&ds);

RTC_DS1307 RTC; // define the Real Time Clock object

// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;

// the logging file
File logfile;

void scanSensors(void)
{
  byte i;
  byte present = 0;
  byte data[12];
  byte addr[8];
  while (ds.search(addr))
  {
    for( i = 0; i < 8; i++) {
    }
    if ( addr[0] == 0x10) {
        maxsensors++;
    }
    else {
      if (addr[0] == 0x28) {
        maxsensors++;
      }
      else {
        Serial.print("Device is unknown!\n");
        Serial.print("Device ID: ");
        Serial.print(addr[0],HEX);
        Serial.println();
        return;
      }
    }
    ds.reset();
    ds.select(addr);
    ds.write(0x44,1);         // start conversion, with parasite power on at the end
    delay(1000);     // maybe 750ms is enough, maybe not
    // we might do a ds.depower() here, but the reset will take care of it.
    present = ds.reset();
    ds.select(addr);   
    ds.write(0xBE);         // Read Scratchpad
    for ( i = 0; i < 9; i++) {           // we need 9 bytes
      data[i] = ds.read();
    }
  }
  ds.reset_search();
  delay(250);
}

void error(char *str)
{
  Serial.print("error: ");
  Serial.println(str);
 
  // red LED indicates error
  digitalWrite(redLEDpin, HIGH);

  while(1);
}

void setup(void)
{
  Serial.begin(9600);
  Serial.println();
 
  // use debugging LEDs
  pinMode(redLEDpin, OUTPUT);
  pinMode(greenLEDpin, OUTPUT);
 
#if WAIT_TO_START
  Serial.println("Type any character to start");
  while (!Serial.available());
#endif //WAIT_TO_START

  // initialize the SD card
  Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    error("Card failed, or not present");
  }
  Serial.println("card initialized.");
 
  // create a new file
  char filename[] = "LOGGER00.CSV";
  for (uint8_t i = 0; i < 100; i++) {
    filename[6] = i/10 + '0';
    filename[7] = i%10 + '0';
    if (! SD.exists(filename)) {
      // only open a new file if it doesn't exist
      logfile = SD.open(filename, FILE_WRITE);
      break;  // leave the loop!
    }
  }
 
  if (! logfile) {
    error("couldnt create file");
  }
 
  Serial.print("Logging to: ");
  Serial.println(filename);

  // connect to RTC
  Wire.begin(); 
  if (!RTC.begin()) {
    logfile.println("RTC failed");
#if ECHO_TO_SERIAL
    Serial.println("RTC failed");
#endif  //ECHO_TO_SERIAL
  }
 

  logfile.println("millis,stamp,datetime,light,enclosure,outside,inside,water");   
#if ECHO_TO_SERIAL
  Serial.println("millis,stamp,datetime,light,enclosure,outside,inside,water");
#endif //ECHO_TO_SERIAL
 
  // If you want to set the aref to something other than 5v
  analogReference(EXTERNAL);

  sensors.begin();
  scanSensors();
}

void loop(void)
{
  DateTime now;

  // delay for the amount of time we want between readings
  delay((LOG_INTERVAL -1) - (millis() % LOG_INTERVAL));
 
  digitalWrite(greenLEDpin, HIGH);
 
  // log milliseconds since starting
  uint32_t m = millis();
  logfile.print(m);           // milliseconds since start
  logfile.print(",");   
#if ECHO_TO_SERIAL
  Serial.print(m);         // milliseconds since start
  Serial.print(","); 
#endif

  // fetch the time
  now = RTC.now();
  // log time
  logfile.print(now.unixtime()); // seconds since 1/1/1970
  logfile.print(",");
  //logfile.print('"');
  logfile.print(now.month(), DEC);
  logfile.print("/");
  logfile.print(now.day(), DEC);
  logfile.print("/");
  logfile.print(now.year(), DEC);
  logfile.print(" ");
  logfile.print(now.hour(), DEC);
  logfile.print(":");
  logfile.print(now.minute(), DEC);
  logfile.print(":");
  logfile.print(now.second(), DEC);
  //logfile.print('"');
#if ECHO_TO_SERIAL
  Serial.print(now.unixtime()); // seconds since 1/1/1970
  Serial.print(",");
//  Serial.print('"');
  Serial.print(now.month(), DEC);
  Serial.print("/");
  Serial.print(now.day(), DEC);
  Serial.print("/");
  Serial.print(now.year(), DEC);
  Serial.print(" ");
  Serial.print(now.hour(), DEC);
  Serial.print(":");
  Serial.print(now.minute(), DEC);
  Serial.print(":");
  Serial.print(now.second(), DEC);
//  Serial.print('"');
#endif //ECHO_TO_SERIAL

  analogRead(photocellPin);
  delay(10);
  int photocellReading = analogRead(photocellPin); 
 
  analogRead(tempPin);
  delay(10);
  int tempReading = analogRead(tempPin);   
 
  // converting that reading to voltage, for 3.3v arduino use 3.3, for 5.0, use 5.0
  float voltage = tempReading * aref_voltage / 1024; 
  float temperatureC = (voltage - 0.5) * 100 ;
  float temperatureF = (temperatureC * 9 / 5) + 32;
 
  logfile.print(",");   
  logfile.print(photocellReading);
  logfile.print(",");   
  logfile.print(temperatureF);
  logfile.print(",");   
#if ECHO_TO_SERIAL
  Serial.print(",");   
  Serial.print(photocellReading);
  Serial.print(",");   
  Serial.print(temperatureF);
  Serial.print(",");   
#endif //ECHO_TO_SERIAL

  sensors.requestTemperatures();
  for (int i=0;i<maxsensors;i++)
  {
    float celsius = sensors.getTempCByIndex(i);
    fahrenheit = celsius * 1.8 + 32.0;
    logfile.print(fahrenheit);
    logfile.print(",");
  #if ECHO_TO_SERIAL
    Serial.print(fahrenheit);
    Serial.print(",");
  #endif // ECHO_TO_SERIAL
  }

  logfile.println();
#if ECHO_TO_SERIAL
  Serial.println();
#endif // ECHO_TO_SERIAL

  digitalWrite(greenLEDpin, LOW);

  // Now we write data to disk! Don't sync too often - requires 2048 bytes of I/O to SD card
  // which uses a bunch of power and takes time
  if ((millis() - syncTime) < SYNC_INTERVAL) return;
  syncTime = millis();
 
  // blink LED to show we are syncing data to the card & updating FAT!
  digitalWrite(redLEDpin, HIGH);
  logfile.flush();
  digitalWrite(redLEDpin, LOW);
 
}


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 8th, '13, 04:56 
Bordering on Legend
Bordering on Legend

Joined: Jun 28th, '12, 22:36
Posts: 301
Gender: Male
Are you human?: YES
Location: Nashville, Tennessee
Data!

Attachment:
logger1.png
logger1.png [ 48.29 KiB | Viewed 7605 times ]


Things are mostly working as intended. The light sensor, as expected, isn't that great at fine distinction, but is a good day/night indicator. I think the inside sensor is getting too much direct sun, hence the high daytime readings. The enclosure sensor (the one on the board itself) definitely shows a good amount of heating during the day. Heat retention is obviously poor, since all temperatures rapidly drop to match the outdoor when the sun goes down, except for the water temp which only slowly drops. Looks like the water does pick up a fair amount of heat during the day, especially those sunny days where the inside sensor is going nuts.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 8th, '13, 17:22 
A posting God
A posting God
User avatar

Joined: Oct 16th, '11, 06:12
Posts: 2019
Gender: Male
Are you human?: 0110010110
Location: Brisbane, qld
Great data!


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 9th, '13, 21:07 
Bordering on Legend
Bordering on Legend
User avatar

Joined: Feb 9th, '13, 15:36
Posts: 431
Images: 0
Gender: Male
Are you human?: Yes
Location: Gawler South, South Australia
Thanks Erbey for the pointer towards Arduino.

As a Fitter and turner tuned software developer now aquaponics nerd I have just purchased the required parts to be build a data logger with it.

I also added a lan card so that I can have one of my servers pol it for data. Load the data into a Firebird database the build reports for a front end.

Magic I say.

If it works out well I can use another one to monitor and control my snake enclosures. All at a bargin price.


So once again thank you.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 9th, '13, 22:54 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
Please document and post it all! :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 11th, '13, 08:04 
Legend Member
Legend Member
User avatar

Joined: Jun 21st, '12, 06:51
Posts: 545
Gender: Male
Are you human?: YES
Location: Australia, WA, Beldon
Johny5 wrote:
Load the data into a Firebird database


Please... for the love of god... why Firebird?


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 11th, '13, 08:42 
Bordering on Legend
Bordering on Legend
User avatar

Joined: Jan 18th, '11, 08:29
Posts: 481
Images: 0
Location: Western NC
Gender: Male
Are you human?: Unknown Cyborg
Location: North Carolina
nebbian wrote:
Please... for the love of god... why Firebird?


+1 :support:


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 12th, '13, 16:33 
Bordering on Legend
Bordering on Legend
User avatar

Joined: Feb 9th, '13, 15:36
Posts: 431
Images: 0
Gender: Male
Are you human?: Yes
Location: Gawler South, South Australia
Because it is free and I have never had a problem with it in the what must be nearly 10 years.

Never had a DB crash or lost data with it. Despite client not do maintenance on the dB for a few years.

But it is as always each to their own i guess.


I am still waiting on supplies as the supplier in China is on holidays, but as It has cost less that $100
including 10 temp probes I will be patient. (It will not be easy).

I will gladly share the details and final program but first I must play with the new toys once they arrive.

Are they here yet.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 13th, '13, 22:14 
Legend Member
Legend Member
User avatar

Joined: Jun 21st, '12, 06:51
Posts: 545
Gender: Male
Are you human?: YES
Location: Australia, WA, Beldon
Hey wow, I didn't realise Firebird was still under active development. The only times I've used it were for supporting very old projects that were put into production 8 or so years ago... I assumed it was well past EOL by now. Reading up it seems to have quite an active community built around it.

I stand corrected :)


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 14th, '13, 05:06 
Bordering on Legend
Bordering on Legend
User avatar

Joined: Feb 9th, '13, 15:36
Posts: 431
Images: 0
Gender: Male
Are you human?: Yes
Location: Gawler South, South Australia
Not a problem nebbian.

None of us can keep up with every thing out there or we would never get any work done. Just like me with this Arduino Mega board. More and more projects for it every day. All I want to do is play and play.

Hole to finish digging today for the new sump instead.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 15th, '13, 23:20 
Newbie
Newbie

Joined: Sep 29th, '11, 12:55
Posts: 12
Gender: Male
Are you human?: YES
Location: East Central Indiana, USA
Since you really seem to be into this, how about a cheap computer to control everything right in your greenhouse, or system area/

Raspberry PI computers can be had for $35.oo for the better model. You will want accessories - such as a 4 port USB hub, a very large Flash card to hold the system and applications (can also be purchased from R/PI), maybe a shell to contain the works, etc.

The costly thing about this would be a monitor. A cheap TV is the least expensive way to go. Stand alone small LCD monitors are still expensive for such an operation. BUT, I saw something in Arduino equipment that output a nice picture of a duck. IF that is the case, maybe you can check on that for use as a monitor.

You don't need much - until, of course, you buy a camera to watch your fish on-screen. ;-)

Keep us posted on your ongoing project results and code!!

I saw an Arduino temp module being built in a VidClip, I think from the Arduino site, or maybe from this site. It was encased in a plastic pen tube, with silicone impregnated into the tube. the VidClip did not show how it was hooked up - nor the code for it.

JayGee


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 16th, '13, 01:21 
Bordering on Legend
Bordering on Legend

Joined: Jun 28th, '12, 22:36
Posts: 301
Gender: Male
Are you human?: YES
Location: Nashville, Tennessee
I think a Raspberry Pi unit would be my next step up in complexity. Right now the only way to get my data is to pull the SD card and transfer to my PC. I added a Bluetooth modem at one point, but all that does is add a serial monitor so you can see what data is being logged as it comes in. No access to the SD card itself.

Having a lightweight webserver on wifi would be great, but I don't know anything about getting the Pi to read the thermometers and log data, much less the other automation I want to add down the line. Of course, I didn't know anything about Arduino a month ago either (but, man, is it simple).


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Feb 16th, '13, 01:51 
A posting God
A posting God
User avatar

Joined: Dec 10th, '11, 15:03
Posts: 2089
Gender: Male
Are you human?: What is human?
Location: Perth Hills
With the Pi, the easiest way to get it going would be to actually use the arduino you have set up and have the Pi poll it over serial. Then do whatever with the data once you have it. Python could easily make good use of the data. That is my plan anyway, if i ever get time. As well as a few other features i have been playing with.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 155 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10, 11  Next

All times are UTC + 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group
Portal by phpBB3 Portal © phpBB Türkiye
[ Time : 0.061s | 16 Queries | GZIP : Off ]