So im Currently Programming a weather station using the arduino uno..But im getting a very annoying error which i cannot figure out.The error in question is
C:\Program Files (x86)\Arduino/Weatherstation.ino:127: undefined reference to `dht11::read(int)'
I have had so much trouble with this code from the beginning but this is hopefully the last error i will face.I need a response ASAP as this is a school project and needs to be completed pretty soon.I have attached the code im using,
Thanks in advance,
Oliver Ferris.
Inputs : DHT11
LDR
10K Potentiometer (Lcd contrast control)
Push Switch (Change info displayed)
Outputs: LCD 2x16
#include <dht11.h>
#include <LiquidCrystal.h>
//initialize DHT11
dht11 DHT11;
// initialize the LCD library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//pin declaration
int lightPin = A0;
int dhtPin = A1;
int buttonPin = 7;
unsigned long cur = 0;
unsigned long measurementFrequency = 1000;
unsigned long lastMeasurement = 0;
int measurementValue = 0;
int lastButtonState = LOW;
unsigned long lastDebounce = 0;
unsigned long buttonDebounceDelay = 250;
int currMode = 0;
boolean modeChanged = false;
boolean isPing = false;
unsigned long lastPing = 0;
unsigned long pingDelay = 250;
void setup() {
//debug
//Serial.begin(9600);
//setup LCD
lcd.begin(16,2);
//print welcome text
lcd.setCursor(3,0);
lcd.print("Welcome to");
lcd.setCursor(2,1);
lcd.print("Olivers Weather Station!");
delay(3000);
lcd.clear();
}
void loop() {
//record current time in milliseconds
cur = millis();
//see if we need to measure
if ((cur - lastMeasurement > measurementFrequency) || modeChanged) {
//control members
lastMeasurement = cur;
lastPing = cur;
modeChanged = false;
//do the work
measureAndDisplay();
//make the ping (blink an asterisk)
ping();
}
//check if blinking
if (isPing && cur - lastPing > pingDelay) pong();
//monitor if button pressed
int currentButtonState = digitalRead(buttonPin);
if ((currentButtonState != lastButtonState) && (currentButtonState == HIGH) && (cur - lastDebounce > buttonDebounceDelay)) {
lastDebounce = cur;
if (currMode == 2) currMode = 0;
else currMode = currMode + 1;
modeChanged = true;
}
//debug
//Serial.println(currentButtonState);
}
void measureAndDisplay() {
//clear the display
lcd.clear();
switch (currMode) {
//0: temperature - read DHT11.temperature and write it out
case 0:
DHT11.read(dhtPin);
measurementValue = DHT11.temperature;
lcd.setCursor(2,0);
lcd.print("Temperature:");
lcd.setCursor(2,1);
lcd.print(measurementValue);
lcd.print(char(223));
lcd.print("C - ");
int toFarenheit;
toFarenheit = (measurementValue * 1.8 + 32); //for our American friends
lcd.print(toFarenheit);
lcd.print(char(223));
lcd.print("F");
break;
case 1:
//1: humidity - read DHT11.humidity and write it out in %
measurementValue = DHT11.humidity;
lcd.setCursor(4,0);
lcd.print("Humidity");
lcd.setCursor(7,1);
lcd.print(measurementValue);
lcd.print("%");
break;
case 2:
//2: light intensity - read the light sensor and output the value in %.
//This can be converted into Lux, but I believe this setup is not precise enough.
measurementValue = analogRead(lightPin);
measurementValue = map(measurementValue, 0, 1023, 100, 0);
lcd.setCursor(0,0);
lcd.print("Light Intensity");
lcd.setCursor(7,1);
lcd.print(measurementValue);
lcd.print("%");
break;
}
}
//show asterisk
void ping() {
lcd.setCursor(15,1);
lcd.print("*");
isPing = true;
//debug
//Serial.println("Ping");
}
//clear asterisk
void pong() {
lcd.setCursor(15,1);
lcd.print(" ");
isPing = false;
//debug
//Serial.println("Pong");
}