I'm trying to connect DHT11 and BMP085 along with a DC motor and a button to display on the LCD screen a few things: temperature, humidity, altitude, dew point, e.t.c.
This is my code below. However I am getting 5 errors.
-
"e BMP temperature" = e does not name a type
-
under void setup(), "DHT.11attach(DHT11PIN);" = 'class dht11' has no member named 'attach'
-
under void loop(), "lcd.print(DHT11.dewPoint());" = 'class dht11' has no member named 'dewPoint'
-
125: error: 'ac1' was not declared in this scope
-
242: error: 'ac1' was not declared in this scope
So these are the 5 errors that I am getting that I can't seem to fix until i comment it out. if i comment it out well then the program doesn't work... Can someone help me with this?
// include the library codes:
#include <LiquidCrystal.h>
#include <Wire.h>
#include <dht11.h>
#include <Versalino.h>
// initialize the LCD with interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
// initialize start variables
int TempF;
int TempC;
int ADCvalue;
dht11 DHT11;
#define DHT11PIN 9
#define BMP_ADDRESS = 0x77
//These are are initialized globally, since the BMP085 pressure calculations require certain variables to have been calculated from t
e BMP temperature
int ac1;
int ac2;
int ac3;
unsigned int ac4;
unsigned int ac5;
unsigned int ac6;
int b1;
int b2;
int mb;
int mc;
int md;
long b5;
const unsigned char OSS = 0;
float atm;
float pressure;
int chk;
int fanPin = A0;
int fanValue = 0;
void setup() {
//attach the DHT11 sensor to a pin
DHT11.attach(DHT11PIN);
//increase ADC resolution by only reading 0V - 1.1V
analogReference(INTERNAL);
// Initialize LCD columns and rows
lcd.begin(20, 4);
//Allow for serial communications at 9600 bits/s
Serial.begin(9600);
//Initialize communications using the Wire library
Wire.begin();
}
void loop() {
lcd.setCursor(0,0);
//output humidity
lcd.print("Humidity (%):");
lcd.print(DHT11.humidity);
//delay 1 sec and clear screen
delay(1000);
lcd.clear();
//output dew point
lcd.print("Dew point (C):");
lcd.print(DHT11.dewPoint());
//delay 1 sec and clear screen
delay(1000);
lcd.clear() ;
//calibrate the BMP085 sensor
bmpCalibrate();
//Output temperature from BMP in ºC
lcd.print("Temp (C): ");
lcd.print(bmpGetTemp(bmpReadUT()));
//delay 1 sec and clear screen
delay(1000);
lcd.clear();
//Output pressure in atm
lcd.print("Pressure (atm): ");
pressure = bmpGetPressure(bmpReadUP());
atm = pressure / 101325;
lcd.print(atm);
//delay 1 sec and clear screen
delay(1000);
lcd.clear();
atm = pressure / 101325;
//Output altitude in feet
lcd.print("Altitude: ");
lcd.print(getAltitude(pressure)*3.1);
//delay 1 sec and clear screen
delay(1000);
lcd.clear();
//reads the voltage from the electric motor
fanValue = analogRead(fanPin);
//maps the voltage from the motor to return 1 if the voltage is
//above 400mV
fanValue = map(fanValue, 0, 800,0, 1);
//outputs either high or low for wind speed based on the
//mapped voltage value
lcd.print("Wind speed: ");
if (fanValue == 1){
lcd.print("HIGH");
}
else{
lcd.print("LOW");
}
//delay 1 sec and clear screen
delay(1000);
lcd.clear();
//Restart the loop
}
//a method to calculate pressure from the BMP
float bmpGetPressure(unsigned long up){
//Calulations to find pressure are derived from the BMP085 datasheet
long x1, x2, x3, b3, b6, p;
unsigned long b4, b7;
b6 = b5 - 4000;
// Calculate B3
x1 = (b2 * (b6 * b6)>>12)>>11;
x2 = (ac2 * b6)>>11;
x3 = x1 + x2;
b3 = (((((long)ac1)*4 + x3)<<OSS) + 2)>>2;
// Calculate B4
x1 = (ac3 * b6)>>13;
x2 = (b1 * ((b6 * b6)>>12))>>16;
x3 = ((x1 + x2) + 2)>>2;
b4 = (ac4 * (unsigned long)(x3 + 32768))>>15;
b7 = ((unsigned long)(up - b3) * (50000>>OSS));
if (b7 < 0x80000000)
p = (b7<<1)/b4;
else
p = (b7/b4)<<1;
x1 = (p>>8) * (p>>8);
x1 = (x1 * 3038)>>16;
x2 = (-7357 * p)>>16;
p += (x1 + x2 + 3791)>>4;
long temp = p;
return temp;
}
//a method to return the dew point from the DHT11
//takes temp and humidity as parameters
double getDewPoint(double celsius, double humidity)
{
//Equation is taken from NOAA dew point equation
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}
//calculates altitude based on the barometric pressure
//from the BMP085. Requires pressure in pascal(Pa)
float getAltitude(float pressure){
float A = pressure/101325;
float B = 1/5.25588;
float C = pow(A,B);
C = 1 - C;
C = C /0.0000225577;
return C;
}
//gets temp from BMP085
float bmpGetTemp(unsigned int ut){
//Equations from the BMP085 datasheet
long x1;
long x2;
x1 = (((long)ut-(long)ac6)*(long)ac5)>>15;
x2 = ((long)mc<<11)/(x1+md);
b5 = x1 + x2;
float temp = ((b5+8)>>4);
temp = temp / 10;
return temp;
}
//communicates with BMP sensor using the wire function
//Returns the value located at 0xF6 needed for the temperature
//Calculations
unsigned long bmpReadUT(){
unsigned int ut;
Wire.beginTransmission(0x77);
Wire.write(0xF4);
Wire.write(0x2E);
Wire.endTransmission();
delay(5);
ut = bmpReadInt(0xF6);
return ut;
}
//communicates with BMP sensor using the wire function
//Writes several values to the BMP085 and waits for response
//Used the msb,lsb and xlsb to return the value needed to
//Calculate pressure
unsigned long bmpReadUP(){
unsigned char msb, lsb, xlsb;
unsigned long up = 0;
Wire.beginTransmission(0x77);
Wire.write(0xF4);
Wire.write(0x34 + (OSS<<6));
Wire.endTransmission();
delay(2+(3<<OSS));
Wire.beginTransmission(0x77);
Wire.write(0xF6);
Wire.endTransmission();
Wire.requestFrom(0x77, 3);
// Wait for data to become available
while(Wire.available() < 3)
;
//establish most and least significant bits
msb = Wire.read();
lsb = Wire.read();
xlsb = Wire.read();
up = (((unsigned long) msb << 16) | ((unsigned long) lsb << 8) | (unsigned long) xlsb) >> (8-OSS);
return up;
}
//calibrates the BMP085 with known data values
void bmpCalibrate(){
ac1 = bmpReadInt(0xAA);
ac2 = bmpReadInt(0xAC);
ac3 = bmpReadInt(0xAE);
ac4 = bmpReadInt(0xB0);
ac5 = bmpReadInt(0xB2);
ac6 = bmpReadInt(0xB4);
b1 = bmpReadInt(0xB6);
b2 = bmpReadInt(0xB8);
mb = bmpReadInt(0xBA);
mc = bmpReadInt(0xBC);
md = bmpReadInt(0xBE);
}
//reads the bits from the BMP085
int bmpReadInt(unsigned char address){
unsigned char msb;
unsigned char lsb;
Wire.beginTransmission(0x77);
Wire.write(address);
Wire.endTransmission();
Wire.requestFrom(0x77,2);
while(Wire.available()<2)
;
msb = Wire.read();
lsb = Wire.read();
return (int) msb<<8 | lsb;
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Proyecto.ino (6.08 KB)