This is my first post, and ill make it clear i am new to both electronics and coding.
I have a UNO board and a Ebay special LCD screen
I2C Address: 0x27
Backlight (White character on Blue background)
Supply voltage: 5V
Size: 82x35x18 mm
Come with IIC interface, which can be connected by DuPont Line
Package Include
1 X IIC/I2C/TWI 1602 Serial LCD Module
and the wired version of a DHT 22 sensor
So....
I downloaded the library "New Liquid Crystal" from https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads (Downloaded repository and installed in the /documents/arduino/library folder. I then cut the original Liquid Crystal library out of the arduino directory and moved it elswhere.
I also downloaded the DHT library from Adafruit and installed in the same way.
I mashed the example code for I2C Hello world and the DHT sensor together and uploaded it. Everything worked fine except for some flakey bread board connections.
I then worked on something else for a while. When i tried to reupload the same code, it would not compile.
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#include <Wire.h>
#define BACKLIGHT_PIN 13
#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTPIN 2 // what digital pin we're connected to
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27); // Set the LCD I2C address
void setup() /*----( SETUP: RUNS ONCE )----*/
{
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
lcd.begin(16,2); // initialize the lcd for 20 chars 4 lines, turn on backlight
lcd.backlight();
dht.begin();
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
}
lcd.setCursor(0,0);
lcd.print("Temp ");
lcd.print(t);
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity ");
lcd.print(h);
lcd.print("%");
delay(2000);
}/* --(end main loop )-- */
Arduino: 1.6.7 (Windows 7), Board: "Arduino/Genuino Uno"
DHT22_LCDdisplay:38: error: 'lcd' does not name a type
lcd.setCursor(0,0);
^
DHT22_LCDdisplay:40: error: 'lcd' does not name a type
lcd.print("Temp ");
^
DHT22_LCDdisplay:41: error: 'lcd' does not name a type
lcd.print(t);
^
DHT22_LCDdisplay:42: error: 'lcd' does not name a type
lcd.print((char)223);
^
DHT22_LCDdisplay:43: error: 'lcd' does not name a type
lcd.print("C");
^
DHT22_LCDdisplay:46: error: 'lcd' does not name a type
lcd.setCursor(0,1);
^
DHT22_LCDdisplay:47: error: 'lcd' does not name a type
lcd.print("Humidity ");
^
DHT22_LCDdisplay:48: error: 'lcd' does not name a type
lcd.print(h);
^
DHT22_LCDdisplay:49: error: 'lcd' does not name a type
lcd.print("%");
^
DHT22_LCDdisplay:52: error: expected constructor, destructor, or type conversion before '(' token
delay(2000);
^
DHT22_LCDdisplay:53: error: expected declaration before '}' token
}/* --(end main loop )-- */
^
exit status 1
'lcd' does not name a type
This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
The errors with the DHT parts are not realy the issue, its the "error: 'lcd' does not name a type" instances that have me baffled.
I have tried google for a couple of hours and have to say im more confused than when i started.
When i made a new sketch in exactly the same way as the first time, it compiled no problem.
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define BACKLIGHT_PIN 13
#define DHTTYPE DHT21 // DHT 21 (AM2301)
#define DHTPIN 2 // what digital pin we're connected to
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27); // Set the LCD I2C address
void setup()
{
// Switch on the backlight
pinMode ( BACKLIGHT_PIN, OUTPUT );
digitalWrite ( BACKLIGHT_PIN, HIGH );
lcd.begin(16,2); // initialize the lcd
dht.begin(); // intitalise DHT sensor
lcd.home (); // go home
lcd.print("DHT22 Sensor");
lcd.setCursor ( 0, 1 ); // go to the start of next line
lcd.print ("Temp/Humidity");
delay ( 1000 );
}
void loop()
{
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
lcd.setCursor(0,0); //lcd start of first line
lcd.print("Temp ");
lcd.print(t); //lcd display temperature value
lcd.print((char)223); //degree symbol(°)
lcd.print("C");
lcd.setCursor(0,1); //lcd start of second line
lcd.print("Humidity ");
lcd.print(h); //lcd display humidity value
lcd.print("%");
delay (200); //delay between reads
}
Sketch uses 7,164 bytes (22%) of program storage space. Maximum is 32,256 bytes.
Global variables use 356 bytes (17%) of dynamic memory, leaving 1,692 bytes for local variables. Maximum is 2,048 bytes.
Im at a loss as to what ive done??
Thanks in advance for any help i receive, playing with this stuff would be impossible for someone like me without the vast amount of knowledge freely given here.