/* SD card datalogger This example shows how to log data from three analog sensors to an SD card using the SD library. The circuit: * analog sensors on analog ins 0, 1, and 2 * SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 ** CS - pin 10 (for MKRZero SD: SDCARD_SS_PIN) created 24 Nov 2010 modified 9 Apr 2012 by Tom Igoe This example code is in the public domain. */ /* TM1637 DISPLAY Basic usage example Demonstrated some of the basic functionality of the library. Initialize the display, set the backlight brightness, print some text, count from 0 to 100 and print on display and blink some text. Note: make sure to set your serial monitor to line end: NEW LINE! The circuit: * connect TM1637 pin CLK to Arduino pin D4 * connect TM1637 pin DIO to Arduino pin D5 * connect TM1637 pin Vcc to Arduino pin 5V * connect TM1637 pin GND to Arduino pin GND Created 25 September 2015 By Bram Harmsen https://github.com/bremme/arduino-tm1637 */ //http://www.circuitbasics.com/how-to-set-up-the-dht11-humidity-sensor-on-an-arduino/ // Added DHTLib library on this link //For DS3231 library //http://www.rinkydinkelectronics.com/library.php?id=73 //https://github.com/avishorp/TM1637 #include // include the SevenSegmentTM1637 library #include "SevenSegmentTM1637.h" #include #include #include #include #include "DS3231.h" RTClib RTC; dht DHT; #define DHT11_PIN 2 const int chipSelect = 10; /* initialize global TM1637 Display object * The constructor takes two arguments, the number of the clock pin and the digital output pin: * SevenSegmentTM1637(byte pinCLK, byte pinDIO); */ const byte PIN_CLK = 4; // define CLK pin (any digital pin) const byte PIN_DIO = 3; // define DIO pin (any digital pin) SevenSegmentTM1637 display(PIN_CLK, PIN_DIO); void setup() { // Open serial communications and wait for port to open: Serial.begin(57600); Wire.begin(); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.print("Initializing SD card..."); // see if the card is present and can be initialized: if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); // don't do anything more: while (1); } Serial.println("card initialized."); display.begin(); // initializes the display display.setBacklight(100); // set the brightness to 100 % display.print("INIT"); // display INIT on the display delay(1000); // wait 1000 ms display.clear(); } void loop() { //delay(3000); DateTime now = RTC.now(); // make a string for assembling the data to log: String dataString = ""; int chk = DHT.read11(DHT11_PIN); //Serial.print("Temperature = "); //Serial.println(DHT.temperature); //Serial.print("Humidity = "); //Serial.println(DHT.humidity); //delay(1000); // read DHT11 sensors and append to the string: //dataString += String("Temperature = " + DHT.temperature + " Humidity = " + DHT.humidity); dataString += String(now.year()) + "/" + String(now.month()) + "/" + String(now.day()) + " " + String(now.hour()) + ":" + String(now.minute()) + ":" + String(now.second()) + ","; dataString += String(DHT.temperature) + "," + String(DHT.humidity); //Serial.println(dataString); delay(1000); // open the file. note that only one file can be open at a time, // so you have to close this one before opening another. File dataFile = SD.open("datalog.txt", FILE_WRITE); // if the file is available, write to it: if (dataFile) { dataFile.println(dataString); dataFile.close(); // print to the serial port too: Serial.println(dataString); uint8_t humidity; humidity = DHT.humidity; uint8_t temperature; temperature = DHT.temperature; display.print("T="); delay(1000); //A half second delay between steps. display.clear(); display.print(temperature); // print SUCC for success delay(1000); //A half second delay between steps. display.clear(); display.print("RH="); delay(1000); //A half second delay between steps. display.clear(); display.print(humidity); //Display the Variable value; DHT.temperature delay(1000); //A half second delay between steps. display.clear(); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } }