My wiring is as follows:
Arduino 5V and GND to respective + and - rails.
Left pin of the MCP9700 (from flat side) to 5v, middle pin to A0 of arduino, right pin to GND.
Left and right pins of 10k potentiometer respectively at GND and 5v, middle pin to the V0 of LCD.
In the LCD, my VSS is to GND, VDD to 5V, RS to arduino pin 12, R/W to GND, E to arduino pin 11, DB4 to arduino pin 5, DB5 to arduino pin 4, DB6 to arduino pin 3, DB7 to arduino pin 2, LED+ to 220 ohm resistor to 5V, LED- to GND.
The LCD I am using is 16x2, and the temperature is all in celsius.
My code is as follows:
#include <LiquidCrystal.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 =2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
lcd.begin(16, 2); //rows, colums
lcd.print("Temperature Sensor");
}
void loop() {
// put your main code here, to run repeatedly:
int value = analogRead(A0); //read from analogue pin
float voltage = value*(5.0/1024.0); //resolution from 0 to 1023, where 1024 is 5v and 0 is 0v
float temp = (voltage - 0.5) * 100.0; //celsius has voltage offset of 500mV
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(temp);
lcd.print("C");
delay(1000);
}
Originally, I had thought the offset was 400mV, and the temperature displayed on the LCD screen was 37.64 celsius which is way too high. I used an offset of 500mV this time but the temperature on the LCD changed to 27.64 C which is still unusually high for the room temperature.
Also, when I used a fan near the project in order to see if the temperature would go any lower, it instead went up a degree.
Could anyone take a look at this and suggest what might be wrong?