Hey everybody! So I been at my little project for a bit now, I thought I finally got it all done, but I was really wrong. (I'm using TFT ips display, 2inch")
I have three sensors hooked up (Light Sensor, Moisture sensor and tempature/Humidity sensor)
FYI temp and Humid sensor are getting shipped ATM.
But for the life of me, I can't figure out how to utilize the whole 2inch display, it's stuck in the top left corner. So I'm just wondering if anybody could nudge me to the right direction on how to do that? ![]()
//#include <DFRobot_DHT11.h>
#include <TFT.h>
#include <SPI.h>
//#include <Wire.h>
#define cs 10
#define dc 9
#define rst -1
//#define DHTPIN 7
#define LRPIN A0
#define led 4
#define buz 6
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
//DFRobot_DHT11 DHT;
float humidity,temperature,LDR;
String temp,hum,soil_moist,ligh_sensor;
int soil_moisture,SM;
int light_sensor,LS;
char T[5],H[5],moist[3],sensor[2];
void display_data_serial()
{
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.println(" deg C");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %RH");
Serial.print("soil moisture: ");
Serial.print("SM");
Serial.println('%');
Serial.print("Light Amount: ");
Serial.print("LS");
Serial.println('%');
}
void setup()
{
TFTscreen.begin();
TFTscreen.background(128,128,128);
TFTscreen.fill(128,128,128);
Serial.begin(9600);
Serial.println("temperature, humidity and soil moisture monitoring program");
TFTscreen.setTextSize(2);
TFTscreen.stroke(255,0,255);
TFTscreen.text("Tem: ", 0, 10);
TFTscreen.text(" *C", 115, 15);
TFTscreen.stroke(0,255,255);
TFTscreen.text("Hum: ", 0, 60);
TFTscreen.text(" %RH", 113, 60);
TFTscreen.stroke(255,255,0);
TFTscreen.text("Moist: ", 0,100);
TFTscreen.text("%", 110, 95);
TFTscreen.stroke(255,255,255);
TFTscreen.text("LS: ",0, 110);
TFTscreen.text("%", 140, 110);
TFTscreen.setTextSize(3);
pinMode(led,OUTPUT);
pinMode(buz,OUTPUT);
}
void loop()
{
// DHT.read(DHTPIN);
// humidity = DHT.humidity;
// temperature = DHT.temperature;
//digitalWrite(led,1);
//digitalWrite(buz,1);
light_sensor = analogRead(A0);
soil_moisture = analogRead(A1);
SM = map(soil_moisture,10,1000,100,0);
LS = map(light_sensor,10,1000,100,0);
display_data_serial();
hum = String(humidity);
temp = String(temperature);
soil_moist = String(SM);
hum.toCharArray(H,5);
temp.toCharArray(T,5);
soil_moist.toCharArray(moist,3);
ligh_sensor.toCharArray(sensor, 2);
TFTscreen.stroke(0,0,200);
TFTscreen.text(T,50,5);
TFTscreen.stroke(0,200,0);
TFTscreen.text(H,50,55);
TFTscreen.stroke(200,0,0);
TFTscreen.text(moist,70,95);
TFTscreen.text(sensor,80,95);
delay(200);
digitalWrite(led,0);
digitalWrite(buz,0);
delay(1800);
TFTscreen.stroke(0,0,0);
TFTscreen.text(T,50,5);
TFTscreen.text(H,50,55);
TFTscreen.text(moist,70,95);
TFTscreen.text(sensor, 80, 95);
delay(200);
}
