int analogPin = A3;
int Rawval ; // variable to store the value read
int Scaleval ;
int RELAY_pin = 10; // Relay is connected to pin D10
void setup()
{
Serial.begin(9600); // setup serial
pinMode(RELAY_pin, OUTPUT);
}
void loop()
{
int Rawval = analogRead(analogPin);
Serial.print("Rawvalue from Analog input =");
Serial.print(Rawval);
// For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
Scaleval = map(Rawval, 0, 675, 0, 20);
Serial.print(" Scaled Value =");
Serial.println(Scaleval);
/// === RELAY code ===
// raw value 675 correspond to 20%, so for 5% we will get 169
if ( Rawval < 169) digitalWrite(RELAY_pin, HIGH);
else digitalWrite(RELAY_pin, LOW);
}
A description for your tutorial would be appreciated.
Your tutorial seems to be missing the LCD code. Not a very good tutorial on displaying sensor data.
Seriously, do you expect someone to just write the code to display the mystery sensor data on the mystery LCD for free. Probably not going to happen. You don't even say which Arduino board.
The way that it usually works here is that you make the attempt at writing the code and we help you when you get stuck.
Please read the forum guidelines. to see what we need to be able to help you.
I will not spoil your test this time
I need a modified code of attached code so that I can visualize the sensor data in to TFT LCD. The code is for Analogous sensor with scale mapping & relay operation using threshold
Your topic was MOVED to its current forum category which is more appropriate than the original as it is not an Introductory Tutorial
Ok can you help
Start with examples from whichever library you decide to use for the screen
Hi, @shuvra100
Welcome to the forum.
Can you please tell us your electronics, programming, arduino, hardware experience?
Thanks.. Tom...
Its an attached pics of the TFT Or any other easiest way to get it done. I need to display the data in to that as per the attached code
Thank you. Kindly help if you are clear about my doubts
Did you start with the examples as mentioned in post #9 by @UKHeliBob?
Yes. But can not able to aligned it with my existing code that has been provided
# Getting Started with the Arduino TFT Screen
This would be a good start. As to integrating the code with what you have here is how it works. You write your code and post your code using code tags as is covered in how to use this forum. I doubt anyone here will do this for you. Once you post your code which you write then you will get suggestions as to corrections but you must put forth the effort. Its not difficult but the work is about you learning.
Ron
What have you managed to print using the examples ?
What is it that you want to print in your sketch ?
#include <DFRobot_DHT11.h>
#include <TFT.h>
#include <SPI.h>
#include <Wire.h>
#define cs 10
#define dc 9
#define rst 8
#define DHTPIN 7
#define led 4
#define buz 6
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
DFRobot_DHT11 DHT;
float humidity,temperature;
String temp,hum,soil_moist;
int soil_moisture,SM;
char T[5],H[5],moist[3];
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('%');
}
void setup()
{
TFTscreen.begin();
TFTscreen.background(0, 0, 0);
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", 110, 60);
TFTscreen.stroke(255,255,0);
TFTscreen.text("Moist: ", 0,100);
TFTscreen.text("%", 110, 95);
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);
soil_moisture = analogRead(A1);
SM = map(soil_moisture,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);
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);
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);
delay(200);
}
Tried withthis example
Please guide . Its a request
OK so what happened with the example? The DHT 11 is temperature and humidity so what is your soil moisture sensor. Where did you get that sample code? Does it compile and load OK? What exactly happens?
Ron
'''int analogPin = A3;
int Rawval ; // variable to store the value read
int Scaleval ;
int RELAY_pin = 10; // Relay is connected to pin D10
void setup()
{
Serial.begin(9600); // setup serial
pinMode(RELAY_pin, OUTPUT);
}
void loop()
{
int Rawval = analogRead(analogPin);
Serial.print("Rawvalue from Analog input =");
Serial.print(Rawval);
// For 3V3 input to read 100%, 3V3 of 5V ref = (3.3 / 5) * 1023 = 675
Scaleval = map(Rawval, 0, 675, 0, 20);
Serial.print(" Scaled Value =");
Serial.println(Scaleval);
/// === RELAY code ===
// raw value 675 correspond to 20%, so for 5% we will get 169
if ( Rawval < 169) digitalWrite(RELAY_pin, HIGH);
else digitalWrite(RELAY_pin, LOW);
}
'''
Please