Arduino+Matlab+(DHT22-Sensor) How to plot the Graph

Hello guys,

I have a problem, I have this code to plot the temperature and the humidity:

#include "DHT.h"

#define DHTPIN 9 // what digital pin we're connected to

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("Start!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Feuchtigkeit: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatur: ");
Serial.print(t);
Serial.print(" *C\t ");
Serial.print("Temperatur: ");
Serial.print(f);
Serial.println(" *F\t");

}

But how to plot the graph of temperature/Humidity on matlab?
and how to save the data of the Temp. and Hum. and of the graph?

Hi Triplex,

you're in the german forum.
Either you translate your text or move to the english forum :wink:
And if it's a matlab problem I doubt you'll get much help in the arduino forum.

Hallo

Ich habe folgendes Problem. Ich habe diesen Code um mir mit dem Seriellen Monitor die Temperatur und Feuchtigkeit anzuzeigen:

#include "DHT.h"

#define DHTPIN 9 // what digital pin we're connected to

#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors. This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
Serial.begin(9600);
Serial.println("Start!");

dht.begin();
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);

// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
return;
}

Serial.print("Feuchtigkeit: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperatur: ");
Serial.print(t);
Serial.print(" *C\t ");
Serial.print("Temperatur: ");
Serial.print(f);
Serial.println(" *F\t");

}

Wie kann ich mir jetzt daraus einen Graphen in Matlab plotten lassen?
und wie kann ich die Werte speichern lassen? und den Graphen auch?
oder/und wie kann ich mir den Graphen direkt in Arduino Serieller Plotter plotten lassen?

Vielen Dank im Voraus.

MfG

Ich denke da bist du besser im Matlab Forum ausgehoben

arduino code:

Serial.print(h);
Serial.print(":");
Serial.print(t);
Serial.print(":");
Serial.println(f);

Matlab Code:

s = serial('COM1','BAUD',4800);
fopen(s)
idn = fscanf(s);
fclose(s)

C = strsplit(idn,':')
x = str2num('C')

plot(x(1));
hold on
plot(x(2));
plot(x(3));