I am new to the world of Arduino but absolutly love the concept of it
I got a Sensor Kit and Uno from ebay which contained a DHT11, LM35 and LCD 16,2.
I downloaded some sample code for a similar kit with the additions of light & Tilt and adapted that code as far as i could, I have got the values displayed on the LCD but they are not refreshing.
I have had a good read of many forum posts but cant seem to find the solution.
heres the adapted code
/////////////////////////////////////////////
// This demo code uses 4 different sensors and an LCD module
// to demonstrate reading a displaying continuous sensor data.
// Data is read from a mechanical tilt sensor to show FLAT or TILT
// An LDR is used to measure light level and is roughly converted to Lux
// A DHT11 is used to measure Humidity in %RH
// Finally an LM35 is used to measure temperature in degress C
//
// This code may be freely used and copied.
//
// Gareth Davies - June 2012
//
////////////////////////////////////////////////
#include <LiquidCrystal.h>
#include <dht11.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int temp, humidity, hCheck;
#define tempPin 1
#define humidityPin 6
dht11 DHT11;
// initialise LCD library and pins
void setup() {
lcd.begin(16, 2);
pinMode(humidityPin, INPUT);
pinMode(tempPin, INPUT);
}
void loop()
{
temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;
delay(10);
hCheck = DHT11.read(humidityPin);
if(hCheck != 0)
humidity = 255; //Must be an error
else
humidity = DHT11.humidity;
showData(temp, humidity);
delay(1000);
}
void showData (int temp, int humidity)
{
String s1, s2, s3;
String spaces = " ";
s1 = String(temp) + char(0xdf) + "C";
if(humidity == 255)
s2 = "ERROR";
else
s2 = String(humidity) + "%";
s3 = s1 + spaces.substring(0, 16 - s1.length() - s2.length()) + s2;
lcd.setCursor(0,0);
lcd.print(s3);
}
Please accept my humble apologies if this is a daft question / post
Edit: After playing a little more i added some serial commands and ran project again - Interestingly the programme only looped twice i.e. only displayed via serial temp, humidity values twice.
I think it is legal to have "global" variables temp and humidity and the same
as local variables with the same name in your last function there, but it really isn't a good idea
because it is easy to get confused.
And if you are having them as global variables, they don't need to be parameters to
your function.
And if you are looking for a suggestion on how to proceed with debugging, I suggest
you separate the sensor reading issue from the possible issue of the lcd object misbehaving.
There is no obvious infinite loop in this code, so the fault might be elsewhere.
step 1: try reading the sensor and sending the output to your pc by serial link. This will
check the sensor code works.
step 2: write another sketch which just tests the lcd object.
Looked at creating an array but I would have to understand this a bit more, so I followed "michinyon" advice and tested the sensor part, and it worked, I then removed the string usage and replaced with lcd character placement;
Is this a type of array?
either way it works now: i intend on completing the tutorials so as to get a better understanding of all things Arduino.