Arduino Temperature sensor and LCD Display

In this post I am going to share with you the circuit diagram, code and how to fix faint display or completely invisible texts on the screen.

Final Product





Components
- Arduino Uno board
- 1 * Breadboard
- 1 * USB data cable (To connect the board to your PC)
- 1 * LM35 Temperature Sensor
- 1 * I2C LCD1602 (QPASS LCD Display)
- Several jumper wires

LM35



For this project you need to add LiquidCrystal Library to your Arduino IDE. In this case I am using V1.07
Download and install by selecting the zip as shown below


















CODE:

// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//

#include


void setup()
{
  Wire.begin();

  Serial.begin(9600);
  Serial.println("\nI2C Scanner");
}


void loop()
{
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16 br="">         Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");

      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknow error at address 0x");
      if (address<16 br="">         Serial.print("0");
      Serial.println(address,HEX);
    } 
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);           // wait 5 seconds for next scan
}
1) You need to get the address of your LCD Display and this code also helps you to confirm that your circuit is okay for the Display.










Note down the returned  address to use in the next case. In my case it is 0x3F

Now execute the code below




/*****************************************
* name:LM35 Temperature Sensor
* function:
* LM35 output voltage has a linear relation with the Celsius temperature, output of 0 v when 0 ℃, 
* every increase 1 ℃, the output voltage increase 10 mv
*****************************************/
//lm35 attach to A0
/****************************************/
#define lmPin A0 //LM35 attach to
#include  
#include
#include
#include

#define I2C_ADDR    0x3F // <<----- add="" address="" code="" find="" from="" here.="" i2c="" it="" nbsp="" scanner="" your="">
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7

int n = 1;

LiquidCrystal_I2C  lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

float tem = 0;
long lmVal = 0; 
void setup()
{
 lcd.begin (16,2); //  <<----- 20x4="" code="" is="" maybe="" yours="">
// Switch on the backlight

lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
lcd.home (); // go home
// lcd.print("SainSmartI2C16x2");  
 //lcd.setCursor (0,1);   
 Serial.begin(9600);
}
void loop()
{
 //  lcd.setBacklight(LOW);    
  lmVal = analogRead(lmPin);//read the value of A0
  tem = (lmVal * 0.0048828125 * 100);//5/1024=0.0048828125;1000/10=100
  lcd.setCursor(2,0);//place the cursor on 5 column,0 row
  lcd.print("Kibuchi Sys.");//print"LM35"
  lcd.setCursor(0,1);//place the cursor on 0 column,1 row
  lcd.print("Temp= ");//print"Tem= "
  lcd.setCursor(5,1);//place the cursor on 5 column,1 row
  lcd.print(tem,2);//print tem
  lcd.print(char(223));//print the unit" ℃ "
  lcd.print("C");
  //lcd.setBacklight(HIGH);  
  delay(300);//delay 300ms
  Serial.print("Temperature:"); 
  Serial.println(tem,HEX); 
  
}


Results





























You may end up showing nothing on the screen but just a blue light.. This is not your problem. Have a closer look and you will see some info from a distance. Now here is the fix.

Behind the display there is a knob called  potentiometer. Rotate this until you get your desired display 





Comments

Popular posts from this blog

Importing a dump file in Oracle 12C

Arduino UNO Sound Sensor