Help cleaning up data from DHT11 sensor with Arduino

Hello, I am trying to make an application that sends the temperature and humidity of a room via telegram. I have a telegram bot in another node, but I can't seem to get the basics right.
I used this code for getting the values from the DHT11 sensor with Arduino:

#include <DHT.h>

//Constants
#define DHTPIN 2     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11  (AM2302)
// Initialize DHT sensor for normal 16mhz Arduino
DHT dht(DHTPIN, DHTTYPE);

//Variables
int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value

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

String hum1;
String temp1;

void loop()
{
    //Read data and store it to variables hum and temp
    hum = dht.readHumidity();
    temp= dht.readTemperature();
    hum1 = String(hum);
    temp1 = String(temp);
    //Print temp and humidity values to serial monitor
    Serial.print("Humidity: ");
    Serial.print(hum1);
    Serial.print("\n");
    Serial.print(temp1);
    Serial.println(" Celsius");
    Serial.print("\n");
    
    delay(2000); //Delay 2 sec.
}

Then, I set up node-red for reading the values from the computer port I plugged my Arduino, but I don't know which function to write to fix these strings show in the debugger and show only the content of the humidity and the temperature.
The picture attached shows my node and the result in the debugger:
Any help will be welcome. Thanks :slightly_smiling_face:

Take the final serial print out, that is giving you the empty line.
What do you get if you then feed that through a JSON node and look at the result in the debug node?

[Edit] Actually you would be better to change the code so that it sends
{"Humidity": value, "Celcius": value}
then feed that through a JSON node.

1 Like

Thank you very much, simply changing the code sent by the Arduino solve it.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.