0% found this document useful (0 votes)
1 views8 pages

Arduino Code

The document contains Arduino code for a weather monitoring system using a DHT11 sensor and an LCD display. It initializes the sensor and LCD, reads temperature and humidity data, and displays it on the LCD while also logging the data to an SD card. The code includes error handling for sensor readings and SD card initialization.

Uploaded by

johnsonmydavid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views8 pages

Arduino Code

The document contains Arduino code for a weather monitoring system using a DHT11 sensor and an LCD display. It initializes the sensor and LCD, reads temperature and humidity data, and displays it on the LCD while also logging the data to an SD card. The code includes error handling for sensor readings and SD card initialization.

Uploaded by

johnsonmydavid
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

// include the library code:

#include <LiquidCrystal.h>

// initialize the library with the numbers of the


interface pins
LiquidCrystal lcd(19, 23, 18, 17, 16, 15);

void setup() {
// set up the LCD's number of columns and rows:
[Link](16, 2);
// Print a message to the LCD.
[Link]("circuitschools.");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting
begins with 0):
[Link](0, 1);
// print the number of seconds since reset:
[Link](millis() / 1000);
}
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 4
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

// Change 0x27 to 0x3F if your LCD does not display


LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
[Link](115200);

[Link]();

[Link]();
[Link]();

[Link](0, 0);
[Link]("Weather System");
[Link](0, 1);
[Link]("Starting...");
delay(2000);
[Link]();
}

void loop()
{
float humidity = [Link]();
float temperature = [Link]();

if (isnan(humidity) || isnan(temperature))
{
[Link]();
[Link](0, 0);
[Link]("Sensor Error");

[Link]("Failed to read DHT11");


delay(2000);
return;
}

// Display on LCD
[Link]();

[Link](0, 0);
[Link]("T:");
[Link](temperature);
[Link]((char)223); // Degree symbol
[Link]("C");

[Link](0, 1);
[Link]("H:");
[Link](humidity);
[Link]("%");

// Display on Serial Monitor


[Link]("Temperature: ");
[Link](temperature);
[Link](" C ");

[Link]("Humidity: ");
[Link](humidity);
[Link](" %");

delay(2000);
}
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>

#define DHTPIN 4
#define DHTTYPE DHT11

DHT dht(DHTPIN, DHTTYPE);

LiquidCrystal_I2C lcd(0x27, 16, 2);

Const int chipSelect = 5;

Void setup()
{
[Link](115200);

[Link]();

[Link]();
[Link]();

If (![Link](chipSelect))
{
[Link](“SD Card Failed”);
[Link](0,0);
[Link](“SD Failed”);
}
Else
{
[Link](“SD Card Ready”);
}
}

Void loop()
{
Float humidity = [Link]();
Float temperature = [Link]();

If (isnan(humidity) || isnan(temperature))
{
[Link](“Sensor Error”);
Return;
}

[Link]();

[Link](0,0);
[Link](“Temp:”);
[Link](temperature);
[Link](“ C”);

[Link](0,1);
[Link](“Hum:”);
[Link](humidity);
[Link](“%”);

File dataFile = [Link](“/[Link]”, FILE_APPEND);

If (dataFile)
{
[Link](“Temperature: “);
[Link](temperature);
[Link](“ C “);

[Link](“Humidity: “);
[Link](humidity);
[Link](“%”);

[Link]();
}

Delay(2000);
}

You might also like