Welcome to the grow room designs and equipment section. Every grower faces different obstacles when setting up a cannabis grow room. Use this section to discuss the different types of grow rooms you use or would like information about to grow cannabis. To become part of our online cannabis growing community click here to register.

DIY Data Logger - Dabbling with Arduino

Discuss setting up your space & what equipment to use
Post Reply
User avatar
weedabix
Registered User
Posts: 475
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 148 times
Been thanked: 123 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
Registered User
Posts: 11786
Joined: Tue Oct 31, 2017 12:05 am
Location: Mount Zion
Has thanked: 39 times
Been thanked: 156 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
Registered User
Posts: 475
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 148 times
Been thanked: 123 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Thanks Smokey, I appreciate your kind words!

User avatar
GMO
Registered User
Posts: 10500
Joined: Sat Jun 02, 2018 2:44 pm
Has thanked: 4546 times
Been thanked: 3136 times
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by GMO »

this is flipping awesome!

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

User avatar
weedabix
Registered User
Posts: 475
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 148 times
Been thanked: 123 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
Registered User
Posts: 475
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 148 times
Been thanked: 123 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
Registered User
Posts: 9793
Joined: Thu Jan 01, 1970 2:33 am
Location: My nest
Has thanked: 507 times
Been thanked: 758 times
Contact:
Status: Offline

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
weedabix
Registered User
Posts: 475
Joined: Mon Dec 02, 2019 9:12 am
Has thanked: 148 times
Been thanked: 123 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
Egzoset
Registered User
Posts: 143
Joined: Sat Nov 23, 2019 6:13 am
Has thanked: 61 times
Been thanked: 77 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
Vaporist of Borg.

User avatar
G3W2HIN
Registered User
Posts: 1146
Joined: Fri Nov 01, 2019 8:20 pm
Location: USA
Has thanked: 183 times
Been thanked: 359 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

Post Reply

Return to “Grow Room Designs & Equipment”