# Problem to display serial in data to gauge

**URL:** <https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535>\
**Category:** Dashboard\
**Created:** [24 February 2021 08:57 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535 "2021-02-24T08:57:57Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [24 February 2021 08:57 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/1 "2021-02-24T08:57:58Z")

</div>

Hi good evening , im currently having a problem with my project. my project is to display the humidity and temperature value in gauge node by using a serial in. but when i connect the serial port it didnt show the value that i want. here is my node setting ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/0/904c45fd11ad682f4fa5993c88e214c93d340cdd.png) and the debug show

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/4/646a2fd19ef18edaf0be610dc05f2bbf452f4df5.png) please help me to solved this problem. in function node i have wrote msg.payload = {temperature: msg.payload.toString('utf8')}  
return msg

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [24 February 2021 11:52 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/2 "2021-02-24T11:52:42Z")

</div>

You need to add a `change` node before the `ui-gauge` and move msg.payload.temperature to msg.payload and the same for humidity

---

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [25 February 2021 06:42 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/3 "2021-02-25T06:42:08Z")

</div>

i have put the change node like you said. but it display undefined. does the code in arduino ide can be the cause? here is my code in my ide

```auto
#include <dht11.h>

 const int dht11pin= 6;
 int value;
 
dht11 DHT;

void setup(){
  
  Serial.begin(9600);
  
  
  delay(1000);//Wait before accessing Sensor
  pinMode(dht11pin, OUTPUT);

}//end "setup()"

    
void loop(){
  //Start of Program 
 
    DHT.read(dht11pin);

    float h = (DHT.humidity) ; //Stores humidity value
    float t = (DHT.temperature) ;

    String temp = String(t);
    String hum = String(h);
     //Stores temperature value
    

  

    value= analogRead(dht11pin);
    Serial.print("Current humidity = ");
    Serial.print(hum);
    Serial.println("%");
    
    
    Serial.print("Current temperature = ");
     Serial.print(temp);
    Serial.println("C");
    
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop(

```

```auto
[{"id":"91d97567.046a58","type":"tab","label":"DHT11 sensor","disabled":false,"info":""},{"id":"6637330a.c7435c","type":"serial in","z":"91d97567.046a58","name":"Arduino","serial":"99a4d77a.f152f8","x":210,"y":260,"wires":[["ac3e2a6f.3f75b8","6bdf444d.cd239c"]]},{"id":"13df06f3.d70369","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.temperature","targetType":"msg","statusVal":"","statusType":"auto","x":930,"y":200,"wires":[]},{"id":"cd3f8475.069fa8","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.humidity","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":280,"wires":[]},{"id":"ac3e2a6f.3f75b8","type":"function","z":"91d97567.046a58","name":"Temperature","func":"msg.payload = {temperature: msg.payload.temperature}\nreturn msg\n\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":430,"y":220,"wires":[["d3c3f729.439d68"]],"info":"Node-RED receives Humidity and Temperature values in ASCII code format from serial monitor. To display these values on Node-RED Dashboard, we need to convert ASCII code into real values. So to do this above java program is used. In this program every ASCII code is subtracted by 48 except the decimal point and comma."},{"id":"501065f3.a445fc","type":"ui_gauge","z":"91d97567.046a58","name":"Humid Gauge","group":"e9247148.a4936","order":1,"width":0,"height":0,"gtype":"gage","title":"Humidity","label":"%","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":900,"y":320,"wires":[]},{"id":"f80bca47.194a48","type":"ui_gauge","z":"91d97567.046a58","name":"Temp Gauge","group":"90603af8.41fe78","order":0,"width":0,"height":0,"gtype":"gage","title":"Temperature","label":"Celcius","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":890,"y":240,"wires":[]},{"id":"6bdf444d.cd239c","type":"function","z":"91d97567.046a58","name":"Humidity","func":"msg.payload = {humidity: msg.payload.humidity}\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","x":420,"y":300,"wires":[["b13f0b9a.5c2ff8"]],"info":"Node-RED receives Humidity and Temperature values in ASCII code format from serial monitor. To display these values on Node-RED Dashboard, we need to convert ASCII code into real values. So to do this above java program is used. In this program every ASCII code is subtracted by 48 except the decimal point and comma."},{"id":"7f385305.5d1bcc","type":"debug","z":"91d97567.046a58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":400,"wires":[]},{"id":"d3c3f729.439d68","type":"change","z":"91d97567.046a58","name":"","rules":[{"t":"move","p":"payload.temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":650,"y":220,"wires":[["13df06f3.d70369","f80bca47.194a48"]]},{"id":"b13f0b9a.5c2ff8","type":"change","z":"91d97567.046a58","name":"","rules":[{"t":"move","p":"payload.humidity","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":300,"wires":[["cd3f8475.069fa8","501065f3.a445fc"]]},{"id":"99a4d77a.f152f8","type":"serial-port","serialport":"COM8","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","waitfor":"","newline":"0","bin":"false","out":"time","addchar":"false","responsetimeout":""},{"id":"e9247148.a4936","type":"ui_group","name":"humidity","tab":"4fca59d3.f1ef38","order":4,"disp":true,"width":"6","collapse":false},{"id":"90603af8.41fe78","type":"ui_group","name":"temperature","tab":"4fca59d3.f1ef38","order":9,"disp":true,"width":"6","collapse":false},{"id":"4fca59d3.f1ef38","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [25 February 2021 07:58 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/4 "2021-02-25T07:58:18Z")

</div>

Since you have control of the Arduino software I think it would be better if you sent the data as JSON strings so that it can be passed through a JSON node and then be available as a JavaScript Object contains the values.

---

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [26 February 2021 09:44 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/5 "2021-02-26T09:44:18Z")

</div>

hi colin, im new in this. can you teach me how to do that?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [26 February 2021 10:01 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/6 "2021-02-26T10:01:39Z")

</div>

> [@woodyisback](#):
>
> teach me how to do that?

Which bit don't you know how to do?  
Build a JSON string in the Arduino?  
Convert it to a javascript object in node red? If this is the bit you don't know how to do then you just have to feed it through a JSON node.

If you mean you don't know what the JSON string should look like then it depends on exactly what you are trying to send, which isn't clear to me, but possibly something like  
`{"temperature": 23.0, "humidity": 38}`

---

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [1 March 2021 02:29 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/7 "2021-03-01T02:29:10Z")

</div>

> [@Colin](#):
>
> Convert it to a javascript object in node red?

> [@Colin](#):
>
> Build a JSON string in the Arduino?

actually both of them , can you ? here is my coding in arduino

```auto

#include <dht11.h>

 const int dht11pin= 6;
 int value;
 
dht11 DHT;

void setup(){
  
  Serial.begin(9600);
  
  
  delay(1000);//Wait before accessing Sensor
  pinMode(dht11pin, OUTPUT);

}//end "setup()"

    
void loop(){
  //Start of Program 
 
    DHT.read(dht11pin);

    float h = (DHT.humidity) ; //Stores humidity value
    float t = (DHT.temperature) ;

    String temp = String(t);
    String hum = String(h);
     //Stores temperature value
    
  

    value= analogRead(dht11pin);
    Serial.print("Current humidity = ");
    Serial.print(hum);
    Serial.println("%");
    
    
    
    Serial.print("Current temperature = ");
    Serial.print(temp);
    Serial.println("C");
    
    
    delay(5000);//Wait 5 seconds before accessing sensor again.
 
  //Fastest should be once every two seconds.
 
}// end loop(

```

---

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [1 March 2021 02:39 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/8 "2021-03-01T02:39:28Z")

</div>

> [@Colin](#):
>
> {"temperature": 23.0, "humidity": 38}

how can i get the value from the arduino dht11 sensor and display it on the json string below?

msg.payload = {"temperature": , "humidity": }  
return msg;

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 March 2021 07:32 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/9 "2021-03-01T07:32:51Z")

</div>

> [@woodyisback](#):
>
> how can i get the value from the arduino dht11 sensor and display it on the json string below?

Modify your Arduino code to actually send the string {"temperature": 23.0, "humidity": 38}. Job done.

---

<div class="post-metadata">

**Author:** ![woodyisback](https://avatars.discourse-cdn.com/v4/letter/w/ed8c4c/32.png) [@woodyisback](https://discourse.nodered.org/u/woodyisback)\
**Post date:** [1 March 2021 07:48 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/10 "2021-03-01T07:48:28Z")

</div>

which part should i change? the serial print?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [1 March 2021 08:14 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/11 "2021-03-01T08:14:33Z")

</div>

Yes. Something like...

```auto
    char s[100];
    sprintf(s, "{\"humidity\": %f, \"temperature\": %f}", hum, temp);
    Serial.print(s);

```

_↑ untested - but should get you on the right track_

... then feed the payload into a JSON node & you will have a JS object

then, the docs will explain how to use the debug panel to find the right path to any data item.

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [31 March 2021 08:14 UTC](https://discourse.nodered.org/t/problem-to-display-serial-in-data-to-gauge/41535/12 "2021-03-31T08:14:36Z")

</div>

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