Arduino Code
#include <DHT.h>
#define DHTPIN 2 // Pin where the KY-015 sensor is connected
#define DHTTYPE DHT11 // DHT11 sensor type
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
float humidity = dht.readHumidity(); // Read humidity from KY-015
float temperature = dht.readTemperature(); // Read temperature from KY-015
// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println(“Failed to read from sensor!”);
return;
}
// Send the temperature and humidity data over serial
Serial.print(“Temperature: “);
Serial.print(temperature);
Serial.print(” C, Humidity: “);
Serial.print(humidity);
Serial.println(” %”);
delay(2000); // Wait for 2 seconds before the next reading
}
Python Code
Arduino Code
// Example Arduino Code
#include <Arduino.h>
const int heartbeatPin = A0; // Pin connected to heartbeat sensor
const int tempSensorPin = A1; // Pin connected to temperature sensor
int heartbeatValue = 0;
int tempValue = 0;
void setup() {
Serial.begin(9600);
}
void loop() {
heartbeatValue = analogRead(heartbeatPin);
tempValue = analogRead(tempSensorPin);
// Send data over serial
Serial.print(“Heartbeat:”);
Serial.print(heartbeatValue);
Serial.print(“, Temp:”);
Serial.println(tempValue);
delay(1000);
}