Welcome to Growroom420! If this is your first visit then you have found the friendliest canna forum on the net and your home of all things growing. Check out grow diaries, enter competitions and much more. Click here to register and become part of our growing community.

DIY Data Logger - Dabbling with Arduino

Discuss setting up your space & what equipment to use
Post Reply
User avatar
weedabix
Posts: 77
Joined: Mon Dec 02, 2019 9:12 am
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

green-qube
User avatar
Smokey
Moderator
Posts: 11405
Joined: Tue Oct 31, 2017 12:05 am
Location: Mount Zion
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: 77
Joined: Mon Dec 02, 2019 9:12 am
Contact:
Status: Offline

Re: DIY Data Logger - Dabbling with Arduino

Post by weedabix »

Thanks Smokey, I appreciate your kind words!

User avatar
GMO
Moderator
Posts: 6244
Joined: Sat Jun 02, 2018 2:44 pm
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

User avatar
weedabix
Posts: 77
Joined: Mon Dec 02, 2019 9:12 am
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.

Post Reply

Return to “Grow Room Designs & Equipment”