⚠️ This forum has been restored as a read-only archive so the knowledge shared by the community over many years remains available. New registrations and posting are disabled.

All times are UTC + 8 hours




Post new topic Reply to topic  [ 155 posts ]  Go to page 1, 2, 3, 4, 5 ... 11  Next
Author Message
 Post subject: Arduino DataLogger
PostPosted: Nov 24th, '11, 20:27 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
Hi anyone and everyone.
Started designing and building an aquaponics dataloggger with an Arduino (http://arduino.cc/en/), in the spirit of open source i thought i would share it here for anyone who might be interested. It will be a kind of long term project with me adding things as i go (read as have money to buy parts components, as I'm a poor uni student haha).

So i started off with a TMP36 temperature sensor and photoresistor and saved the data to the internal EEPROM of the arduino, which was all cool bananas. I soon realized i would need a portable power supply so it could easily stay in our greenhouse. So off to ebay I went...to purchase a 2.1mm powerjack and battery container.
I then decided i wanted to use an SD card because EEPROM is only good for i think 100 000 read/writes which is probably plenty but I wanted to be able to easily take it and put it in my computer to create graphs etc. so back to ebay for an MicroSD shield (to anyone following that wants to use my plans/code/etc make sure you get one with and 5-3.3V logic converter or you will blow your SD). I also be explainought and LCD screen so reasons soon to be explained.

I also bought some stuff for a chicken coop door opener, but thats another story. (feel free to ask)

Thats about where I am up to at the moment but...i have some other goals
- 3 temperature sensors, waterTemp, insideGreenhouse, outsideGreenhouse ( these will probabily be the DS18B20 sensors rather than TMP36 as the DS18B20 can use the 1-Wire connections, this means all sensors can go into one pin)
- humidity sensor
- an RTC (real time clock) to give a time and date to all readings. internal oscillator is probably fine but I may want to use it for something else one day)
-LCD screen with buttons to scroll through the readings and show time/date.
-Once I am completely happy and don't want to change the datalogger (probably Never) i will try to solder it to a PCB with an ATMEL atmega328 micro-controller.

Well that's all i can think of at the moment. I have never done one of these how to's before. I realize I have been pretty scarce on any background information but, to try and explain everything would take forever. But remember google is your friend and the arduino website has heaps of info for beginners, probably more for beginners than the experienced, of which I am by no means one of. After googling you have any questions regarding programming or electronics I will do my best to answer anything and everything.
I am now going to start copy - pasting some of the code i have written for any interested.


Top
 Profile  
Reply with quote  
    Advertisement
 
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 20:44 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
This is the code I wrote using a TMP36 temp sensor just to get used to programming again. If you were to just Use the EEPROM memory it shouldn't be too hard to add in more variables just be careful not to overwrite anything. I won't bother putting up a schematic for this circuit unless its asked for, its just a temp sensor with the data connection going to analog pin 0
/*
* Read from a single sensor and save to EEPROM memory of an Arduino
*
* Copyright (C) 2011 Daniel Erbe (daniel.anthony.erbe@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//include EEPROM library
#include <EEPROM.h>

//declare variables
int waterTempPin = 0; //data pin from temp sensor
int waterTemp; //water temp variable
int address; // memory address of current water temp variable
int wait = 7200000; // wait 2 hours

void setup()
{
//begin serial connection to computer (only for testing purposes, comment out when in use)
Serial.begin(9600);
}

void loop()
{
//for loop to write to all memory addresses in EEPROM (assuming 1024)
for(address=0; address < 1024; address++)
{
// read from temp sensor
waterTemp = analogRead(waterTempPin);
//calculated degrees celcius
waterTemp = (((waterTemp * 5.0)/1024) - 0.5) * 100.0;
// print value into EEPROM memory
Serial.println(waterTemp);
EEPROM.write(address, waterTemp);
//wait however long till next reading is taken
delay(wait);
}
// if memory is full then infinate while loop so no data is over written
while(1) { }
}


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 20:53 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
So you can read your data you will need to run this program and copy all the values from the serial connection...If there is any questions please ask and ill try to answer.

These two programs were never used other than for some revision and to get started while i waited for parts so may not be %100 ready to be used in real situations

/*
* Read from EEPROM of arduino and print to serial connection of computer
*
* Copyright (C) 2011 Daniel Erbe (daniel.anthony.erbe@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

//include EEPROM library
#include <EEPROM.h>

//declare variables
int waterTemp;
int address;

void setup()
{
//start serial connection
Serial.begin(9600);
//print a header to explain the info
Serial.println("Water Temperature in 2Hr Intervals");
}

void loop()
{
//for each adress from 0 - 2023
for(address=0; address < 1024; address++)
{
//read from current adress and assign to variable "waterTemp"
waterTemp = EEPROM.read(address);
//print waterTemp to screen
Serial.println(waterTemp);
//255 was default value in EEPROM so if water temp says 255 it must have run out of real data. So break the loop and send it to an infinite while loop doing nothing...may need to be changed is EEPROM has different values maby change to within 15- 40 or something?
if (waterTemp == 255)
break;
}
while(1)
{
}
}


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 21:17 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
If your code doesn't compile don't stress it could be my fault, as I have been commenting my touchpad is randomly clicking. Sometimes while i am typing and i accidentally type in my code and it may bring about a compiler error...already been in touch with dell customer support but don't even get me started on that one.

A couple of points
-CSV format is for Libreoffice calc if it reads a space it puts the string in a new collum, perfect for graphing.
-for the light sensor you get a reading between 0 and 1023, so by dividing it by 1023 will give you as response as a percentage...And yes i did just realize all mine have been divided by 1024. You guys have helped me already and no one had even replied.
- for the temp sensor i forgot the calculation now haha, its got something to do with the output being 500mV at 0`C and adding 20mv per degree or something, I'll need to check it and get back to everyone.
-Oh and I think i forgot to mention in my first post if anyone has any suggestions then let me know, thats why i decided to post all this in the first place... But I wont be making a controller for valves/solenoids etc. because dad likes it the way he can fix it if something brakes, but I will help design and program something if i have time before uni starts again...
/*
* Write Data from a TMP36 and photoresistor to an SD card using an SD card shield
*
* Copyright (C) 2011 Daniel Erbe (daniel.anthony.erbe@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//include SD library
#include <SD.h>

//declare variables
File file;
int waterTempPin = 0;
int waterTemp;
int lightPin = 1;
int lightLevel;
//these are to show if the SD card initalised properly and hey, all good projects need some flashing lights???
int goodLEDPin = 3;
int badLEDPin = 2;
//string for the data that gets written to the SD
String data;

void setup()
{
//start connection to computer
Serial.begin(9600);
//set pin 10 to output because the SD card library needs it to be even though CS is on pin 4
pinMode(10, OUTPUT)
//LED pins need to be set as outputs
pinMode(3, OUTPUT);
pinMode(2, OUTPUT)
//if SD doesnt initalize make red LED light up
if (!SD.begin(4))
{
digitalWrite(badLEDPin, HIGH);
return;
}
//if does initalise green LED turns on
digitalWrite(goodLEDPin, HIGH);
//create file data.csv if already there just open it and make it written too.
file = SD.open("data.csv", FILE_WRITE);
//if file if open print Water_Temp in one collum and Light_level in another
if(file)
{
file.println("Water_Temp Light_Level");
}
//if not then make red light light up
else
{
digitalWrite(goodLEDPin, LOW);
digitalWrite(badLEDPin, HIGH);
return;
}

}

void loop()
{
//read waterTemp from waterTempPin
waterTemp = analogRead(waterTempPin);
//some maths to get degrees celcius
waterTemp = (((waterTemp * 5.0)/1024) - 0.5) * 100.0;
//print waterTemp to computer (only for testing purposes)
Serial.println(waterTemp);
//read lightLevel
lightLevel = analogRead(lightPin);
//get lightLevel as percentage
lightLevel = (lightLevel*100.0)/1024.0;
//print to lightLevel to screen (only for testing purposes)
Serial.println(lightLevel);
// put all data into string called data
String data = String(waterTemp) + " " + String(lightLevel);
//print to SD card
file.println(data);
//delay for 2.5 seconds because this is just an inside test
delay(2500);
}


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 21:25 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
Well last post until i get more parts or I get a question.
I just left it running in my room connected to my computer while i made the previous posts and took almost 3000 readings in 2.5 second intervals.
I am pretty stoked, it shows the room go from just over 30 to about 26 as the aircon got turned on and very little change in light readings. and almost 6000 readings (3k of each light and temp) took 19.2kB of space on a 1gb MicroSD.

I also decided on another goal I may start work on tonight or tomorrow, that is getting it to read commands from a text file and then run them on the arduino. For example changing reading frequency without needing to reflash the micrcontroller, just by editing a text file on the MicroSD


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 22:33 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
Code:
Just noticed there is a way to specifically add code to a post, so any further code will be posted like this. But in the mean time... a schematic for the SD datalogger, my circuit and the code. I'll put these in my dropbox folder and share the public link...
Dropbox is an awesome program that installs a file on your computer and anything you put in it is backed up online. you can also install the same folder on another computer and it keeps the folder synced between all computers and online (up to 2GB). it obviously lets you share stuff from your "public" folder. if anyone thinks thats awesome like I do and wants to sign up use this link [url]http://db.tt/gNhUgOZ[/url] then we both get an extra 250MB for free.
but here we go

schematic as .png
http://dl.dropbox.com/u/19981222/MicroSD%20Datalogger/Screenshot%20at%202011-11-24%2022%3A18%3A01.png
schematic as .sch
http://dl.dropbox.com/u/19981222/MicroSD%20Datalogger/SDDatalogger.sch
MicroSD shield schematic
http://dl.dropbox.com/u/19981222/MicroSD%20Datalogger/MicroSD-schematic.pdf
and code
http://dl.dropbox.com/u/19981222/MicroSD%20Datalogger/greenhouseSDWriteNarrated.pde


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 24th, '11, 22:47 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
Nice work :)
I played around with a PIC a while ago, opening and closing various valves and water level sensors, that kinda thing.
I have been away from AP for a while due to RL commitments, but have just started rebuilding my system after a house move.
No electronics at the moment, the mechanical side was rather high maintenance and I don't have the time for that right now.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 01:11 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
Thanks,
I haven't touched anything other than Arduino mainly because C is the language I know best. But i have heard or PIC and PICAXE, have you experimented with much arduino? if so how do they compare? I would think hooking everything up to a microcontroller would make things less maintenance? although it would still need regular checks of course. You would also need to program in heaps of safeguards in the event of something going wrong. Probably in a completely different circuit.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 09:02 
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
Erbey wrote:
[stuff deleted]

I also decided on another goal I may start work on tonight or tomorrow, that is getting it to read commands from a text file and then run them on the arduino. For example changing reading frequency without needing to reflash the micrcontroller, just by editing a text file on the MicroSD



That's a great idea, like a config file.

I love it.

Keep it coming.

TC will be your biggest fan.

oh... and you can attach zip files if you want to include the GPL licence agreement with your code.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 09:04 
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
DuiNui wrote:
Nice work :)
I played around with a PIC a while ago, opening and closing various valves and water level sensors, that kinda thing.
I have been away from AP for a while due to RL commitments, but have just started rebuilding my system after a house move.
No electronics at the moment, the mechanical side was rather high maintenance and I don't have the time for that right now.


High maintenance?

Blocked valves or something. I'm about to start looking into controlling a tap so would be keen to know more.


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 11:21 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
High maintenance was probably a poor choice of words.
The water level sensors gave me problems, mostly false positive readings, I think due to noise.
I don't have a scope here so never found out what was wrong.
It all worked perfectly on the bench but outside it would fail from time to time.
I built safeguards into the software but GB's would overflow occasionally and I ran out of time to develop it further.
Actually before I added the level sensors and the system ran just on a timed flood/drain cycle, it worked fine, I should have left it at that ;)
The valves worked really well, micro servo attached to a ping pong ball inside a 20-40mm adapter.
Here's a short video of the system, there is a close-up of one of the valves working.
There are also some pics in my thread.





I've never used the Arduino so can't comment on that.
Have been using PICS for donkey's years and know them inside out, that's why I went with PIC


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 13:15 
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
Erbey, what do you think it will cost in total?


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 13:33 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
DuiNui wrote:
High maintenance was probably a poor choice of words.
The water level sensors gave me problems, mostly false positive readings, I think due to noise.

Were you using and analog sensor to measure an actual distance in cm or something?
I personally would have made a simple digital water sensor with two strips of metal next to each other.
one constantly at 5V with the other connected to a digital input pin. If the water reaches the sensor, the data line will read HIGH. if not it would read LOW. I imagine with ultrasonic or IR sensors a lot of the energy would be absorbed or reflected at a funny angle due to water movement?


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 13:47 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
Erbey wrote:
I personally would have made a simple digital water sensor with two strips of metal next to each other.
One constantly at 5V with the other connected to a digital input pin.

Is almost exactly what I did, except not constant +5v, I drove that from an output pin.
The input impedance is very high making it susceptible to noise, I think it was picking up noise from the servo driver cables, but hard to tell without a scope.
I added some code to drive the output pin high for a set period and then measure that time on the input pin from the sensor.
That made things much better, but that was about the time I ran out of time, moving house etc. etc.

Talking about this again has made me want to dig all the stuff out of the box and start playing again, in fact I have just mounted the solar panel and connected the battery up :D


Top
 Profile  
Reply with quote  
 Post subject: Re: Arduino DataLogger
PostPosted: Nov 25th, '11, 13:51 
Newbie
Newbie

Joined: Sep 18th, '10, 19:15
Posts: 28
Gender: Male
Are you human?: yes
Location: Perth, WA
BullwinkleII wrote:
Erbey, what do you think it will cost in total?

Hmmmm, because I plan on it being a constant work in progress adding and subtracting things as i go not sure.
Also because I'm using it as a learning curve to eventually move into AVR microcontrollers and assembly language programming its more of a hobby than a project.
But as it stands:
- Arduino ~ $30
-MicroSD shield ~ $10
-MicroSD ~ $10 but i had one lying around
-LCD shield ~ $10
-2.1mm powerjack ~$2
-Battery connector ~$2 already had
-9V battery ~ not sure 5-10$
-RTC - Pack of 5 for $5
-RTC battery/battery holder ~ no idea shouldnt be much
-photoresistor ~$2
-TMP36 $3-4
-2xLED and 2x330ohm and 1x 10K ohm resisistors ~ $5 but depends if you buy bulk on ebay or just what you need

Thats a guideline but its hard to say. The first set of code i put up would let you make a simple datalogger with a single sensor with nothing but the arduino and either a battery pack or 240VAC-9VDC power supply and sensor and all up would cost maby $40. But that was also with an Arduino UNO you could get an Arduino mini or something for like $15, so a total of maby $25.
So essentially like most projects it can go as high as you want, but from of low as about 25$ plus any extra costs.

For me the programming/microcontroller learning is worth it because it will help me out heaps at uni and it will answer the question of weather to grow silver perch or barra next summer. (if you lost a tank of barra you would wish you paid the $50 and made the datalogger).
I will no doubt reuse most of the stuff i buy in other projects aswell.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 155 posts ]  Go to page 1, 2, 3, 4, 5 ... 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:  
cron

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