I have been recently working on a website that takes input from the arduino ie- temperature and humidity. But there is a fatal problem that I've encountered, the serial monitor spews out some garbage with some actual readings. Is there a way to eliminate this?
╰─λ cat /dev/ttyACM0
T0°C
Humidity: 39.00%
00%
Temperature: 32.70°C
Humidity: 39.00%
Temperature: 32.70°C
Humidity: 39.00%
Temperature: 32.70°C
Humidity: 39.00%
00%
Temperature: 32.70°C
Humidity: 39.00%
Temperature: 32.70°C
Humidity: 39.00%
Temperature: 32.70°C
Humidity: 39.00%
idit9.00Tempure:70°Humi: 39
emperatu32.7
Huty: 0%
idit9.00Tempure:70°umidity.00%Tratu32.7
idit9.00Tempture.70�Humi: 39
empere: 0°Cmidi39.0
atur°C
Hum9.00
code-
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 4
#define DHTTYPE DHT11
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
sensor_t sensor;
dht.begin();
delayMS = sensor.min_delay / 1000;
}
void loop() {
delay(delayMS);
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
}
board - Arduino Uno (R3)
setup()
that makes it evident in the output listing that it is only running once.delayMS
? The calculation looks fishy, sincesensor
is not initialized. The value should be around 2500ms.sudo fuser -v /dev/ttyACM0
.