Temperature alarm and time on a LCD screen with a DS3231, Buzzer and LED

In this article we will measure the temperature and the RTC clock time with the DS3231 module.
We will implement a buzzer and led for the temperature alarm.
After that, we will display these values on a A000096 1.17 inch TFT/LCD screen!

Read the tutorial below or watch the youtube video.

Project materials:

Arduino UNO
Click here for the Amazon productlink
arduino-uno

TFT 1.17 inch LCD screen (A000096 Arduino)
Click here for the Amazon productlink

arduino-tft

DS3231
Click here for the Amazon productlink

Buzzer 5V
Click here for the Amazon productlink

LED 5V

Some wires
Click here for the Amazon productlink

wires.jpg

Wiring Diagram:

Arduino wiring diagram DS3231 + Buzzer + Led.jpg

Arduino pin 2  –  Buzzer and Led +
Arduino pin 4  –  SD LCD screen
Arduino pin 8  –  Reset LCD screen
Arduino pin 9  –  D/C LCD screen
Arduino pin 10 – CS LCD screen
Arduino pin 11  – MOSI LCD screen
Arduino pin 12  – MISO LCD screen
Arduino pin 13  – SCK LCD screen
Arduino 5V         – 5V  LCD screen, VVC DS3231, BL LCD screen
Arduino GND     – GND LCD screen, GND DS3231, – LED, – Buzzer
Arduino A4         – SDA DS3231
Arduino A5          – SCL DS3231

Arduino Code

 

Click here for the DS3231 library link

 

// CreaTechWeb: Temperature alarm and time on a LCD screen with a DS3231, Buzzer and LED
// https://createchweb.com/temperature-alarm-and-time-on-a-lcd-screen-with-a-ds3231-buzzer-and-led/

#include <DS3231.h>
#include <SPI.h>
#include <TFT.h>

char Printout[10];

#define cs     10
#define dc     9
#define rst    8

TFT TFTscreen = TFT(cs, dc, rst);

// Init the DS3231 using the hardware interface
DS3231  rtc(SDA, SCL);

// Init a Time-data structure
Time  t;


float temperature;


int BuzLedPin =  2;      // the number of the BuzLed Pin

void setup()
{
  // Get data from the DS3231
  rtc.begin();

  //Set the start date and time
  rtc.setTime(16, 12, 00);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(27, 11, 2016);   // Set the date to January 1st, 2014


  // Put this line at the beginning of every sketch that uses the GLCD:
  TFTscreen.begin();
  // Clear the screen with a white background
  TFTscreen.background(255, 255, 255);
  // set the font color to white
  TFTscreen.stroke(0, 0, 0);
  // set the text size to small (1)
  TFTscreen.setTextSize(1);
  // Print the text on the LCD screen
  TFTscreen.text("www.CreaTechWeb.com\n ", 25, 5);
  TFTscreen.text("Creative with Arduino\n ", 15, 15);

  // Set the standard text size for the loop
  TFTscreen.setTextSize(2);

  // Set BuzLedPin as OUTPUT
  pinMode(BuzLedPin, OUTPUT); 
 
}

void loop() {
  // Get data from the DS3231
  t = rtc.getTime();

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  String(t.date, DEC).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 20, 40);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  // Print the : on the LCD screen
  TFTscreen.text(":", 40, 40);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  String(t.mon, DEC).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 50, 40);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  // Print the : on the LCD screen
  TFTscreen.text(":", 70, 40);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  String(t.year, DEC).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 80, 40);




  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  String(t.hour, DEC).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 50, 70);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  // Print the : on the LCD screen
  TFTscreen.text(":", 70, 70);

  // set the font color to green
  TFTscreen.stroke(181, 230, 29);
  String(t.min, DEC).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 80, 70);

  // set the font color to red
  TFTscreen.stroke(255, 0, 0);
  // Get current temperature data from the DS3231
  String(rtc.getTemp()).toCharArray(Printout, 13);
  // Print the value on the LCD screen
  TFTscreen.text(Printout, 40, 100);
  // Print the C on the LCD screen
  TFTscreen.text("C", 110, 100);
  
  // Get data from the DS3231
  temperature = rtc.getTemp();

  // if temperature drops below 20 celcius set BuzLedPin HIGH
  if ( temperature < 20)
  {
    digitalWrite(BuzLedPin, HIGH);   
  }
  
  // if temperature rises above 20 celcius set BuzLedPin LOW
  if ( temperature > 20) 
  {
    digitalWrite(BuzLedPin, LOW);
  }

  // Refresh every 60 seconds the LCD screen and his values.
  delay (60000);
  TFTscreen.noStroke();
  TFTscreen.fill (255, 255, 255);
  TFTscreen.rect( TFTscreen.width() / 3 - 40, TFTscreen.height() / 3 - 10, TFTscreen.width() / 3 + 70, TFTscreen.height() / 3 + 40);

}

End result

20161127_171925.jpg

Geef een reactie

Vul je gegevens in of klik op een icoon om in te loggen.

WordPress.com logo

Je reageert onder je WordPress.com account. Log uit / Bijwerken )

Twitter-afbeelding

Je reageert onder je Twitter account. Log uit / Bijwerken )

Facebook foto

Je reageert onder je Facebook account. Log uit / Bijwerken )

Google+ photo

Je reageert onder je Google+ account. Log uit / Bijwerken )

Verbinden met %s