Welcome to Growroom420 growers forum. Growroom420 is a online cannabis growing community. Follow grow diaries, find solutions to cannabis deficiencies, learn how to grow cannabis and much more. If this is your first visit you will need to register to access the forums full features and enter our many competitions. Click here to register.

DIY Data Logger - Dabbling with Arduino

Discuss setting up your space & what equipment to use
User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Hi GR420,
first of all a disclaimer: I'm not an engineer, can't code, am not a maker and don't have experience with any of it - so whatever I'm reporting here is just my own learning experience: I don't know what I am doing, and if so I got it from helpful sources on the internet, off people who actually do know what they are doing.

The Project:
So I wanted to build a data logger and it's an evolving project. For now it logs and displays temperature and humidity of my grow tent every 25 seconds. The data is stored on a micro SD card as a comma separated txt file and displayed on a little lit LCD. It is powered by USB.
This is it:
Image

Looks a bit frantic I know - I have many ideas for improvements of it - until then it is just a prototype.
So far:
Most of my kit is from two Elegoo Arduino kits of Amazon. If you can buy the original - just to support the cause, otherwise it's totally fine. The items used from those kits are:
Arduino Uno
16x2 LCD
DHT11 (Humidity and Temperature sensor)- mine was mounted so I didn't need a resistor with it.
SD card module,
RTC (real time clock) module
micro SD card
1k and 220 Ohm resistors
jumper wires
Bread Board

Both the wiring and code are mostly from those two tutorials:
https://randomnerdtutorials.com/arduino ... rd-module/
for the temperature logging and:
https://circuitdigest.com/microcontroll ... easurement
for the LCD.

There were a few issues I ran into: 1. I needed to download a newer version of the Arduino IDE to work with the newest Mac OS on 64bit.
Then I ran out of digital pins but you can just use the analog ins as 14, 15, 16, 17...
so the final code looks like this:

Code: Select all

/*
 * Rui Santos 
 * Complete Project Details http://randomnerdtutorials.com
 */

#include <SPI.h> //for the SD card module
#include <SD.h> // for the SD card
#include <DHT.h> // for the DHT sensor
#include <RTClib.h> // for the RTC
#include<LiquidCrystal.h>
LiquidCrystal lcd(7,6,14,15,16,17);

byte degree[8] = 
              {
                0b00011,
                0b00011,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000,
                0b00000
              }; //degree symbol for lcd
//define DHT pin
#define DHTPIN 2     // what pin we're connected to

// uncomment whatever type you're using
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

// change this to match your SD shield or module;
// Arduino Ethernet shield and modules: pin 4
// Data loggin SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
const int chipSelect = 8; 

// Create a file to store the data
File myFile;

// RTC
RTC_DS1307 rtc;

void setup() {
  //initializing the DHT sensor
  dht.begin();

  //initializing Serial monitor
  Serial.begin(9600);
  
  // setup for the RTC
  while(!Serial); // for Leonardo/Micro/Zero
    if(! rtc.begin()) {
      Serial.println("Couldn't find RTC");
      while (1);
    }
    else {
      // following line sets the RTC to the date & time this sketch was compiled
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    }
    if(! rtc.isrunning()) {
      Serial.println("RTC is NOT running!");
    }
    
  // setup for the SD card
  Serial.print("Initializing SD card...");

  if(!SD.begin(chipSelect)) {
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
    
  //open file
  myFile=SD.open("DATA.txt", FILE_WRITE);

  // if the file opened ok, write to it:
  if (myFile) {
    Serial.println("File opened ok");
    // print the headings for our data
    myFile.println("Date,Time,Temperature ºC, Humidity %");
  }
  myFile.close();
 lcd.begin(16, 2);
 lcd.createChar(1, degree);
 lcd.clear();
 lcd.print("   Humidity   ");
 lcd.setCursor(0,1);
 lcd.print("  Measurement ");
 delay(2000);
 lcd.clear();
 lcd.print("Weedabix @ GR420 ");
 delay(2000);
}
void loggingTime() {
  DateTime now = rtc.now();
  myFile = SD.open("DATA.txt", FILE_WRITE);
  if (myFile) {
    myFile.print(now.year(), DEC);
    myFile.print('/');
    myFile.print(now.month(), DEC);
    myFile.print('/');
    myFile.print(now.day(), DEC);
    myFile.print(',');
    myFile.print(now.hour(), DEC);
    myFile.print(':');
    myFile.print(now.minute(), DEC);
    myFile.print(':');
    myFile.print(now.second(), DEC);
    myFile.print(",");
  }
  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.println(now.day(), DEC);
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.println(now.second(), DEC);
  myFile.close();
  delay(1000);  
}

void loggingTemperature() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  //float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if  (isnan(t) /*|| isnan(f)*/) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //debugging purposes
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.println(" *C");
  //Serial.print(f);
  //Serial.println(" *F\t"); 
  
  myFile = SD.open("DATA.txt", FILE_WRITE);
  if (myFile) {
    Serial.println("open with success");
    myFile.print(t);
    myFile.println(",");
  }
  myFile.close();
  delay(1000);
}

void loggingHumidity() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  // Read temperature as Celsius
  float h = dht.readHumidity();
  
  
  // Check if any reads failed and exit early (to try again).
  if  (isnan(h) /*|| isnan(f)*/) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //debugging purposes
  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.println(" %");

  
  myFile = SD.open("DATA.txt", FILE_WRITE);
  if (myFile) {
    Serial.println("open with success");
    myFile.print(h);
    myFile.println(",");
  }
  myFile.close();
  delay(1000);
}

void printingData(){
    float h = dht.readHumidity();
  
  
  // Check if any reads failed and exit early (to try again).
  if  (isnan(h) /*|| isnan(f)*/) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //debugging purposes
  Serial.print("Humidity: "); 
  Serial.print(h);
  Serial.println(" %");

  float t = dht.readTemperature();
  // Read temperature as Fahrenheit
  //float f = dht.readTemperature(true);
  
  // Check if any reads failed and exit early (to try again).
  if  (isnan(t) /*|| isnan(f)*/) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  
  //debugging purposes
  Serial.print("Temperature: "); 
  Serial.print(t);
  Serial.println(" *C");
  //Serial.print(f);
  //Serial.println(" *F\t");  
  lcd.setCursor(0,0);
  lcd.print("Humidity: ");
  lcd.print(h);   // printing Humidity on LCD
  lcd.print(" %");
  lcd.setCursor(0,1);
  lcd.print("Temperature:");
  lcd.print(t);   // Printing temperature on LCD
  lcd.write(1);
  lcd.print("C");
  delay(500);
}
void loop() {
  loggingTime();
  loggingTemperature();
  delay(4000);
  loggingHumidity();
  printingData();
  delay(25000);
}

As I said, credits to those who wrote the actual tutorials, so I left the link in the comments.
But I couldn't resist to tinker with the welcome screen ;-)

Here's a little video to show it booting up.


Next steps are:
- get a longer cable to put the sensor next to the flowers and not having it dangle quite far up in the tent
- include light and pressure sensors to check on the fan as well as a soil humidity sensor (or multiple)
- add a button for the LCD backlight
- stream it to the cloud so I can check it on my phone
- solder it onto e.g. a prototype shield
- put it in a case

Happy to provide more details if anyone wants them, or take some advice from anyone knowledgeable!
cheers,
weedabix
These users thanked the author weedabix for the post:
TommyT (Sun Apr 05, 2020 8:02 am)

User avatar
Smokey
Posts: 11802
Joined: Tue Oct 31, 2017 12:05 am
Location: Mount Zion
Has thanked: 89 times
Been thanked: 100 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by Smokey »

:Shock: :Shock: :Shock: :Shock:

This place never ever ceases to amaze me,

This is incredible it really is :clap: :clap: :clap: :clap: I cannot wait to see the progression and then the "Dragons Den Pitch" :lol:

Awesome stuff Weedabix I look forward to the future development

Peace be the journey


Smokes
Image
🍁 Who Jah Bless No Man Curse 🍁

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Thanks Smokey, I appreciate your kind words!

User avatar
GMO
Podcast Admin
Posts: 7302
Joined: Sat Jun 02, 2018 2:44 pm
Has thanked: 1066 times
Been thanked: 618 times
Contact:
Status: Online

Re: DIY Data Logger - Dabbling with Arduino

Post by GMO »

this is flipping awesome!

imma sit in the corner and take notes
Image
“If you can't explain it to a six year old, you don't understand it yourself.” -Albert Einstein

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

thanks GMO - let me know if you need any more details.
I forgot one thing: So far the components probably cost about £10 - 20 in total if you don't mind waiting for them to arrive from china or a little more if you buy them off amazon.

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

some upgrades

Post by weedabix »

So there were some issues that I discovered...
1. The data format was impractical - there was a line break where it shouldn't have been - easy fix!
2. The cable for the temperature/humidity sensor was too short
3. The display crapped out over night.


So I did some enhancements - and of course everything was a bit harder than anticipated!
I bought some ribbon cable to have a nice way of attaching it to the sensor inside the tent - I even crimped some connectors so I can change or unplug the sensor in seconds.
I upgraded to an arduino mega so I have more pins to play with in the future - but that meant that I had to change a lot - which I wasn't aware of.
After a long search, I found out that the most likely reason for the LCD stopping to work was that the power supply wasn't stable enough. I assume the USB port had a drop everytime the light went on or off. It took me forever to figure that out. Now I have everything on a 9V power supply and so far it's going alright!
I have the feeling the humidity is being reported very low. It is consistently at least 5% under the hygrometer I got off amazon - which is lying on the ground, whereas the sensor is fixed to a skewer in the pot. Maybe it's a problem of the long cable, maybe a calibration issue, maybe it is real and there is a gradient within the tent or the other meter is not working properly.
So long story short - this still hasn't really helped me with my grow at all but it's super fun to play with! And I'm learning tons along the way!

More proper upgrades to come soon!
cheers,
weedabix

User avatar
Nanook
Banned users
Posts: 9164
Joined: Thu Jan 01, 1970 2:33 am
Location: My nest
Has thanked: 416 times
Been thanked: 481 times
Contact:
Status: Online

Re: DIY Data Logger - Dabbling with Arduino

Post by Nanook »

Cool, look forward to seeing the upgrades :)
The quieter you become, the more you are able to hear.

User avatar
Hmr81
Known User
Posts: 636
Joined: Mon Dec 02, 2019 6:32 pm
Has thanked: 111 times
Been thanked: 279 times
Contact:
Status: Online

Re: DIY Data Logger - Dabbling with Arduino

Post by Hmr81 »

I've been looking at doing something very similar, but to monitor two tents at the same time and then output to a webpage run on a local webserver raspberry pi but im sure you could load a webserver into that setup as well.

Those LCD displays need a good case really, esp if located inside the tent, which is why i was going to output to a webpage(via a small MySql Db).

Word of warning on the light sensors, i wouldn't bother getting one to read the "power" or spectrum of the light, just a basic sensor so you can see if the light is on or off is what im thinking, as the decent sensors are a bloody fortune lol.

So im am currently making basic designs to read; temp at soil height & canopy height and soil temp, rhd, light status, air pressure in both tents so double the sensors. I havent worked out the power required yet but i might even throw a PC at it as i have a spare hp microserver doing nothing.

Nice build mate.
From the Garage of HMR :puff puff:

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Hi HMR,
you're right, the light sensor would just be to see whether the light is on or off basically. But that can already be valuable information. It shouldn't be too hard to add more sensors and an iot station is my end goal - but I want to slowly build up to that so I can understand what I am doing. Also I'm keeping everything outside of the tent, except the sensor so I can actually read it while the tent is still closed. I'll keep you updated once I add the next components!
Looking forward to hearing from you about the project!

User avatar
Hmr81
Known User
Posts: 636
Joined: Mon Dec 02, 2019 6:32 pm
Has thanked: 111 times
Been thanked: 279 times
Contact:
Status: Online

Re: DIY Data Logger - Dabbling with Arduino

Post by Hmr81 »

I'm probably going the windows route as I have spare kit lol but will keep you updated.

Good work though mate, looks sweet little project
From the Garage of HMR :puff puff:

User avatar
Marcus
Respected User
Posts: 1430
Joined: Thu Nov 29, 2018 2:25 pm
Has thanked: 443 times
Been thanked: 596 times
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by Marcus »

I keep reading the title of the thread as "DIY Data Lager" and it's making me want a beer!

Interesting project Weetabix. :oik!:

But I think you got a red and a yellow wire mixed up. Try cutting the green. You got about 15 seconds before this place blows! :suicide:

:lol:
This is a block of text that can be added to posts you make. There is a 500 character limit.

User avatar
Egzoset
Posts: 32
Joined: Sat Nov 23, 2019 6:13 am
Has thanked: 0
Been thanked: 3 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by Egzoset »

Salutations Weedabix,
weedabix wrote:
Wed Jan 15, 2020 11:42 pm
...don't know what I am doing... ... ...it's an evolving project. ...stream it to the cloud...
Well, i had to think hard in order to refresh old memories but my advice would be to make provisions for "SNMP" statistics. Simple .CSV formatted records could be analyzed using either 'OpenOffice Calc' or 'GNUmeric' at a later time. Sorry not being able to offer more input than that.

Good day, have fun!! :oik!:
Image

User avatar
G3W2HIN
Posts: 781
Joined: Fri Nov 01, 2019 8:20 pm
Location: USA
Has thanked: 54 times
Been thanked: 307 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by G3W2HIN »

looking good now that the testing is done any plans for a permanent finish?? ive built 2 of these i like to test the sensors they are not perfect , they are pretty damn good tho arduino is the way open source baby!!!
INNER PEACE

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

So I am slowly getting there - I had a few stupid hickups... such as bad cables, bad contacts or me just accidentally pulling out a cable! But now finally it's been running a bit and the data looks ok!
So this is the data:Image
temperature and humidity are straight forward... these somewhat make sense...
The light intensity is the percentage of an arbitrary value. And plotted is only the minimum of each our. This means that if the light value is 0 - lights are off, if it's close to 98% lights are on and if it's somewhere in the middle, I had only another white light on at any point in that hour e.g. when I was opening the tent to look after them.
The height measures the hight from a sensor to the light - the sensor is currently ca 5cm above the plants together with the light sensor... the humidity and temperature were measured at the height of the pots.
This is the setup:
Image
Next steps:
- barometer (to check the fan's working)
- soil humidity sensor (for the fun of it)
- connect it to a server
- solder it
- put it in a box (I have to find a good box for it G3!)

So yes, i'd like to make it a bit more permanent but I have no illusions about the accuracy of the whole thing - but I'm pretty sure my chinese thermometer for 5 quid probably uses the same or cheaper components! And in the end it's not necessary and more a cool thing to play around with.

Fun times ahead!

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

So after long time struggling, I finally managed to make an iteration to this project. I am now using a smaller processor (nodemcu) with a BME280 and a photodiode (all together maybe £5-6, connected to my wifi and sending it to Thingspeak, an IoT platform. Now I can see online from anywhere: The temperature, relative humidity, pressure, and light level in my growroom. Temperature and humidity are obviously important, pressure and light were intended so I can check whether the fan is working and I have a lower pressure in the tent, light, so I can check the lights are on or off. Both these aren't working well yet - so more to fiddle, the temperature and humidity are working great! Next project:
- fix light sensor
- place another pressure sensor outside the tent to adjust for atmospheric pressure
- write little code to 1. plot min/max temperature/rh 2. Plot VPD

So it's never ending ;-) but that's the fun of it!
Ask me if you want to know any details!

Image
Image

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Little update... I got the light sensor working now, so it tells me whether the light is on or off from anywhere and gives me some data to stare at when I'm procrastinating...
This is a recent screenshot, you can see that I looked at the plants during lights off, turning on the "work light" - giving only half the signal of the normal light. Once the normal light turns on at 12.30 the temperature goes up and therefore the rh goes down. Also if the light is running, the button is green. The air was super dry recently so I put a small humidifier in the tent and it's now at a reasonable level. Next I need to fix the pressure sensor and do some more fun stuff with the data. The whole thing runs fairly stable, but every now and then (like once every two days) I have to restart it... maybe that's something I can fix.

Image
These users thanked the author weedabix for the post (total 3):
kbag (Mon Mar 30, 2020 1:49 pm) • Hmr81 (Mon Mar 30, 2020 2:44 pm) • Minty (Wed Apr 29, 2020 11:58 pm)

User avatar
Hmr81
Known User
Posts: 636
Joined: Mon Dec 02, 2019 6:32 pm
Has thanked: 111 times
Been thanked: 279 times
Contact:
Status: Online

Re: DIY Data Logger - Dabbling with Arduino

Post by Hmr81 »

Love this mate, it's something I've been meaning to get round to. Tempted to build one per tent, what's the total build cost?
These users thanked the author Hmr81 for the post:
weedabix (Mon Mar 30, 2020 7:14 pm)
From the Garage of HMR :puff puff:

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

costs are:

BME280: £0.99-5
Nodemcu esp 8266: £3-6
photoresistor: £1 for 10

Breadboard, usb cable, resistor (10k ohm) each pretty cheap...

so if you build 3 of them, and you buy them cheap from china, you might get away with maybe £10-15 for all three of them... if you buy the parts on amazon and get some tools and make some mistakes, it gets a bit more expensive.
I ordered lots of things I didn't need, ordered some wrong parts, tried and played around so I have definitely paid more than £5 for it.

Let me know if you need help with it.

User avatar
MafooFarms
Posts: 763
Joined: Sat Feb 22, 2020 4:32 am
Location: MafoooFarms on Instagram
Has thanked: 265 times
Been thanked: 403 times
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by MafooFarms »

Weedabix, praise man. This is legit sir! I would really like to get in on the arduino and raspberry pi robotics builds for data logging and also automation in the future :)

I have some books on how to make sensors and program raspberry pi and arduino units. Just havent made the time or investment to move forward with it.

Def checking in on this
These users thanked the author MafooFarms for the post:
weedabix (Mon Mar 30, 2020 7:14 pm)

User avatar
weedabix
Posts: 447
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 183 times
Been thanked: 228 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Cool, let me run this for a while and I'll see whether it works on a longer scale.. I can then write up a more detailed report of what I did...
These users thanked the author weedabix for the post:
Hmr81 (Mon Mar 30, 2020 8:48 pm)

Post Reply

Return to “Grow Room Designs & Equipment”