loading

Mini Arduino environment monitor ** UPDATE - Added RTC ***

FeaturedContest WinnerContest Winner
This is an Example of how you can use the Arduino to monitor various environmental parameters And display them on a LCD screen. 

Note: I Added a Real Time Clock!! To see the steps, added parts  and Sketch I added new steps..
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts List

Picture of Parts List
Arduino uno R3 or compatible                                           30.00 
Sainsmart "1.8" TFT Color LCD Display                          18.50 
DHT11 Digital Temperature and Humidity Sensor        6.44 
Mini Breadboard                                                                    5.00 
Jumper Wire

Step 2: Connect display to Arduino

I used the mini breadboard to connect the display to the Arduino.
Use jumper wires to connect from the Arduino pins to the breadboard in the following order:
Arduino:  5v         TFT DISPLAY   VCC
                 gnd                                 GND            
Digital     4                                      SCL                  
                 5                                     SDA
                 6                                     CS
                 7                                     DC
                 8                                     RES

Step 3: Test the display

Picture of Test the display
WP_20130610_004.jpg
WP_20130610_006.jpg
WP_20130610_005.jpg
WP_20130610_007.jpg
In order to test the display, you will need to download and install two libraries into your Arduino IDE. Although the display is sold by Sainsmart, I had trouble using their libraries and downloaded the libraries from ADAFRUIT, who sells a similar display and has  much better  documentation and support..I'd normally feel a little guilty about ordering these from SainSmart and using the Adafruit instructions and libraries, but I purchase enough other stuff from Adafruit to appease my conscience. If you end up taking the same route I did, I encourage you to at least look at the other stuff they offer. 

Two libraries need to be downloaded and installed:  The first is the ST7735 library (which contains the low-level code specific to this device). The second is the Adafruit GFX Library (which handles graphics operations common to many displays that Adafruit sells). Download both ZIP files, uncompress and rename the folders to 'Adafruit_ST7735' and 'Adafruit_GFX' respectively, place them inside your Arduino libraries folder and restart the Arduino IDE.

You should now be able to see the  library and examples in  select File > Examples > Adafruit_ST7735 > graphicstest sketch. load the sketch to your Arduino.

If you were successful at installing the libraries, and loading the graficstest sketch,  Click on the verify button to compile the sketch and make sure there are no errors.

It's time to connect your Arduino to your PC using the USB cable, and  click on the upload button  to upload the sketch to the Arduino.
 
Once uploaded, the Arduino should perform all the test display procedures! If you're not seeing anything - check to see if the back-light is on, if the back-light is not lit, something is wrong with the Power  wiring. If the back-light is lit ,but you see nothing on the display recheck the digital signals wiring.

If everything is working as expected, we are ready to  wire up the DHT sensor. 

Step 4: Connect the DHT11 sensor to the Arduino

Picture of Connect the DHT11 sensor to the Arduino
WP_20130610_014.jpg
WP_20130610_013.jpg
As with the display, I used jumper wires to connect the required power and data pins for the DHT11  using the mini Breadboard. Line up the pins and then plug in the sensor.

Looking at the front of the sensor:
From Left to Right
connect pin 1 of DHT11 to 5 V, Pin 2 to Digital Pin 2 of the Arduino, Pin 3 no connection, and Pin 4 to Arduino GND.
That's It! 

Step 5: Test the DHT11 sensor

Picture of Test the DHT11 sensor
WP_20130610_021.jpg
WP_20130610_020.jpg
WP_20130610_019.jpg
WP_20130610_018.jpg
You need to download another Library  to get the Arduino to talk with the DHT11 sensor. The sensor I got didn't come with any documentation, so I Googled around until I found a library that works.
I found it in the Virtualbotix website

As with the display  libraries, Download the library unzip it,  and install it in the Arduino IDE. Place it inside your Arduino libraries folder , rename it  DHT11, and restart the Arduino IDE.

You should now be able to see the  library and examples in  select File > Examples > DHT11 > dht11_functions sketch.
oad the sketch to your Arduino.

If you were successful at installing the libraries, and loading the dht11_functions sketch,  Compile the sketch  by clicking on the verify button and make sure there are no errors.

It's time to connect your Arduino to your PC using the USB cable.  Click on the upload button  to upload the sketch to the Arduino.

Once uploaded to the Arduino, open the serial monitor, and you should see the data stream  with information coming from the sensor.

If you got the sensor working, we're now ready to display the data on the TFT Screen..

Step 6: Final step, Displaying Sensor Data on the TFT

Picture of Final step, Displaying Sensor Data on the TFT
// copy the sketch below and paste it into the Arduino IDE compile and run the program.
// this sketch was created using code from both the adafruit and the virtuabotix sample sketches
// You can use any (4 or) 5 pins
#define sclk 4
#define mosi 5
#define cs   6
#define dc   7
#define rst  8  // you can also connect this to the Arduino reset
#define ANALOG_IN 0 // for cds light sensor

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <dht11.h> // dht temp humidity sensor library

dht11 DHT11;
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);



void setup(void) {
  DHT11.attach(2); // set digital port 2 to sense dht input
  Serial.begin(9600);
  Serial.print("hello!");
 
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  Serial.println("init");
  //tft.setRotation(tft.getRotation()+1); //uncomment to rotate display

// get time to display "sensor up time"
  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;

  Serial.println(time, DEC);
  delay(500);


  Serial.println("done");
  delay(1000);


tftPrintTest();
  delay(500);
  tft.fillScreen(ST7735_BLACK);
// Splash screen for esthetic purposes only
  // optimized lines
  testfastlines(ST7735_RED, ST7735_BLUE);
  delay(500);

  testdrawrects(ST7735_GREEN);
  delay(500);
  tft.fillScreen(ST7735_BLACK);
}
void loop() {
// tft.invertDisplay(true);
// delay(500);
//  tft.invertDisplay(false);
tft.setTextColor(ST7735_WHITE);
tft.setCursor(0,0);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setCursor(50, 20);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_BLUE);
  tft.print(millis() / 1000);
  tft.setTextSize(1);
  tft.setCursor(40, 40);
  tft.setTextColor(ST7735_WHITE);
  tft.println("seconds");
  tft.setCursor(0, 60);
  tft.drawLine(0, 50, tft.width()-1, 50, ST7735_WHITE); //draw line separator
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (C): ");
  tft.setTextColor(ST7735_GREEN);
  tft.println((float)DHT11.temperature,1);
  tft.setTextColor(ST7735_WHITE);
  tft.print("Humidity    (%): ");
  tft.setTextColor(ST7735_RED);
  tft.println((float)DHT11.humidity,1);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (F): ");
  tft.setTextColor(ST7735_GREEN);
  tft.println(DHT11.fahrenheit(), 1);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (K): ");
// tft.print(" ");
  tft.setTextColor(ST7735_GREEN);
  tft.println(DHT11.kelvin(), 1);

  tft.setTextColor(ST7735_WHITE);
  tft.print("Dew Point   (C): ");
  tft.setTextColor(ST7735_RED);
  tft.println(DHT11.dewPoint(), 1);
  tft.setTextColor(ST7735_WHITE);
  tft.print("DewPointFast(C): ");
  tft.setTextColor(ST7735_RED);
  tft.println(DHT11.dewPointFast(), 1);
  tft.drawLine(0, 110, tft.width()-1, 110, ST7735_WHITE);
  tft.setCursor(0,115);
  tft.print("Light intensity ");
int val = analogRead(ANALOG_IN);
  tft.setCursor(60, 130);
   tft.setTextColor(ST7735_YELLOW);
  tft.println(val, 1);
  delay(2000);
  tft.fillScreen(ST7735_BLACK);
 
}
void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 60);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("temperature");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("humidity");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(2);
  tft.println("monitor");
  tft.setTextColor(ST7735_BLUE);
  //tft.setTextSize(3);
  //tft.print(3598865);
  delay(500);
  }
 
void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

Step 7: Bonus ! A light sensor using analog input

Picture of Bonus !  A light sensor using analog input
WP_20130611_013.jpg
WP_20130611_017.jpg
WP_20130611_015.jpg
WP_20130611_010.jpg
WP_20130611_006.jpg
As an Added bonus, you can monitor any analog signal using one of the Arduino analog inputs. As an example , I  will use a CDS photo resistor to monitor Light intensity.
You Wil need:
1 CDS photo-resistor
1 10 K ohm resistor
Steps:
Connect the resistor and  CDS photocell in series in an unused space in the mini breadboard. 
Connect the open leg of the photocell to the +5v
Connect the open leg of the resistor to  GND
Connect the CDS Resistor Junction to the Analog input 0 of the Arduino (the code to monitor the input is already in the sample sketch)
You're done!!
You can monitor virtually any  analog parameter using this input method: i.e Sound level, wind speed, vibration etc...

Step 8: Video of running Prototype

I Don't Know how to embed a video, so here's the link to youtube where you can see it in action.

http://www.youtube.com/watch?v=ZaEn8vhsrsg&feature=youtu.be

Step 9: UPDATE: Added an Ultrasonic sensor and Modified program to just update the numbers

Picture of UPDATE: Added an Ultrasonic sensor and Modified program to just update the numbers
WP_20130613_004.jpg
WP_20130613_003.jpg
// Program now only refreshes numbers and added range meter. will post another instructable with the progress soon
#define sclk 4
#define mosi 5
#define cs   6
#define dc   7
#define rst  8  // you can also connect this to the Arduino reset
#define ANALOG_IN 0 // for cds light sensor

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <dht11.h> // dht temp humidity sensor library
#include <NewPing.h> // S04 Ultrasonic sensor Library
dht11 DHT11;
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.


void setup(void) {
  DHT11.attach(2); // set digital port 2 to sense dht input
  Serial.begin(115200);
  Serial.print("hello!");
 
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  Serial.println("init");
  //tft.setRotation(tft.getRotation()+1); //uncomment to rotate display

  uint16_t time = millis();
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;

// Serial.println(time, DEC);
// delay(500);


// Serial.println("done");
// delay(1000);


tftPrintTest();
  delay(500);
  tft.fillScreen(ST7735_BLACK); // Clear screen
  // commented lines below are  Grid and Square splash Screen
//  optimized lines
//  testfastlines(ST7735_RED, ST7735_BLUE);
//  delay(500);
//  testdrawrects(ST7735_GREEN);
//  delay(500);

  tft.fillScreen(ST7735_BLACK);
}
void loop() {
  // tft.invertDisplay(true);
  // delay(500);
  // tft.invertDisplay(false);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.setCursor(0,0);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setCursor(50, 20);
  tft.setTextSize(2);
  tft.setTextColor(ST7735_BLUE, ST7735_BLACK);
  tft.print(millis() / 1000);
  tft.setTextSize(1);
  tft.setCursor(40, 40);
  tft.setTextColor(ST7735_WHITE);
  tft.println("seconds");
  tft.setCursor(0, 60);
  tft.drawLine(0, 50, tft.width()-1, 50, ST7735_WHITE);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (C): ");
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  tft.println((float)DHT11.temperature,1);
  tft.setTextColor(ST7735_WHITE);
  tft.print("Humidity    (%): ");
  tft.setTextColor(ST7735_RED, ST7735_BLACK);
  tft.println((float)DHT11.humidity,1);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (F): ");
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  tft.println(DHT11.fahrenheit(), 1);
  tft.setTextColor(ST7735_YELLOW);
  tft.print("Temperature (K): ");
// tft.print(" ");
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK);
  tft.println(DHT11.kelvin(), 1);

  tft.setTextColor(ST7735_WHITE);
  tft.print("Dew Point   (C): ");
  tft.setTextColor(ST7735_RED, ST7735_BLACK);
  tft.println(DHT11.dewPoint(), 1);
  tft.setTextColor(ST7735_WHITE);
  tft.print("DewPointFast(C): ");
  tft.setTextColor(ST7735_RED, ST7735_BLACK);
  tft.println(DHT11.dewPointFast(), 1);
  tft.drawLine(0, 110, tft.width()-1, 110, ST7735_WHITE);
  tft.setCursor(0,115);
  tft.print("Light intensity ");
int val = analogRead(ANALOG_IN);
  //tft.setCursor(60, 130);
   tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
  tft.println(val, 1);
  //delay(2000);
 
  delay(500);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  tft.setCursor(0,130);
  tft.setTextColor(ST7735_RED);
  tft.print("Distance: ");
 
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
  tft.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  tft.setTextColor(ST7735_RED,ST7735_BLACK);
  tft.print(" cm   ");
  delay(50);
// tft.fillScreen(ST7735_BLACK);
}
void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 10);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.println("INSTRUCTABLES.COM");
  delay(500);
  tft.setCursor(0, 60);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("temperature");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("humidity");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(2);
  tft.println("monitor");
  tft.setTextColor(ST7735_BLUE);
  //tft.setTextSize(3);
  //tft.print(3598865);
  delay(50);
  }
 
void testfastlines(uint16_t color1, uint16_t color2) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t y=0; y < tft.height(); y+=5) {
    tft.drawFastHLine(0, y, tft.width(), color1);
  }
  for (int16_t x=0; x < tft.width(); x+=5) {
    tft.drawFastVLine(x, 0, tft.height(), color2);
  }
}

void testdrawrects(uint16_t color) {
  tft.fillScreen(ST7735_BLACK);
  for (int16_t x=0; x < tft.width(); x+=6) {
    tft.drawRect(tft.width()/2 -x/2, tft.height()/2 -x/2 , x, x, color);
  }
}

Step 10: Latest stream- lined code (sketch) build. Runs Faster, Looks Better!

Picture of Latest stream- lined code (sketch) build.  Runs Faster, Looks Better!
WP_20130619_003.jpg
WP_20130619_002.jpg
WP_20130619_001.jpg
// Sketch Build 1.04 compiled on Arduino 1.0.3. Changes from last build: moved static prints to void setup, cleaned up void loop redundant code.
// This sketch was modified to run the loop faster.. refresh rate is about 1.5 seconds.
// copy the sketch below and paste it into the Arduino IDE verify, and run the program.
// this sketch was created using code from the adafruit,the virtuabotix, and newPing sample sketches
#define sclk 4
#define mosi 5
#define cs   6
#define dc   7
#define rst  8
#define ANALOG_IN 0 // for cds light sensor

#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <dht11.h> // DHT11 temp humidity sensor library
#include <NewPing.h> // S04 Ultrasonic sensor Library
dht11 DHT11;
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.


void setup(void) {
  DHT11.attach(2); // set digital port 2 to sense DHT11 input

  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  uint16_t time = millis(); // time calculations to display sketch runtime in seconds
  tft.fillScreen(ST7735_BLACK);
  time = millis() - time;


//tftPrintTest(); //Initial introduction text, uncomment to view on screen

  tft.fillScreen(ST7735_BLACK); // Clear screen
 
// *** Printing static Items on display in the setup void in order to speed up the loop void****
  tft.fillScreen(ST7735_BLACK); //  clear screen
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.setCursor(0,0);
  tft.println("Sketch has been");
  tft.println("running for: ");
  tft.setCursor(40, 40);
  tft.setTextColor(ST7735_WHITE);
  tft.println("seconds");
 
   tft.drawLine(0, 50, tft.width()-1, 50, ST7735_WHITE);
   tft.setCursor(0, 60);
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (C): ");
   tft.drawLine(0, 110, tft.width()-1, 110, ST7735_WHITE);
   tft.setTextColor(ST7735_WHITE);
   tft.println("Humidity    (%): ");
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (F): ");
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (K): ");
   tft.setTextColor(ST7735_WHITE);
   tft.println("Dew Point   (C): ");
   tft.setTextColor(ST7735_WHITE);
   tft.println("DewPointFast(C): ");
   tft.setCursor(0,115);
   tft.setTextColor(ST7735_YELLOW);
   tft.print("Light intensity ");
}
void loop() {
  tft.setCursor(50, 20);
  tft.setTextSize(2); //set text size for seconds
  tft.setTextColor(ST7735_BLUE, ST7735_BLACK); // set color for seconds
  tft.print(millis() / 1000);
  tft.setTextSize(1); //set text size for all data coming from DHT11
  tft.setCursor(98, 60);
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set color for all data coming from DHT11
  tft.print((float)DHT11.temperature,2);
  tft.setCursor(98, 68);
   tft.print((float)DHT11.humidity,2);
  tft.setCursor(98, 76);
   tft.print(DHT11.fahrenheit(), 2);
  tft.setCursor(98, 84);
    tft.print(DHT11.kelvin(), 1);
  tft.setCursor(98, 92);
   tft.print(DHT11.dewPoint(), 2);
  tft.setCursor(98,100);
   tft.print(DHT11.dewPointFast(), 2);
  tft.setCursor(98,115);
  int val = analogRead(ANALOG_IN); // READ LIGHT SENSOR VALUE
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); //set light sensor data text color
  tft.print(val, 1); // PRINT LIGHT SENSOR VALUE
  tft.print("  ");
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  tft.setCursor(0,130);
  tft.setTextColor(ST7735_RED);
  tft.print("Distance: ");
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);
  tft.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
  tft.setTextColor(ST7735_RED,ST7735_BLACK);
  tft.print(" cm   ");
  delay(50);

}
void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 10);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.println("INSTRUCTABLES.COM");
  delay(500);
  tft.setCursor(0, 60);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("temperature");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("humidity");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(2);
  tft.println("monitor");
  tft.setTextColor(ST7735_BLUE);
   delay(50);
  }

Step 11: Add A real Time Clock to Monitor

Picture of Add A real Time Clock to Monitor
WP_20130709_006.jpg
WP_20130709_010.jpg
To Add a real time clock to the monitor, you will need:

A TinyRTC Module
4 Jumper wires
The Wire Library
The RTC Library

Step 12:

Picture of
To Connect the TinyRTC to the Arduino, Refer to the Diagram and:

Connect the RTC VCC  to the Arduino  +5 v
                       RTC GND to the Arduino GND
                       RTC SDA to  the Arduino Analog Pin 4
                       RTC SCL to  the Arduino Analog Pin 5


Step 13: Install the Required libraries

Picture of Install the Required libraries
You need to  install the required libraries:

Wire Library -This library is included with the Arduino IDE

RTC Library - Have uploaded this library for your convenience, download it and place it inside your Arduino libraries folder.

If you were successful at installing the libraries,  load the RTClib>DS1307  sketch,  Compile the sketch  by clicking on the verify button and make sure there are no errors.


Click on the upload button  to upload the sketch to the Arduino.

Once uploaded to the Arduino, open the serial monitor, and you should see data   with information coming from the TinyRTC

If you got the TinyRTC  working, we're now ready to display the data on the TFT Screen..

Step 14: Upload the Sketch below to get Time and temperature In your mini display!

Picture of Upload the Sketch below to get Time and temperature In your mini display!
// Sketch Build 1.04 compiled on Arduino 1.0.3.
// This sketch was modified to run the loop faster.. refresh rate is about 1.5 seconds.
// copy the sketch below and paste it into the Arduino IDE verify, and run the program.
// this sketch was created using code from the adafruit-libraries
#define sclk 4
#define mosi 5
#define cs   6
#define dc   7
#define rst  8
#define ANALOG_IN 3 // for cds light sensor
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
#include <Wire.h> // library needed for RTC
#include "RTClib.h" //RTC Library
#include <dht11.h> // DHT11 temp humidity sensor library

RTC_DS1307 RTC;
dht11 DHT11;
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);

void setup(void) {
DHT11.attach(2); // set digital port 2 to sense DHT11 input
Wire.begin();
RTC.begin();

  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab

  tft.fillScreen(ST7735_BLACK);

//tftPrintTest(); //Initial introduction text, uncomment to view on screen

  tft.fillScreen(ST7735_BLACK); // Clear screen
 
// *** Printing static Items on display in the setup void in order to speed up the loop void****
 
   tft.drawLine(0, 50, tft.width()-1, 50, ST7735_WHITE);
   tft.setCursor(0, 60);
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (C): ");
   tft.drawLine(0, 110, tft.width()-1, 110, ST7735_WHITE);
   tft.setTextColor(ST7735_WHITE);
   tft.println("Humidity    (%): ");
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (F): ");
   tft.setTextColor(ST7735_YELLOW);
   tft.println("Temperature (K): ");
   tft.setTextColor(ST7735_WHITE);
   tft.println("Dew Point   (C): ");
   tft.setTextColor(ST7735_WHITE);
   tft.println("DewPointFast(C): ");
   tft.setCursor(0,115);
   tft.setTextColor(ST7735_YELLOW);
   tft.print("Light intensity ");
  
}

void loop() {
  tft.setCursor(10,0);
   tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.println("INSTRUCTABLES.COM");
   tft.setTextColor(ST7735_YELLOW,ST7735_BLACK);
   tft.setTextSize(1);
    tft.setCursor(30,10);
    DateTime now = RTC.now();
    tft.print(now.year(), DEC);
    tft.print('/');
    tft.print(now.month(), DEC);
    tft.print('/');
    tft.print(now.day(), DEC);
    tft.println(' ');
    tft.setCursor(15,25);
    tft.setTextSize(2);
    tft.setTextColor(ST7735_BLUE,ST7735_BLACK);
    tft.print(now.hour(), DEC);
    tft.print(':');
    tft.print(now.minute(), DEC);
    tft.print(':');
    tft.print(now.second(), DEC);
    tft.println(" ");

  tft.setTextSize(1); //set text size for all data coming from DHT11
  tft.setCursor(98, 60);
  tft.setTextColor(ST7735_GREEN, ST7735_BLACK); // set color for all data coming from DHT11
  tft.print((float)DHT11.temperature,2);
  tft.setCursor(98, 68);
   tft.print((float)DHT11.humidity,2);
  tft.setCursor(98, 76);
   tft.print(DHT11.fahrenheit(), 2);
  tft.setCursor(98, 84);
    tft.print(DHT11.kelvin(), 1);
  tft.setCursor(98, 92);
   tft.print(DHT11.dewPoint(), 2);
  tft.setCursor(98,100);
   tft.print(DHT11.dewPointFast(), 2);
  tft.setCursor(98,115);
  int val = analogRead(ANALOG_IN); // READ LIGHT SENSOR VALUE
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK); //set light sensor data text color
  tft.print(val, 1); // PRINT LIGHT SENSOR VALUE
  tft.print("  ");

}
void tftPrintTest() {
  tft.setTextWrap(false);
  tft.fillScreen(ST7735_BLACK);
  tft.setCursor(0, 10);
  tft.setTextColor(ST7735_WHITE);
  tft.setTextSize(1);
  tft.println("INSTRUCTABLES.COM");
  delay(500);
  tft.setCursor(0, 60);
  tft.setTextColor(ST7735_RED);
  tft.setTextSize(2);
  tft.println("temperature");
  tft.setTextColor(ST7735_YELLOW);
  tft.setTextSize(2);
  tft.println("humidity");
  tft.setTextColor(ST7735_GREEN);
  tft.setTextSize(2);
  tft.println("monitor");
  tft.setTextColor(ST7735_BLUE);
   delay(50);
  }
1-40 of 87Next »
sel303 made it!4 months ago

Thanks for the instructable! I changed the display a little and only used the DHT11 sensor. I have a different TFT display also.

Thanks!

IMG_20150328_130639~2.jpg

can you tell me please the model of your TFT display? thank you

Tontec 1.8" TFT Color LCD Display Module SPI Interface MicroSD for Arduino UNO MEGA R3. I got it from amazon

Is this possible to make with an Arduino Pro Mini to make it smaller? I am new at this. :D

*and portable.

stagehawk21 made it!3 months ago

Thank you so much for sharing your work! I am quite new to the electronics community, but thanks to people like yourself I learn more, and more each day. I just finished building this environment monitor, and already have plans for augmenting the system. Your Instructable is; well-constructed, clear, and concise. It was truly a pleasure following your lead, and I couldn't be more proud of the result. Thanks again for sharing, and keep up the good work!

IMG_0139[1].JPGIMG_0140[1].JPGIMG_0143[1].JPG
thenickbyrd4 months ago

I get the following error when running the example from the library to test the display(step 3)

avrdude: stk500_getsync(): not in sync: resp=0x30

Can anyone help me?

peter6961 made it!7 months ago
love it, cant wait for the updates.
after reading this instructible I went ahead and ordered a screen and rtc as you mentioned.
I received my lcd 2 weeks ago, added a 4 port relay, moded code for the very first time!!( yay me haha raspberry pi helped a load!) and hooked it up to my 7x6x7 greenhouse for a week with lights and fans, it stayed at daytime a constant 28c (exactly what I set it!) and today I received my rtc :-), I cant wait to use the sd card!, how are you planning on viewing the log on the sd? button to flash screen would be cool.
thank you very much for your time and effort to make this public it is very much appreciated!


pictured is a very crude case but I ts all I had laying around.
temp_608441278.jpg
fastenspy8 months ago

Hello, how to refresh the number on the screnn, but without refreshing the entire screen ?!

HULKGQN fastenspy7 months ago

the code dose that now. give it a try.

dvshverma8 months ago

Brilliant documentation, very clear instruction

MaximeM9 months ago

Hello,

I have this problem, even if I place "versalino.h" in the same directory as the sketch * .ino.

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows Vista), Board: "Arduino Uno"
In file included from dht11.cpp:43:
dht11.h:66: error: 'VersalinoBUS' does not name a type
dht11.h:67: error: 'VersalinoBUS' has not been declared
dht11.h:73: error: 'VersalinoBUS' has not been declared
dht11.h:76: error: 'VersalinoBUS' has not been declared
dht11.h:80: error: 'VersalinoBUS' has not been declared
dht11.h:93: error: 'VersalinoBUS' does not name a type
dht11.cpp:59: error: 'VersalinoBUS' has not been declared
dht11.cpp:66: error: 'VersalinoBUS' has not been declared
dht11.cpp: In member function 'void dht11::attach(int, int)':
dht11.cpp:69: error: '_myBUS' was not declared in this scope
dht11.cpp: At global scope:
dht11.cpp:81: error: 'VersalinoBUS' does not name a type
dht11.cpp:91: error: variable or field 'setBUS' declared void
dht11.cpp:91: error: 'VersalinoBUS' was not declared in this scope
dht11.cpp: In member function 'int dht11::read()':
dht11.cpp:111: error: '_myBUS' was not declared in this scope
dht11.cpp: At global scope:
dht11.cpp:116: error: 'VersalinoBUS' has not been declared
dht11.cpp: In member function 'int dht11::read(int, int)':
dht11.cpp:118: error: request for member 'PINS' in 'myBUS', which is of non-class type 'int'

Mackmario11 months ago

thank you so much finally was able to get my lcd screen to work!

HI everyone

I have a next problem when I try to compyle

C:\Program Files (x86)\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(const uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:324: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:326: error: 'SPI_CLOCK_DIV4' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\Adafruit_ST7735\Adafruit_ST7735.cpp:334: error: 'SPI_MODE0' was not declared in this scope

thpradhan1 year ago

i am a software developer after reviewing these project i am big fan of Arduino and your's .. thanks a lot for nice share..

in couple of days i am getting my board and other things as soon i do my first test m going to upload :)

thanks once again for lovely share.

pkinahan1 year ago

Would it be possible to add a particle counter to this instructable?

johnag (author)  pkinahan1 year ago

yes, if you find one with an arduino compatible output... but I haven't seen. Any out there...

boozer_21 year ago

I dont really need the display, but I need to access the sensor values over the network so I can remotely monitor temp/humidity etc. Anyone know how to add networking to this so the temps can be read remotely?

johnag (author)  boozer_21 year ago

check this instructable out, it might be what you're. Looking for:

http://www.instructables.com/id/Arduino-TempHumidity-with-LCD-and-Web-Interface/

sam_771 year ago

Dear Jhon

That's a gr8 project you have built but after watching your vedio i wish to ask you why does the display on the lcd screen keeps on changing is there any way to keep it stable?

regards

sachin

johnag (author)  sam_771 year ago

yes the last update to the sketch only refreshes the numbers instead of clearing the entire screen

sam_77 johnag1 year ago

thnx dear John would I am looking forward to make after a few things done

sam_77 johnag1 year ago

thnx dear John would I am looking forward to make after a few things done

Edgar2 years ago
This can help security personnel monitor a lot of additional useful stuff, at a glance, you could make a commercial version of this. Voted and went to my Blog:
http://faz-voce-mesmo.blogspot.pt/2013/06/robots-brava.html
johnag (author)  Edgar2 years ago
Obrigado Edgar

Hello.

The project remarkable, tell as to replace DHT11 sensor with the DS18S20 sensor, what it is necessary to change?

Edgar johnag2 years ago
Sempre às ordens.
Edgar johnag2 years ago
:)
anikin19761 year ago

Hello.

The project remarkable, tell as to replace DHT11 sensor with the DS18S20 sensor what it is necessary to change?

MoonDocker1 year ago

I don't know if anyone else noticed but you need to change the graphicstest code example from adafruit to work with this display. Make sure you have the below at the beginning of the code. The code comes preset with the code for the shield. I spent a few minutes trying to get my display to work and finally looked closely at the code.

// For the breakout, you can use any (4 or) 5 pins

#define sclk 4

#define mosi 5

#define cs 6

#define dc 7

#define rst 8 // you can also connect this to the Arduino reset

Hello,
I want to use a larger display 3.2 for this project, what would I use here?

Thanks nice project
Hello Well, maybe a stupid question but
How can I set the date and time I have some tried but no result.

Thanks Bill
johnag (author)  barracuda431 year ago
Use the sample sketch that came with the rtc library there is an option to set the rtc to your compute time

johnag (author)  johnag1 year ago
Code to set the clock:

if (! RTC.isrunning()) {

// following line sets the RTC to the date & time the sketch is compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
johnag (author)  johnag1 year ago
Here's an sketch to run just the RTC, copy and paste to the Arduino IDE. it sets the clock if it's not set.
// Sketch Build 1.04 compiled on Arduino 1.0.3.
// This sketch was modified to run the loop faster.. refresh rate is about 1.5 seconds.
// copy the sketch below and paste it into the Arduino IDE verify, and run the program.
// this sketch was created using code from the adafruit and RTC -libraries
#define sclk 4
#define mosi 5
#define cs 6
#define dc 7
#define rst 8

#include // Core graphics library
#include // Hardware-specific library
#include
#include // library needed for RTC
#include "RTClib.h" //RTC Library

RTC_DS1307 RTC;

Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);

void setup(void) {

Wire.begin();
RTC.begin();

tft.initR(INITR_BLACKTAB); // initialize a ST7735S chip, black tab

tft.fillScreen(ST7735_BLACK); // Clear screen

if (! RTC.isrunning()) {
tft.println("RTC was NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
delay(3000);
tft.fillScreen(ST7735_BLACK); // Clear screen

}
}

void loop() {
tft.setCursor(10,0);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
tft.println("INSTRUCTABLES.COM");
tft.setTextColor(ST7735_YELLOW,ST7735_BLACK);//set text color & size for DATE coming from TinyRTC
tft.setTextSize(2);
tft.setCursor(5,30);
DateTime now = RTC.now();
tft.print(now.year(), DEC);
tft.print('/');
tft.print(now.month(), DEC);
tft.print('/');
tft.print(now.day(), DEC);
tft.println(' ');
tft.setCursor(15,70);
tft.setTextColor(ST7735_GREEN,ST7735_BLACK); //set color for TIME
tft.setTextSize(2);//set text size for TIME coming from TinyRTC
tft.print(now.hour(), DEC);
tft.print(':');
if(now.minute() < 10) {
tft.print('0');
tft.print(now.minute(), DEC);
}
else {
tft.print(now.minute(), DEC);
}
tft.print(':');
if(now.second() < 10) {
tft.print('0');
tft.print(now.second(), DEC);
}
else {
tft.print(now.second(), DEC);
}
tft.println(" ");

}

ptosaure1 year ago
Hi, I have a problem with the library, in my sketch it's written :

In file included from sketch_sep21a.ino:12:
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:9: error: stray '\302' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:9: error: stray '\267' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:9: error: stray '\302' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:9: error: stray '\267' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: stray '#' in program
In file included from sketch_sep21a.ino:13:
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:9: error: stray '\302' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:9: error: stray '\267' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:9: error: stray '\302' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:9: error: stray '\267' in program
In file included from sketch_sep21a.ino:13:
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:315:46: error: exponent has no digits
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:316:62: error: exponent has no digits
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_ST7735/Adafruit_ST7735.h:599: error: stray '#' in program
In file included from sketch_sep21a.ino:12:
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:4: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:403: error: expected constructor, destructor, or type conversion before 'const'
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '=' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected constructor, destructor, or type conversion before '.' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected constructor, destructor, or type conversion before '.' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected constructor, destructor, or type conversion before '.' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token
C:\Users\Bichon\Desktop\arduino-1.0.3\libraries\Adafruit_GFX/Adafruit_GFX.h:552: error: expected unqualified-id before '<' token


I have try other version and other library but they don't work... coul'd you help me please
Thank you
can you guide me sir?
jmh430811 year ago
The DHT sensor and display are working fine. When I try to compile this sketch on either the 1.01 or 1.05 IDE environment I get

sketch_aug18a:17: error: expected constructor, destructor, or type conversion before numeric constant
sketch_aug18a.cpp: In function 'void setup()':
sketch_aug18a:23: error: request for member 'attach' in '11', which is of non-class type 'int'
sketch_aug18a.cpp: In function 'void loop()':
sketch_aug18a:78: error: request for member 'temperature' in '11', which is of non-class type 'int'
sketch_aug18a:82: error: request for member 'humidity' in '11', which is of non-class type 'int'
sketch_aug18a:86: error: request for member 'fahrenheit' in '11', which is of non-class type 'int'
sketch_aug18a:91: error: request for member 'kelvin' in '11', which is of non-class type 'int'
sketch_aug18a:96: error: request for member 'dewPoint' in '11', which is of non-class type 'int'
sketch_aug18a:100: error: request for member 'dewPointFast' in '11', which is of non-class type 'int
Ideas?
johnag (author)  jmh430811 year ago
Check the dht Library.seems like it's Not installed properly
kurtee1 year ago
Very nice instructable!
Don't forget to add the leading "0" for Minutes and Seconds when < 10 on the RTC.
; )
1-40 of 87Next »