23-03-2019, 22:31
Tak więc , lcd I2C nie wyświetla tego co jest w void loop. Chciałem, aby LCD wyświetlał wilgotność, temperaturę i wilgotność gleby, ale nic nie wyświetla. Z góry dziękuje za pomoc
Kod:
int woda = 8; //You can remove this line, it has no use in the program.
int soilPin = A0;//Declare a variable for the soil moisture sensor
int val; //This variable stores the value received from Soil moisture sensor.
int soilPower = 7;//Variable for Soil moisture Power
#include <dht.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
dht DHT; //Declaring the DHT as a dht type to use it later
#define DHT11_PIN 9//Declaring where the DHT signal pin is wired
void setup() {
pinMode(8, OUTPUT); //Set pin 8 as OUTPUT pin, to send signal to relay
pinMode(0, INPUT); //Set pin 0 as input pin, to receive data from Soil moisture sensor.
pinMode(soilPower, OUTPUT);
digitalWrite(soilPower, LOW);
{
Serial.begin(9600);
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
}
}
void loop() {
}
//This is a function used to get the soil moisture content
int readSoil()
{
digitalWrite(soilPower, HIGH);//turn D7 "On"
delay(10);//wait 10 milliseconds
val = analogRead(soilPin);//Read the SIG value form sensor
digitalWrite(soilPower, LOW);//turn D7 "Off"
return val;//send current moisture value
{
lcd.clear();
lcd.setCursor(0, 0);
int chk = DHT.read11(DHT11_PIN); //Reading data from the module
lcd.print("Tmp:");
lcd.print(DHT.temperature); //Showing temperature value (before that you can do some math to get the temperature in Farnheit)
lcd.print("C");
lcd.setCursor(6, 0);
lcd.print("Wil:");
lcd.println(DHT.humidity); //Showing humidity percentage
lcd.print("%");
lcd.setCursor(6, 1);
lcd.print("Glb:");
lcd.println(DHT.humidity); //Showing humidity percentage
lcd.print("%");
delay(1000);//refreshing every 1s
}
{if (readSoil() > 600) {
Serial.println("wetSoil");
lcd.setCursor(0, 1);
lcd.print("Wilg");
delay(500);
}
else {
lcd.setCursor(0, 1);
lcd.print("Such");
Serial.println("drySoil");
}
Serial.print("Soil Moisture = "); //get soil moisture value from the function below and print it
Serial.println(readSoil());
//This 1 second time frame is used so you can test the sensor and see it change in real-time.
//For in-plant applications, you will want to take readings much less frequently.
delay(1000);//take a reading every second
}
}