#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>
#include <Wire.h>
#include <hd44780.h> // main hd44780 header
#include <hd44780ioClass/hd44780_I2Cexp.h> // i2c expander i/o class header
const char SSID[] = "XXXX"; // Replace with your network SSID (WiFi name)
const char PASS[] = "XXXX"; // Replace with your network password
void onLED1D2Change();
bool lED1D2;
CloudTemperatureSensor t1; // Cloud variable for the first temperature sensor
CloudTemperatureSensor t2; // Cloud variable for the second temperature sensor
// Define the analog pins for the LM35 sensors
const int LM35Pin1 = A0;
const int LM35Pin2 = A1;
// Timing variables
unsigned long previousMillis = 0;
const long interval = 60000; // Interval at which to read temperatures (milliseconds)
// Initialize the LCD (hd44780_I2Cexp object)
hd44780_I2Cexp lcd;
void initProperties() {
ArduinoCloud.addProperty(lED1D2, READWRITE, ON_CHANGE, onLED1D2Change);
ArduinoCloud.addProperty(t1, READ, 60 * 1000); // Update every minute
ArduinoCloud.addProperty(t2, READ, 60 * 1000); // Update every minute
}
WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
void setup() {
// Initialize serial and wait for port to open
Serial.begin(9600);
delay(1500);
// Initialize cloud properties
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// Set debug message level
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// Initialize pin 2 as an output
pinMode(2, OUTPUT);
// Initialize the LCD
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.backlight(); // Turn on the backlight
// Print initial debug information
Serial.println("Setup complete. Beginning loop...");
}
void loop() {
ArduinoCloud.update();
// Check if the interval time has passed
unsigned long currentMillis = millis(); // Get the current time
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis; // Update the last time temperatures were read
// Read temperatures from the LM35 sensors
float temperature1 = readTemperature(LM35Pin1); // Read temperature from the first sensor
float temperature2 = readTemperature(LM35Pin2); // Read temperature from the second sensor
// Print temperature readings to the Serial Monitor for debugging
Serial.print("Temperature 1: ");
Serial.println(temperature1);
Serial.print("Temperature 2: ");
Serial.println(temperature2);
// Explicitly update cloud variables
ArduinoCloud.update();
// Debugging cloud sync
Serial.print("Updated Cloud t1: ");
Serial.println(t1);
Serial.print("Updated Cloud t2: ");
Serial.println(t2);
// Update the LCD display
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Temp1: ");
lcd.print(temperature1);
lcd.print(" C");
lcd.setCursor(0, 1);
lcd.print("Temp2: ");
lcd.print(temperature2);
lcd.print(" C");
// Update the cloud variables
t1 = temperature1;
t2 = temperature2;
}
}
// Function to read temperature from an LM35 sensor
float readTemperature(int pin) {
int reading = analogRead(pin); // Read the analog value from the specified pin
float voltage = reading * (5.0 / 1023.0); // Convert the analog value to a voltage
float temperatureC = voltage * 100.0; // Convert the voltage to temperature in Celsius
return temperatureC; // Return the temperature
}
// Function to handle changes in the lED1D2 variable
void onLED1D2Change() {
// Write to pin 2 based on the lED1D2 value from the cloud
digitalWrite(2, lED1D2 ? HIGH : LOW);
}
void ont1Change() {
Serial.println("t1 changed on the cloud");
}
void ont2Change() {
Serial.println("t2 changed on the cloud");
}
''
I updated my sketch to arduino r4 wifi The temperature can show on LCD and Serial monitor but show 0.00 in my dashboard Can anyone help me. Please.