Hello all I am new to programming with arduino and everything else, but I have been running this code and i got it to work the first time and now I dont know why it wont work.
Also while attempting to add a rtc I do not know how to do it. I am using a sainsmart tiny RTC ds1307. And for the weather project i am using a 16x2 lcd, dht11 sensor, and a arduino uno.
It says stuff like "dht11 does not name a type", or "RTC was not declared in this scope". Not sure what to do.
Heres the code:
#include <dht.h>
#include <Wire.h>
#include <LiquidCrystal.h>
#include <Time.h>
#include <RTClib.h>
const char* Mon[] =
{"Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov" }; //months of the week also in romanian
byte thermometer[8] = //icon for termometer
{
B00100,
B01010,
B01010,
B01110,
B01110,
B11111,
B11111,
B01110
};
byte drop[8] = //icon for water droplet
{
B00100,
B00100,
B01010,
B01010,
B10001,
B10001,
B10001,
B01110,
};
/*-----( Declare objects )-----*/
// Set the pins on the I2C chip used for LCD connections:
// addr, en,rw,rs,d4,d5,d6,d7,bl,blpol
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
// Set the LCD I2C address
dht11 DHT11;
/*-----( Declare Constants, Pin Numbers )-----*/
#define DHT11PIN 2 //dht11 signal pin connected to D2
void setup() /*----( SETUP: RUNS ONCE )----*/
{
Wire.begin();
lcd.begin(16,2); // initialize the lcd for 16 chars 2 lines, turn on backlight
//lcd.backlight();
lcd.clear();
lcd.createChar(1,thermometer);
lcd.createChar(2,drop);
// part code from http://tronixstuff.wordpress.com/
Wire.beginTransmission(0x68);
Wire.write(0x07); // move pointer to SQW address
Wire.write(0x10); // sends 0x10 (hex) 00010000 (binary) to control register - turns on square wave
Wire.endTransmission();
// end part code from http://tronixstuff.wordpress.com/
setSyncProvider(RTC.get);
}/*--(end setup )---*/
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
temp_check(); //displaying temperature
date_time(); //displaying date and time
}
void temp_check()
{
int chk = DHT11.read(DHT11PIN);
lcd.setCursor(0, 1);
lcd.write(1);
lcd.write(" ");
lcd.print((float)DHT11.temperature*1.8+32, 0);
lcd.print((char)223); //degree sign
lcd.print("F");
lcd.print(" ");
lcd.setCursor(9, 1);
lcd.write(2);
lcd.setCursor(11, 1);
lcd.print((float)DHT11.humidity, 0);
lcd.print("%");
delay(2000);
}
void date_time()
{
tmElements_t tm;
(RTC.read(tm));
lcd.setCursor(0, 0);
addzero(tm.Hour);
lcd.print(":");
addzero(tm.Minute);
lcd.setCursor(7,0);
lcd.print(tm.Month[Mon]);
lcd.print(" ");
addzero(tm.Day);
lcd.print("-");
lcd.print(tmYearToCalendar(tm.Year)-2000);
}
void addzero(int number) { //this adds a 0 before single digit numbers
if (number >= 0 && number < 10) {
lcd.write('0');
}
lcd.print(number);
}
moderator: added code tags == # button above smileys. (please use them)