I
I
Igor_26982020-06-03 00:51:45
Arduino
Igor_2698, 2020-06-03 00:51:45

Combine two sketches together, how to do it???

First sketch:

#include // Add the necessary libraries
#include
#include "DHT.h"
#define DHTPIN A1 // pin for the signal coming from the sensor

//select the sensor to use
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

//
DHT sensor initialization dht(DHTPIN, DHTTYPE);

byte degree[8] = // encode the degree character
{
B00111,
B00101,
B00111,
B00000,
B00000,
B00000,
B00000,
};
LiquidCrystal_I2C lcd(0x27,20,4); // Set the address and display dimension

void setup() {
lcd.init(); // Initialize lcd
lcd.backlight(); // Turn on the highlight
lcd.createChar(1, degree); // Create character 1

Serial.begin(9600);
dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);

// Display humidity and temperature readings

//Humidity
lcd.setCursor(0, 2); // Set the cursor to the beginning of line 1
lcd. print("Hum = % "); // Display text
lcd.setCursor(7, 2); // Set cursor to character 7
lcd.print(h, 1); // Display humidity value

//Temperature
lcd.setCursor(0, 3); // Set the cursor to the beginning of line 2
lcd. print("Temp = \1C "); // Display text, \1 - degree
sign lcd.setCursor(7, 3); // Set cursor to character 7
lcd.print(t,1); // Display temperature value
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question