I have made a hygrometer using DHT11 which shows it's output in a 2 digit 7 segment display. but i need to add a code which calibrate the dht11 sensor value in this exiting code. please help me to marge this two code in one...
main code
#include <SevenSegmentDisplay.h>
//============================================================================
// Name : TempControl.ino
// Author : Romualdo Dasig
// Version : v0.1
// Copyright : MIT License
// Description : Display temperature to a Seven Segment LED Display
//============================================================================
// Libraries
#include <DHT.h>
// Setup Sensor.
#define DHTPIN 2 // Temperature Sense pin
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE); // Initialize DHT Sensor
// Variables
float hum; // Humidity
float temp; // Temperature
// Variable to store current time.
unsigned long previousMillis = 0;
// Set interval to read temperature.
const long interval = 5000;
// Configure a 2-Digit 7-Segment Display.
int segments[7] = {3, 4, 7, 6, 5, 10, 8}; // Display segments (a,b,c,d,e,f,g)
int displays[2] = {12, 11}; // Display digits (00 - 99)
int type = COMMON_ANODE; // Type
SevenSegmentDisplay sevenSegmentDisplay(
segments[0],
segments[1],
segments[2],
segments[3],
segments[4],
segments[5],
segments[6],
displays[0],
displays[1],
type
);
void setup()
{
Serial.begin(9600);
dht.begin();
sevenSegmentDisplay.begin();
}
void loop()
{
// Get current time in milliseconds.
unsigned long currentMillis = millis();
// Read temperature every 2 seconds.
if (currentMillis - previousMillis >= interval) {
// Save the last time we've read the temperature.
previousMillis = currentMillis;
// Read data and store it to variables hum and temp.
hum = dht.readHumidity();
//temp= dht.readTemperature();
}
// Display temperature.
sevenSegmentDisplay.display(hum);
}
second code of DHT 11 calibration:
//www.youtube.com/c/engineer2you
#include <Wire.h>
//#include <Sodaq_SHT2x.h> //for SHT21 sensor
//-------------------------------BME280
#include <Arduino.h>
//#include <BMx280I2C.h>
//#define I2C_ADDRESS 0x76
//BMx280I2C bmx280(I2C_ADDRESS); //create object I2C Address 0x76
//-------------------------------DHT22
#include <DHT.h>;
#define DHT_PIN 2 // Output of DHT22 to pin 14 Arduino
#define DHT_TYPE DHT11 // DHT22 (AM2302)
DHT dht(DHT_PIN, DHT_TYPE); // Initialize DHT sensor for Arduino 16MHz
//int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
//-------------------------------DHT22
void setup()
{
Wire.begin();
Serial.begin(9600);
dht.begin(); //DHT22
}
//---------------------------------------------------------BMP280
void loop()
//////////////DHT22
{
hum = dht.readHumidity();
//hum = hum - 28;
hum = map(hum,59,65,38,47);
temp= dht.readTemperature();
//temp = temp + 2.8;
Serial.print("--------------------DHT22 Humidity: ");Serial.println(hum);
Serial.print("DHT22 Temp: ");Serial.println(temp);
Serial.println("***");
Serial.println("***");
Serial.println("***");
delay(1000);
}
double map(double x, double in_min, double in_max, double out_min, double out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}