Hello everybody on this forum.
I'm complete newbie on programming arduino and need some help. I would like to connect 3 sensors (2xlm35 1xdht11) to arduino uno and display readings on lcd 16x4 via i2c adapter.
The script to read lm35 I use is:
#include <DHT11.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity
float cel()
{
int pin;
float c;
pin=analogRead(A1);
c = (500.0 * pin)/1023;
return(c);
}
void setup()
{
lcd.begin(16,2);
lcd.print("C= ");
}
void loop()
{
float Celciusze = cel();
lcd.setCursor(2,0);
lcd.print(Celciusze);
delay(1000);
}
The script to read dht11 I use is:
#include <DHT11.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
// Addr, En, Rw, Rs, d4, d5, d6, d7, backlighpin, polarity
int pin = A0;
DHT11 dht11(pin);
double Fahrenheit(double celsius) {
return ((double)(9 / 5) * celsius) + 32;
}
double Kelvin(double celsius) {
return celsius + 273.15;
}
void setup() {
lcd.begin(16, 2);
lcd.backlight();
lcd.clear();
lcd.print("Humidity & temp");
delay(3000);
lcd.clear();
lcd.print("Starting.....");
delay(3000);
}
void loop() {
int err;
float temp, humi;
if ((err = dht11.read(humi, temp)) == 0)
{
lcd.clear();
delay(500);
lcd.setCursor(0, 0);
lcd.print("Temp");
lcd.setCursor(0, 1);
lcd.print("Humidity");
lcd.setCursor(9, 0);
lcd.print(temp);
lcd.print(" C");
lcd.setCursor(9, 1);
lcd.print(humi);
lcd.print(" %");
delay(10000);
}
else
{
lcd.println();
lcd.print("Error No :");
lcd.print(err);
lcd.println();
}
}
Can someone help me to merge this two codes to read this 3 sensors at the same time?
Thanks in advance