--> Project II - 16. Bar Graph Digital Thermometer Using TFT LCD Touch Screen (Arduino Based) | basic arduino tutorial

Monday, August 7, 2017

Project II - 16. Bar Graph Digital Thermometer Using TFT LCD Touch Screen (Arduino Based)

| Monday, August 7, 2017
Bar Graph Digital Thermometer Using TFT LCD Touch Screen




Arduino UNO reads the temperature with LM35 temperature sensor and LCD touch screen. The LCD module used is 2.4 '' TFT LCD Shield.


Hardware Requirement
  • LCD 2,4’’ TFT Shield with Touch Screen Module
  • Arduino UNO
  • LM35 Temperature Sensor
  • Power supply +5 Volt


                  LM35 Temperature Sensor | Source     LCD 2.4" TFT Shield with Touch Screen | Source


Block diagram


Schematic


Arduino - LCD 2.4" TFT Wiring




LCD 2.4" TFT Module is compatible with Arduino Uno, so you just plug in to the top of Arduino with All of pin connected, Like image below.





Source Code/Sketch


#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define YP A3
#define XM A2
#define YM 9
#define XP 8
#define XGRAPH 50
#define YGRAPH 125
#define HGRAPH 135
#define WGRAPH 21 //LEBAR GRAPH HARUS GANJIL
#define LM35 A5
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
int newHeight;
int oldHeight = 0;
int heightDiff;
void setup(void) {
tft.reset();
uint16_t identifier = tft.readID();
if(identifier==0x0101)identifier=0x9341;
tft.begin(identifier);
tft.fillScreen(BLACK);
tft.drawRect(10, 10, 220, 75, YELLOW);
tft.fillRect(15, 15, 210, 65, BLUE);
tft.drawRect(10, 90, 220, 220, WHITE);
tft.fillRect(15, 95, 210, 210, WHITE);
tft.setTextColor(YELLOW, BLUE);
tft.setTextSize(3);
tft.setCursor(22, 20);
tft.print("Thermometer");
tft.setCursor(60, 50);
tft.print("Digital");
tft.setTextColor(RED);
tft.setTextSize(2);
tft.setCursor(140, 195);
tft.print("Suhu:");
Serial.begin(9600);
tft.fillCircle(XGRAPH, YGRAPH, (WGRAPH/2), BLACK);
tft.fillRect((XGRAPH-(WGRAPH/2)), YGRAPH, WGRAPH, HGRAPH, BLACK);
tft.fillCircle(XGRAPH, (HGRAPH+YGRAPH), ((WGRAPH/2)+10), BLACK);
tft.fillCircle(XGRAPH, YGRAPH, (WGRAPH/2)-3, WHITE);
tft.fillRect((XGRAPH-(WGRAPH/2)+3), YGRAPH, (WGRAPH-6), HGRAPH, WHITE);
tft.fillCircle(XGRAPH, (HGRAPH+YGRAPH), ((WGRAPH/2)+7), WHITE);
tft.fillCircle((XGRAPH+WGRAPH), YGRAPH, 3, BLACK);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(((XGRAPH+WGRAPH)+8), (YGRAPH-5));
tft.print("100");
tft.setTextSize(1);
tft.print("0");
tft.setTextSize(2);
tft.print("C");
tft.fillCircle((XGRAPH+WGRAPH), ((YGRAPH+(HGRAPH/2))-(WGRAPH/2)), 3, BLACK);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(((XGRAPH+WGRAPH)+8), (((YGRAPH+(HGRAPH/2))-(WGRAPH/2)))-5);
tft.print("50");
tft.setTextSize(1);
tft.print("0");
tft.setTextSize(2);
tft.print("C");
tft.fillCircle((XGRAPH+WGRAPH), ((YGRAPH+HGRAPH)-((WGRAPH/2)+7)), 3, BLACK);
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.setCursor(((XGRAPH+WGRAPH)+8), (((YGRAPH+HGRAPH)-((WGRAPH/2)+7))-5));
tft.print("0");
tft.setTextSize(1);
tft.print("0");
tft.setTextSize(2);
tft.print("C");
//tft.fillCircle(175, 225, 26, RED);
tft.fillRect((XGRAPH-(WGRAPH/2)+5), YGRAPH, (WGRAPH-10), HGRAPH, RED);
tft.fillCircle(XGRAPH, (HGRAPH+YGRAPH), ((WGRAPH/2)+5), RED);
}
void loop(void) {
int suhu=(analogRead(LM35)*5)/10;
tft.setCursor(130, 220);
tft.setTextColor(RED, WHITE);
tft.setTextSize(4);
tft.print(suhu);
tft.setTextSize(2);
tft.print("0");
tft.setTextSize(4);
tft.print("C");
tft.fillRect(130, 255, 80, 4, RED);
if(suhu <= 100){
newHeight = map(suhu,0, 100, 0, (HGRAPH-(WGRAPH/2)));
heightDiff = oldHeight-newHeight; // only draw new part of bar graph for faster display
if (oldHeight != newHeight) tft.fillRect((XGRAPH-(WGRAPH/2)+5), YGRAPH+((HGRAPH-suhu)-((WGRAPH/2)+7)), (WGRAPH-10), HGRAPH-((HGRAPH-suhu)-((WGRAPH/2)+7)), RED);
tft.fillRect((XGRAPH-(WGRAPH/2)+5), YGRAPH, (WGRAPH-10), ((HGRAPH-suhu)-((WGRAPH/2)+7)), WHITE);
if (suhu==100)tft.fillCircle(XGRAPH, YGRAPH, (WGRAPH/2)-5, RED);
oldHeight=newHeight; // remember how high bar is
}
tft.fillCircle(XGRAPH, (HGRAPH+YGRAPH), ((WGRAPH/2)+5), RED);
delay(300);
}

How it Works

1. Connect the Arduino with Peripherals needed
2. Plug in the Power Source on the device
3. Compile and upload the script program above to your arduino

4. Make sure the TFT LCD library is installed.
5. The LCD instantly displays the readable temperature


Video for  Project II - 16. Bar Graph Digital Thermometer Using TFT LCD Touch Screen (Arduino Based)





Download the required file.

Related Posts

6 comments:

  1. I followed the instructions and doesn't work, regards

    ReplyDelete
    Replies
    1. Check the LCD Shield pins: it should be A0, A1, A2, A3 and A4

      Delete
  2. I well followed the instructions, the LCD Shield pins are exactly A0 to A4 of the Arduino Uno. But it doesn't work.
    Regards

    ReplyDelete
  3. Thank you. You can ignore my previous email I finally solved the problem
    Regards.

    ReplyDelete
  4. the display flickers a bit can I do something about that?

    ReplyDelete