# Help with visualising DHT sensor data

**URL:** <https://discourse.processing.org/t/help-with-visualising-dht-sensor-data/13331>\
**Category:** Electronics (Arduino, etc.)\
**Created:** [August 12, 2019, 12:44pm UTC](https://discourse.processing.org/t/help-with-visualising-dht-sensor-data/13331 "2019-08-12T12:44:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![figsgigs](https://avatars.discourse-cdn.com/v4/letter/f/da6949/32.png) [@figsgigs](https://discourse.processing.org/u/figsgigs)\
**Post date:** [August 12, 2019, 12:44pm UTC](https://discourse.processing.org/t/help-with-visualising-dht-sensor-data/13331/1 "2019-08-12T12:44:52Z")

</div>

Hello good people here! I’m new to processing, and attempting to read my DHT11 sensor and visualising it via Processing. I’ve taken the processing/ arduino code from an online tutorial, and adapted it for my own arduino. Seems like the Arduino (UNO) data can’t be read but I’m not sure what the issue is (code perhaps?). Have attached my code as below!

Appreciate your help! 🙂

**Processing Code**

```auto
import meter.*;
import processing.serial.*;

Serial usbPort;
int [] sensors = null;
boolean firstContact = false;
String[] list;

Meter m, m2;

void setup() {
  size(950, 400);
  background(0);
  
  String portName = Serial.list()[0];//listens for serial port and names it"portName"
  usbPort = new Serial(this, "/dev/cu.SLAB_USBtoUART", 9600);

  fill(120, 50, 0);
  m = new Meter(this, 25, 100);
  // Adjust font color of meter value  
  m.setTitleFontSize(20);
  m.setTitleFontName("Arial bold");
  m.setTitle("Temperature (C)");
  m.setDisplayDigitalMeterValue(true);
  
  // Meter Scale
  String[] scaleLabelsT = {"0", "10", "20", "30", "40", "50", "60", "70", "80"};
  m.setScaleLabels(scaleLabelsT);
  m.setScaleFontSize(18);
  m.setScaleFontName("Times New Roman bold");
  m.setScaleFontColor(color(200, 30, 70));
  
  m.setArcColor(color(141, 113, 178));
  m.setArcThickness(10);
  m.setMaxScaleValue(80);
  
  m.setNeedleThickness(3);
  
  m.setMinInputSignal(0);
  m.setMaxInputSignal(80);

  // A second meter for reference
  int mx = m.getMeterX();
  int my = m.getMeterY();
  int mw = m.getMeterWidth();
  
  m2 = new Meter(this, mx + mw + 20, my);
  m2.setTitleFontSize(20);
  m2.setTitleFontName("Arial bold");
  m2.setTitle("Humidity (%)");
  m2.setDisplayDigitalMeterValue(true);
  
  String[] scaleLabelsH = {"0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"};
  m2.setScaleLabels(scaleLabelsH);
  m2.setScaleFontSize(18);
  m2.setScaleFontName("Times New Roman bold");
  m2.setScaleFontColor(color(200, 30, 70));
  
  m2.setArcColor(color(141, 113, 178));
  m2.setArcThickness(10);
  m2.setMaxScaleValue(100);
  
  m2.setNeedleThickness(3);
  
  m2.setMinInputSignal(0);
  m2.setMaxInputSignal(100);
  
}

public void draw() {
  
  textSize(30);
  fill(0, 255, 0);
  text("Temperature and Humidity", 270, 50);
  
  if (usbPort.available() > 0) {
    String val = usbPort.readString();
    list = split(val, ',');
    float temp = float(list[0]);
    float hum = float(list[1]);
    
    println("Temperature: " + temp + " C " + "Humidity: " + hum + " %");
    
    m.updateMeter(int(temp));
    m2.updateMeter(int(hum));
  }
}

```

**Arduino Code** (attaching original notes here)

```auto
#include <DHT.h>

// for DHT22, 
// VCC: 5V or 3V
// GND: GND
// DATA: 2
int pinDHT11 = 2;
#define DHTTYPE DHT11
DHT dht(pinDHT11, DHTTYPE);

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

void loop() {
  // start working...
  
  // read without samples.
  // @remark We use read2 to get a float data, such as 10.1*C
  // if user doesn't care about the accurate data, use read to get a byte data, such as 10*C.
  float temperature = dht.readTemperature();

  }
  
  Serial.print(temperature);
  Serial.print(",");
  return;
  }
  // DHT22 sampling rate is 0.5HZ.
  delay(2500);
}

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [August 12, 2019, 2:03pm UTC](https://discourse.processing.org/t/help-with-visualising-dht-sensor-data/13331/2 "2019-08-12T14:03:36Z")

</div>

please after

> [@figsgigs](#):
>
> String val = usbPort.readString();

use ( temporary ) a

```auto
println("arduino send: "+val);

```

and check if that data make any sense.

actually it might be a good idea to strip down that processing code to a 5 line thing  
just for confirm the communication.

* * *

> [@figsgigs](#):
>
> I’ve taken the processing/ arduino code from an online tutorial

in that case a link can be good,  
just imagine you start from a 10 year old code for a retired processing version, or other…

---

<div class="post-metadata">

**Author:** ![figsgigs](https://avatars.discourse-cdn.com/v4/letter/f/da6949/32.png) [@figsgigs](https://discourse.processing.org/u/figsgigs)\
**Post date:** [August 12, 2019, 2:51pm UTC](https://discourse.processing.org/t/help-with-visualising-dht-sensor-data/13331/3 "2019-08-12T14:51:40Z")

</div>

[Just fyi the link to the tutorial is here!](https://www.hackster.io/hardikrathod/create-gui-to-visualize-temp-and-humidity-for-arduino-85a7aa)
