# Arduino- Node Red Dashboard Separate Sensor Data Logging

**URL:** https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116
**Category:** Dashboard
**Created:** [27 June 2018 08:47 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116 "2018-06-27T08:47:43Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [27 June 2018 08:47 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/1 "2018-06-27T08:47:43Z")

</div>

I am using 2 sensors ( photo resistor and temperature, in the middle is just LED and buzzer regarding on the response change with photo resistor sensor) and would like to put up on the gauge and chart in the dashboard. Right now, the reading reads in line with comma in between, the chart is combining them up which makes them unstable and gauge is only showing for 1 sensor. how could I separate and do different reading, gauge and chart for each sensor? Below is the arduino code and node red.

arduino:

```auto
int sensePin = 0;
int ledPin = 9;
int val;
int tempPin = 1;
const int buzzer = 12;

void setup()
{
  pinMode(ledPin, OUTPUT);
  analogReference(DEFAULT); 
  pinMode(buzzer, OUTPUT);
   Serial.begin(9600);
  
}

void loop()
{
  // read the sensor
  int val = analogRead(sensePin);
  
  if(val < 960)
  {
    digitalWrite(ledPin, HIGH);
    tone(buzzer, 1000); 

  }
  else
  {
    digitalWrite(ledPin, LOW);
    noTone(buzzer);    
  
  }
    
    val = analogRead(tempPin);
  float mv = ( val/1024.0)*5000; 
  float cel = mv/10;
  float farh = (cel*9)/5 + 32;

  Serial.print(cel);
  Serial.print("*C , ");
  Serial.println(analogRead(sensePin)); 
  delay(1000);

}

```

node-red:

```auto
[{"id":"155d5a28.f6d206","type":"debug","z":"ef68beb7.75aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":382,"y":196,"wires":[]},{"id":"99c64bbb.3ec6a8","type":"ui_text","z":"ef68beb7.75aa","group":"9aaba0ca.eddc2","order":0,"width":"0","height":"0","name":"","label":"PHOTORESISTOR, TEMPERATURE","format":"{{msg.payload}}","layout":"row-left","x":458,"y":103,"wires":[]},{"id":"792451eb.62aaa","type":"ui_gauge","z":"ef68beb7.75aa","name":"","group":"9aaba0ca.eddc2","order":0,"width":0,"height":0,"gtype":"gage","title":"direction","label":"units","format":"{{value}}","min":0,"max":"2000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"1000","seg2":"1500","x":358,"y":45,"wires":[]},{"id":"15dee299.b5ad8d","type":"ui_chart","z":"ef68beb7.75aa","name":"","group":"9aaba0ca.eddc2","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"","dot":false,"ymin":"0","ymax":"1000","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":354,"y":420,"wires":[[],[]]},{"id":"e6a955df.4030b8","type":"serial in","z":"ef68beb7.75aa","name":"","serial":"2365f3c7.2d0b6c","x":159,"y":244,"wires":[["792451eb.62aaa","99c64bbb.3ec6a8","155d5a28.f6d206","15dee299.b5ad8d","9f39afc.9482e5"]]},{"id":"9f39afc.9482e5","type":"serial out","z":"ef68beb7.75aa","name":"","serial":"2365f3c7.2d0b6c","x":350,"y":289,"wires":[]},{"id":"9aaba0ca.eddc2","type":"ui_group","z":"","name":"SENSORS","tab":"c326fe58.3d375","order":1,"disp":true,"width":"14","collapse":false},{"id":"2365f3c7.2d0b6c","type":"serial-port","z":"","serialport":"COM3","serialbaud":"9600","databits":"8","parity":"none","stopbits":"1","newline":"\\n","bin":"false","out":"char","addchar":false},{"id":"c326fe58.3d375","type":"ui_tab","z":"","name":"READING","icon":"dashboard"}]

```

---

<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: [27 June 2018 09:23 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/2 "2018-06-27T09:23:26Z")

</div>

Is that the exact arduino code or did you type it in because it looks like there are some errors in it

What sensors are you using?

What is the debug node showing?

---

<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: [27 June 2018 09:49 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/3 "2018-06-27T09:49:19Z")

</div>

@youthtech please edit your post and put three backticks on a line before the flow and on the line after it. That tells discourse that it should not mess with the text and in particular it should not change the quotes into smart quotes. As it is currently it is not possible to import the flow.  
Thanks.

---

<div class="post-metadata">

### Author: ![markost](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@markost](https://discourse.nodered.org/u/markost)
#### Post date: [27 June 2018 14:48 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/4 "2018-06-27T14:48:36Z")

</div>

Format Serial.print(ln) in Arduino as:  
1(sensor1value)  
2(sensor2value).

At node red side use function with if then and substring, and two outputs.

If 1st string is “1” then send rest of the message to the 1st output.  
Same for 2nd output but if 1st string is “2”.

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [27 June 2018 15:00 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/5 "2018-06-27T15:00:14Z")

</div>

yes, it is the exact arduino code, I’m using a photo resistor and temperature sensor LM35. debug node shows the readings from the photo resistor and temperature.

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [27 June 2018 15:12 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/6 "2018-06-27T15:12:42Z")

</div>

I am sorry, I’m confuse. which line should I put the three back ticks? is it for both arduino and node red or just the node red?

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [27 June 2018 15:15 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/7 "2018-06-27T15:15:32Z")

</div>

When you share any sort of code or flow json that should not be treated as normal written text, then you should put ``` before and after it.

Here is some code without the backticks:

void setup()  
{  
pinMode(ledPin, OUTPUT);  
analogReference(DEFAULT);  
pinMode(buzzer, OUTPUT);  
Serial.begin(9600);

}

Here is some code with the ``` (backticks):

```auto
void setup()
{
pinMode(ledPin, OUTPUT);
analogReference(DEFAULT);
pinMode(buzzer, OUTPUT);
Serial.begin(9600);

}

```

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [27 June 2018 15:36 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/8 "2018-06-27T15:36:41Z")

</div>

alright. just knew this, thanks for teaching. I edited it.

---

<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: [27 June 2018 15:53 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/9 "2018-06-27T15:53:11Z")

</div>

Can you post a screen shot of the debug output so we can see exactly what you have.

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [28 June 2018 00:47 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/10 "2018-06-28T00:47:17Z")

</div>

![debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/95d8dcd133934b3dcd5bd3b455f0506dc35358f2.PNG)

 ![dashboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/78c1e1aed0db2af39ca88425b0b5199f3cd5bd62.PNG)

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [28 June 2018 03:58 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/11 "2018-06-28T03:58:46Z")

</div>

Hi, One possible way (among many) is to use below code inside a function node with 2 outputs:

```auto
let reg = /\d+/g;
let result = msg.payload.match(reg);
[a, b] = result;
temp = {payload: parseInt(a)};
light = {payload: parseInt(b)};
return [temp, light];

```

Explanation:

[JavaScript Problem: Extracting Numbers from a String](https://youtu.be/pfkkdzeyx6U)

Function node:

```auto
[{"id":"a7d3a24b.5b0d7","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"14139795.2a1468","type":"function","z":"a7d3a24b.5b0d7","name":"Extract data","func":"let reg = /\\d+/g;\nlet result = msg.payload.match(reg);\n[a, b] = result;\ntemp = {payload: parseInt(a)};\nlight = {payload: parseInt(b)};\nreturn [temp, light];","outputs":2,"noerr":0,"x":514.1000556945801,"y":206.00001525878906,"wires":[[],[]]}]

```

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [29 June 2018 03:48 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/13 "2018-06-29T03:48:14Z")

</div>

I have a question, what to put for a and b for enable it to work? I tried put ldr as a and cel as b but only a shows up, b does not. I have adjusting the arduino codes for easier labelling as follow:

```auto
int LDR = A0;
int ledPin = 9;
int LDRReading = 0; 
int val;
int tempPin = A1;
const int buzzer = 12;

void setup()
{
  pinMode(ledPin, OUTPUT);
  analogReference(DEFAULT); 
  pinMode(buzzer, OUTPUT);
   Serial.begin(9600);
  
}

void loop()
{
  LDRReading = analogRead(LDR);  
  
  if(LDRReading < 800)
  {
    digitalWrite(ledPin, HIGH);
    tone(buzzer, 1000); 

  }
  else
  {
    digitalWrite(ledPin, LOW);
    noTone(buzzer);    
  
  }
    
    val = analogRead(tempPin);
  float mv = ( val/1024.0)*5000; 
  float cel = mv/10;
  float farh = (cel*9)/5 + 32;
  float ldr = (LDRReading)*1;

  Serial.print(ldr);
  Serial.print(" , ");
  Serial.print(cel);
  Serial.println(); 
  delay(500);

}

```

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [29 June 2018 04:57 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/14 "2018-06-29T04:57:06Z")

</div>

Hi, the very same function node (same code) should work as long as your arduino output is two numbers separated by comma (which seems to be the case). Can you insert a debug node in the output of the serial node and another debug node in the output of the function node and than show us a screenshot of the debug side panel ?

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [29 June 2018 05:54 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/15 "2018-06-29T05:54:10Z")

</div>

![debug](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/066aa428caa67987953b2eec7ed313b2adcfe279.PNG)

 ![daashboard](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/70045def679255881a31176d5da0155f67409d59.PNG)

---

<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: [29 June 2018 10:17 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/16 "2018-06-29T10:17:43Z")

</div>

> [@Andrei](#):
>
> [{"id":"a7d3a24b.5b0d7","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"14139795.2a1468","type":"function","z":"a7d3a24b.5b0d7","name":"Extract data","func":"let reg = /\d+/g;\nlet result = msg.payload.match(reg);\n[a, b] = result;\ntemp = {payload: parseInt(a)};\nlight = {payload: parseInt(b)};\nreturn [temp, light];","outputs":2,"noerr":0,"x":514.1000556945801,"y":206.00001525878906,"wires":[,]}]

@Andrel - your reg expression converts the periods (".") in the numbers to commas (",") - i.e. for "854.00, 38.09" you get 854,00,38,09 so  
[a, b] = result;  
returns 854 and 0

---

<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: [29 June 2018 10:24 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/17 "2018-06-29T10:24:31Z")

</div>

If the data is as you say i.e. "854.00, 38.09” - I would feed it to a CSV node and then you can access the data with msg.payload.col1 and msg.payload.col2

---

<div class="post-metadata">

### Author: ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)
#### Post date: [30 June 2018 01:25 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/18 "2018-06-30T01:25:07Z")

</div>

Hi zenofmud, your are are indeed, my bad. Thanks for pointing out 😉

Youthtech,

The proposed solutions from zenofmud and markost should work. I will provide below a second attempt but again I did not test thoroughly. It will work despite that the code is not removing the “\*C” from the string.

I found this explanation:

parseFloat parses its argument, and returns a floating point number. If it encounters a character other than a sign (+ or -), numeral (0-9), a decimal point, or an exponent, it returns the value up to that point and ignores that character and all succeeding characters. Leading and trailing spaces are allowed.

```auto
let result = msg.payload.split(",");
[a,b] = result;
temp = {payload: parseFloat(a)};
light = {payload: parseFloat(b)};
return [temp,light];

```

Testing flow:

```auto
[{"id":"2c35d982.dae386","type":"tab","label":"Flow 18","disabled":false,"info":""},{"id":"eb696b33.4bf5d8","type":"function","z":"2c35d982.dae386","name":"Extract data","func":"let result = msg.payload.split(\",\");\n[a,b] = result;\ntemp = {payload: parseFloat(a)};\nlight = {payload: parseFloat(b)};\nreturn [temp,light];","outputs":2,"noerr":0,"x":540,"y":181,"wires":[["3df65eb1.173642"],["a8c8d257.faffa"]]},{"id":"94eb5816.f85108","type":"inject","z":"2c35d982.dae386","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":195.99994659423828,"y":181.9999876022339,"wires":[["3baa0c18.d23554"]]},{"id":"3baa0c18.d23554","type":"function","z":"2c35d982.dae386","name":"","func":"msg.payload = \"854.30 \\, 35.15\\n\\f\";\nreturn msg;","outputs":1,"noerr":0,"x":346.99995040893555,"y":182.9999876022339,"wires":[["eb696b33.4bf5d8"]]},{"id":"3df65eb1.173642","type":"debug","z":"2c35d982.dae386","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":725.8999443054199,"y":107.99998474121094,"wires":[]},{"id":"a8c8d257.faffa","type":"debug","z":"2c35d982.dae386","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":724.8999443054199,"y":185.99998474121094,"wires":[]}]

```

---

<div class="post-metadata">

### Author: ![markost](https://avatars.discourse-cdn.com/v4/letter/m/3d9bf3/32.png) [@markost](https://discourse.nodered.org/u/markost)
#### Post date: [2 July 2018 14:25 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/19 "2018-07-02T14:25:49Z")

</div>

hi,

i think that easiest way for the start solving your problem is:

1st step:

format your arduino code

instead

```auto
 Serial.print(ldr);
  Serial.print(" , ");
  Serial.print(cel);
  Serial.println(); 
  delay(500);

```

use:

```auto
 Serial.print("ldr=");
 Serial.println(ldr,2); //2 decimal place
 Serial.print("cel=");  
 Serial.println(cel,2); //2 decimal place
   
  delay(500);

```

See what you have at debug

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [3 July 2018 00:01 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/20 "2018-07-03T00:01:11Z")

</div>

This solve the problem. Thank you so much for your help.

---

<div class="post-metadata">

### Author: ![youthtech](https://avatars.discourse-cdn.com/v4/letter/y/85e7bf/32.png) [@youthtech](https://discourse.nodered.org/u/youthtech)
#### Post date: [3 July 2018 00:02 UTC](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116/21 "2018-07-03T00:02:12Z")

</div>

the dashboard doesn’t show any value of both readings, but debug shows both.

[Next page](https://discourse.nodered.org/t/arduino-node-red-dashboard-separate-sensor-data-logging/1116.md?page=2)
