I am using this sketch to show the temperature from a LM35 sensor. The data or readings is displayed in the serial monitor, but not the 16x2 lcd.
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
float temperature = voltage*100;
// print out the value you read:
Serial.println("Voltage : ");
Serial.println(voltage);
Serial.println("Temperature : ");
Serial.println(temperature);
lcd.setCursor(0,0);
lcd.print("T :");
lcd.print(temperature);
lcd.print((char)223);
lcd.print("C");
delay(500);
}
Please post your sketch, using code tags when you do
Posting your code using code tags prevents parts of it being interpreted as HTML coding and makes it easier to copy for examination
In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.
Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.
No, it's not. As presented in the opening post there is e.g. no setup() function, there is no declaration for the lcd object and probably a lot more that we don't know about.
Ok, fair dos then.
this one also does not show anything on the lcd screen:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.print("LM35 Test");
delay(1000);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
float temperature = voltage*100;
// print out the value you read:
Serial.println("Voltage : ");
Serial.println(voltage);
Serial.println("Temperature : ");
Serial.println(temperature);
lcd.setCursor(0,0);
lcd.print("T :");
lcd.print(temperature);
lcd.print((char)223);
lcd.print("C");
delay(500);
}
I would recommend that you use the currently best available library for the i2c lcd modules which is Bill Perry's hd44780.h. It is available through the library manager.
It will auto configure the i2c address and the pin configuration. There is a comprehensive diagnostic sketch as part of the library if there are any issues. Reference material is here.
Install the library, using the library manager, and this sketch should work with your device. If not, run the diagnostic sketch I2CexpDiag and report the results.
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h> // include i/o class header for i2c expanders
hd44780_I2Cexp lcd; // declare lcd object: auto locate & config display for hd44780 chip
void setup()
{
// initialize LCD with number of columns and rows:
lcd.begin(16,2);
// Print a message to the LCD
lcd.print("Hello, World!");
}
void loop()
{
lcd.setCursor(0, 1);
lcd.print(millis() / 1000);
delay(1000);
}
The wires check out ok thanks. I've just run I2C scanner sketch which should display the address of the I2C lcd, but it can't find the device.. I only bought it yesterday, and it looks like it' faulty