Temperature Control of Peltier Element #3

Reading Temperature Sensor Data

We were going to use DHT11 for sensing the temperature.
DHT11 is a temperature and humidity sensor, it has a digital output and has a sampling rate of 1 second.


Note that since it has a sampling rate of 1 second, we put a delay greater than 1 s to avoid garbage values.

The connection of DHT11 with Arduino is fairly simple,

DHT11

DHT11 Arduino Pin
Vdd +5v
Data D7
GND GND

Now before running the code we have to add the DHT11 libraries, which can be downloaded from this link :

DHT11 Library

The code to read Temperature data from DHT11 and printing it on serial monitor is:

#include<dht.h> 
dht DHT;
#define DHT11_PIN 7

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  delay(2000);
}

Now that we have verified that our DHT11 sensor is giving us Temperature readings, we will extend the circuit in the previous post.
The previous circuit already consists of LCD and Potentiometer, keeping their connections unchanged the Temperature senor is added on pin D7 as mentioned above to display the current temperature reading on the LCD along with the set temperature.

The extended code is :

#include<dht.h>
#include<LiquidCrystal.h>
dht DHT;
#define DHT11_PIN 7

const int rs = 12, en = 8, d4 = 5, d5 = 4, d6 = 13, d7 = 2;
int temp=0;
int temp1=0;
float potchange=0;
int sensorPin=A0;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() 
{
  	  lcd.begin(16, 2);
          Serial.begin(9600);     
}
void loop()
{

  // Reading Potentiometer
  temp=analogRead(sensorPin);
  potchange=temp;
  temp1=15+(temp/1023.0)*41.0;
  
  // For Reading DHT11
  int chk = DHT.read11(DHT11_PIN);
  
  // Printing on LCD
  lcd.setCursor(0, 0);
  lcd.print("Set Temp: ");
  lcd.setCursor(10, 0);
  lcd.print(temp1);
  lcd.setCursor(13, 0);
  lcd.print("C"); 
  lcd.setCursor(0,1);
  lcd.print("Actual Temp:");
  lcd.print((int)DHT.temperature);
  lcd.setCursor(15,1);
  lcd.print("C");
 
 // Printing on Serial Monitor
  Serial.print("Set Temperature = ");
  Serial.println(temp1);
  Serial.print("Current Temperature = ");
  Serial.println(DHT.temperature);
  
  delay(2000);
}

The above codes can be accessed and downloaded from these github links :

Displaying DHT11 data on serial monitor

and

Combined Code for Potentiometer Readings,DHT11 Readings and LCD

 

0

1 thought on “Temperature Control of Peltier Element #3”

Leave a Reply