per·se·ver·ance (n)
Steadfastness in doing something despite difficulty or delay in achieving success.

Showing posts with label Microprocessor. Show all posts
Showing posts with label Microprocessor. Show all posts



In this post, I will discuss a little background on what Humidity is and how a DHT11 sensor measures Humidity. After that, I’ll show you how to connect the DHT11 to the Arduino and give you some example code so you can use the DHT11 in your own projects.



THE DHT11 SENSOR:




The DHT11 is a digital sensor that lets you easily get relative humidity and temperature readings in your projects. 



DHT11 Technical Specifications:
- Humidity Range: 20-90% RH
- Humidity Accuracy: ±5% RH
- Temperature Range: 0-50 °C
- Temperature Accuracy: ±2% °C
- Operating Voltage: 3V to 5.5V


WHAT IS RELATIVE HUMIDITY?


The DHT11 humidity and temperature sensor measures relative humidity (RH) and temperature. Relative humidity is the ratio of water vapor in air vs. the saturation point of water vapor in air. The saturation point of water vapor in air changes with temperature. Cold air can hold less water vapor before it is saturated, and hot air can hold more water vapor before it is saturated. The formula for relative humidity is as follows:
Relative Humidity = (density of water vapor / density of water vapor at saturation) x 100%
Basically, relative humidity is the amount of water in the air compared to the amount of water that air can hold before condensation occurs. It’s expressed as a percentage.  For example, at 100% RH condensation (or rain) occurs, and at 0% RH, the air is completely dry.




The DHT11 calculates relative humidity by measuring the electrical resistance between two electrodes. The humidity sensing component of the DHT11 is a moisture holding substrate (usually a salt or conductive plastic polymer) with the electrodes applied to the surface. When water vapor is absorbed by the substrate, ions are released by the substrate which increases the conductivity between the electrodes. The change in resistance between the two electrodes is proportional to the relative humidity. Higher relative humidity decreases the resistance between the electrodes while lower relative humidity increases the resistance between the electrodes.

The temperature readings from the DHT11 come from a surface mounted NTC temperature sensor (thermistor) built into the unit. To learn more about thermistors and how to use them on the Arduino, check out our Arduino Thermistor Temperature Sensor Tutorial.



There are two different variations of the DHT11 sensor you might come across. One type has four pins, and the other type is mounted to a small PCB that has three pins. The PCB mounted version with three pins is nice since it includes a surface mounted 10K Ohm pull up resistor for the signal line:




1.Install the DHT Library:
Go to 'SKETCH' >> 'Include Library' >> 'Add Library' >> Select DHTLib.zip file.
NOTE: Restart the Arduino IDE in order for you to see the DHTLib in the installed list of library. 

2. Upload the sample program below to Arduino and open the serial monitor.

#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);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  delay(1000);
}



Files needed:
HumiditySensor.pdf
DHTLib.zip







DISPLAYING CUSTOM CHARACTERS ON LCD USING PIC16F877A 



Reference: https://electrosome.com/custom-characters-lcd-pic-mikroc/

NOTE: Please go through the tutorial on Interfacing Character LCD with PIC Microcontroller – MicroC Pro.



     Let us first discuss some of the basic concepts and terminologies that we are going to use in displaying custom characters on our 16x2 LCD. Basically, the LCD is consist of 3 memory blocks called CGROM, DDRAM, and CGRAM.


Character Generation ROM (CGROM)
       This is the memory which holds the 5×8 or the 5×10 dot patterns of predefined characters in the LCD. It can create 208 5x8 character dot patterns and 32 5x10 character dot patterns.





















Display Data RAM (DDRAM)
        Just like our personal computers, the LCD also has a RAM and it is called DDRAM. This is the memory which holds the character data which is currently displayed on the LCD. Its capacity is 80x8 bits.

Character Generation RAM (CGRAM)
        This memory works similar to CGROM as this is a RAM we can modify its data anytime. We can store our custom character patterns in this memory through program. We can store up to eight 5x8 character dot patterns and four 5x10 character dot patterns in this memory.

The starting address of the CGRAM is from 00-07.



Creating your own Custom Characters



  1. On your Microsoft Excel software create a 5x8 box just like the picture above. That will serve as our 5x8 dot pattern as seen on our LCD. 
  2. To create your custom character, just fill the box that will satisfy your design.
  3. The shaded boxes are labeled 1 and the unshaded boxes are labeled as 0. Since we are processing 8 bits of data, the first column of boxes serves as our higher bit data and the remaining column of boxes is our lower bit data.
  4. On our example above, just convert the binary form of data into decimal.

MODIFIED CODE:


// LCD module connections
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
// End LCD module connections

const char character0[] = {0,0,10,31,31,14,4,0};
const char character1[] = {14,27,17,17,17,17,31,0};
const char character2[] = {14,27,17,17,17,31,31,0};
const char character3[] = {14,27,17,17,31,31,31,0};
const char character4[] = {14,27,17,31,31,31,31,0};
const char character5[] = {14,31,31,31,31,31,31,0};
const char character6[] = {0,4,2,31,2,4,0,0};
const char character7[] = {0,0,14,17,17,10,27,0};

void CustomChar0() {
  char i;
  Lcd_Cmd(64);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character0[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar1() {
  char i;
  Lcd_Cmd(72);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character1[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar2() {
  char i;
  Lcd_Cmd(80);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character2[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar3() {
  char i;
  Lcd_Cmd(88);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character3[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar4() {
  char i;
  Lcd_Cmd(96);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character4[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar5() {
  char i;
  Lcd_Cmd(104);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character5[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar6() {
  char i;
  Lcd_Cmd(112);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character6[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void CustomChar7() {
  char i;
  Lcd_Cmd(120);
  for (i = 0; i<=7; i++) Lcd_Chr_CP(character7[i]);
  Lcd_Cmd(_LCD_RETURN_HOME);
}

void main()  {
  Lcd_Init(); // Initialize LCD

  Lcd_Cmd(_LCD_CLEAR); // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

  //Send Custom Charactors to CGRAM
  CustomChar0();
  CustomChar1();
  CustomChar2();
  CustomChar3();
  CustomChar4();
  CustomChar5();
  CustomChar6();
  CustomChar7();
  //End

  //Display Custom Characters
  Lcd_Chr(1,1,0);
  Delay_ms(1000);
  Lcd_Chr(1,2,1);
  Delay_ms(1000);
  Lcd_Chr(1,3,2);
  Delay_ms(1000);
  Lcd_Chr(1,4,3);
  Delay_ms(1000);
  Lcd_Chr(1,5,4);
  Delay_ms(1000);
  Lcd_Chr(1,6,5);
  Delay_ms(1000);
  Lcd_Chr(1,7,6);
  Delay_ms(1000);
  Lcd_Chr(1,8,7);
  Delay_ms(1000);
}
NOTE: Some of the syntax of the code might not build on your project because of the version of MikroC programmer you are using. Just go to the Help and go to the LCD Library of your MikroC programmer to check the right syntax of your program. It is also nice to drop some of your questions on the comment section below.











author
John Aldrin T. Mantes
Hi! Welcome to my Blog. This blog is part of our requirement in our Educational Technology class. The content of the blog is comprise of the discussions during the Observation and Participation class. Feel free to ask questions on the comment section. Have a great Day.