In: Computer Science
We need to code an LCD with a temperature and humidity sensor for the arduino UNO board. The LCD should simply display the temperature and humidity reading from the DHT11 sensor. We must do this without the use of arduino or lcd libraries, and only use raw c code. For example we need to use PORTD |= (1<<5); to set the pin to 5. The LCD is connected to pins A0 and A1, and it is using I2C. The temperature sensor is connected to digital pin 5.
I don't think there is a way to use lcd without its library. But I have Impelmented the code with less complexity,hope you like it.
#include <LiquidCrystal.h> #include "DHT.h" // set the DHT Pin #define DHTPIN 5 // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); dht.begin(); // Print a message to the LCD. lcd.print("Temp: Humidity:"); } void loop() { delay(500); // set the cursor to column 0, line 1 // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // read humidity float h = dht.readHumidity(); //read temperature in Fahrenheit float f = dht.readTemperature(true); if (isnan(h) || isnan(f)) { lcd.print("ERROR"); return; } lcd.print(f); lcd.setCursor(7,1); lcd.print(h); }