pipparichter
Published © GPL3+

Flashing LED Light and Temperature Data Logger

A super-fast and super-bright flashing LED light, perfect for growing plants (and you can record the temperature too)!

BeginnerFull instructions provided8,528
Flashing LED Light and Temperature Data Logger

Things used in this project

Hardware components

Solid and/or stranded core wire (assorted colors)
×1
Chanzon LED light chips (full spectrum)
×1
Chanzon 1W 3W 5W LED heat spreaders
×1
heat sink for MOSFET
This is screwed on to the MOSFET on the SSR module. It is optional, as my MOSFET did not get too hot.
×1
SparkFun MOSFET Power Control Kit
×1
aluminum heat sink
×1
microSD card
For your computer to read the chip, you may need a microSD card adapter.
×1
LPV60-36 constant voltage controller
×1
DS3231 AT24C32 11C real time clock module
×1
2-prong power cord
Any old 2-prong power cord will do-- just cut it and solder it to the constant voltage controller.
×1
heat shrink tubing
For soldering wires together.
×1
microSD card module
×1
thermal adhesive
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino UNO
Arduino UNO
×1

Story

Read more

Schematics

Overview of Wiring Schematics

This is just a diagram showing which pins connect to which. It is not drawn to scale, and wire lengths will have to be adjusted as-needed.

Code

Flashing Light Code

C/C++
In order to change to frequency of the flashing light, adjust the variable hertz (line 31). The start date and time can be adjusted in lines 27 and 28. The code controls the flashing light, and directs the writing of temperature data to the SD card (in CSV format). This code was derived from a how-to post on the HowToMechatronics website.
#include <Wire.h>

#include <DS3231.h> //this library includes functions to be used for the DS3231 module
#include <SD.h> //this library includes functions to be used for the SD card module
#include <SPI.h> //this library includes functions that allow for the communication between the microcontroller and external devices

File tempData; //[defines the variable tempData as a file-type object]
DS3231 rtc(SDA, SCL); //[]
int pinCS = 10; //assigns pin 10 as the Chip Select pin
int gatePin = 4; //assigns pin 4 as the gate pin

void setup(){ //code within setup will only be carried out once

  pinMode(gatePin, OUTPUT); //defines gatePin as output
  
  Serial.begin(9600); //sets the rate of data transmission to the Serial Monitor (Tools > Serial Monitor) at 9600 bits per second
  pinMode(pinCS, OUTPUT); //defines pinCS as output

  if (SD.begin()){ //initializes the SD card and library and begins use of the SPI bus and CS pin
    Serial.println("ready"); //if the SD card and library are initialized successfully, the begin function will return True, and "ready" will be printed to the Serial Monitor
  }
  else{ 
    Serial.println("failed"); //if the SD card and library are not initialized successfully, the begin function will return False, and "failed" will be printed to the Serial Monitor
    return; //the return function will stop the rest of the code from running if the SD card and library fail to initialize
  }
  rtc.begin(); //initializes the microcontroller's internal real time clock and RTC library
  rtc.setTime(0,0,0); //sets the time (hour, minute, second)
  rtc.setDate(30,6,2018); //sets the date [(day, month, year)]
}

int hertz = 1; //creates the variable hertz, which can be altered
float delay_HIGH = (1000/hertz)*0.1; //creates the variable delay_HIGH, which is dependent on hertz and provides for a 10 percent duty cycle
float delay_LOW = (1000/hertz)*0.9; //creates the variable delay_LOW, which is dependent on hertz and provides for a 10 percent duty cycle
int max_count = 600*hertz; //creates the variable max_count, which is dependent on hertz and gives the number of flash cycles that can be repeated in a 10 minute period

void loop(){
  int count = 0;
  while (count <= max_count){ //continues the flash cycle for 10 minutes, or repeats the cycle while the cycle count is less than the number of cycles in 10 minutes   
    digitalWrite(gatePin, HIGH); //sends a HIGH signal to the gate of the MOSFET, powering on the LEDs
    delay(delay_HIGH); //keeps the LEDs on for time delay_HIGH
    digitalWrite(gatePin, LOW); //sends a LOW signal to the gate of the MOSFET, powering off the LEDs
    delay(delay_LOW); //keeps the LEDs off for time delay_low
    count ++; //increments the variable count by one
  }
  Serial.print(rtc.getDateStr()); //prints the date to the Serial Monitor, [imported from the internal RTC]
  Serial.print(",");
  Serial.print(rtc.getTimeStr()); //prints the time to the Serial Monitor, [imported from the internal RTC]
  Serial.print(",");
  Serial.println(float(rtc.getTemp())); //prints the temperature to the Serial Monitor, imported from the DS3231 module

  tempData = SD.open("data.txt", FILE_WRITE); //creates the variable tempData, [which opens/creates the file "data.txt" from the SD card and allows writing]
  if(tempData){ //if the "data.txt" file on the SD card is successfully opened/created, the following data is written to the file in CSV format
    tempData.print(rtc.getDateStr()); //writes the date to "data.txt"
    tempData.print(",");
    tempData.print(rtc.getTimeStr()); //writes the time to "data.txt"
    tempData.print(",");
    tempData.println(float(rtc.getTemp())); //writes the temperature to "data.txt"
    tempData.close(); //closes the file "data.txt"
  }
  else{
    Serial.println("error opening file"); //if the "data.txt" file is not successfully opened/created, "error opening file" is printed to the Serial Monitor
  }
}

Credits

pipparichter

pipparichter

1 project • 5 followers

Comments