What's new

Help Pahelp po Arduino code

Here's an example Arduino code that displays temperature readings on an LCD screen:

Code:
#include <LiquidCrystal.h> // include the liquid crystal library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

int tempPin = A0; // assign the analog pin A0 to tempPin
float temperature; // variable to store temperature

void setup() {
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD
}

void loop() {
  temperature = analogRead(tempPin); // read the voltage from the temperature sensor
  temperature = temperature * 0.48828125; // convert the voltage reading to Celsius
  lcd.setCursor(0, 1); // move the cursor to the second line of the LCD
  lcd.print(temperature); // display the temperature reading on the second line of the LCD
  lcd.print(" C"); // display the unit of temperature on the second line of the LCD
  delay(1000); // wait for a second before taking another temperature reading
}

Note: This code assumes that you are using a LM35 temperature sensor, which outputs a voltage proportional to the temperature in Celsius. If you are using a different sensor, you may need to adjust the conversion factor in the code.
 
Here's an example Arduino code that displays temperature readings on an LCD screen:

Code:
#include <LiquidCrystal.h> // include the liquid crystal library

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

int tempPin = A0; // assign the analog pin A0 to tempPin
float temperature; // variable to store temperature

void setup() {
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD
}

void loop() {
  temperature = analogRead(tempPin); // read the voltage from the temperature sensor
  temperature = temperature * 0.48828125; // convert the voltage reading to Celsius
  lcd.setCursor(0, 1); // move the cursor to the second line of the LCD
  lcd.print(temperature); // display the temperature reading on the second line of the LCD
  lcd.print(" C"); // display the unit of temperature on the second line of the LCD
  delay(1000); // wait for a second before taking another temperature reading
}

Note: This code assumes that you are using a LM35 temperature sensor, which outputs a voltage proportional to the temperature in Celsius. If you are using a different sensor, you may need to adjust the conversion factor in the code.
Arduino code for displaying temperature in LCD using DHT
 
Arduino code for displaying temperature in LCD using DHT
Here's an example Arduino code that displays temperature readings on an LCD screen using the DHT temperature and humidity sensor:

Code:
#include <LiquidCrystal.h> // include the liquid crystal library
#include <DHT.h> // include the DHT library

#define DHTPIN 2 // assign the DHT sensor pin
#define DHTTYPE DHT11 // set the sensor type

DHT dht(DHTPIN, DHTTYPE); // initialize the sensor

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins

void setup() {
  lcd.begin(16, 2); // set up the LCD's number of columns and rows
  lcd.print("Temperature:"); // display "Temperature:" on the first line of the LCD
  dht.begin(); // start the sensor
}

void loop() {
  float temperature = dht.readTemperature(); // read the temperature from the sensor
  lcd.setCursor(0, 1); // move the cursor to the second line of the LCD
  lcd.print(temperature); // display the temperature reading on the second line of the LCD
  lcd.print(" C"); // display the unit of temperature on the second line of the LCD
  delay(1000); // wait for a second before taking another temperature reading
}

Note: make sure to install the DHT library before uploading the code to your Arduino board. You can install the library by going to "Sketch" -> "Include Library" -> "Manage Libraries" and searching for "DHT". Also, depending on the version of your DHT sensor, you may need to adjust the DHTTYPE in the code.
 
#include <DHT.h>
#include <LiquidCrystal_I2C.h>

#define DHTPIN 2
#define DHTTYPE DHT11
LiquidCrystal_I2C lcd (0x27, 16,2);
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
Serial.begin(9600);
dht.begin();
lcd.init();
lcd.backlight();
}

void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();

if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
lcd.setCursor(0,0);
lcd.print("Humid: ");
lcd.print(h, 0);
lcd.print(" %");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(t, 0);
lcd.print(" C");
lcd.print(" ");
}
//install mo lang yung DHT library then scan mo ano code ng lcd i2c mo tsaka mo modify yang code
 

Similar threads

Back
Top