I have this code that takes temperature and humidity values from a DHT11 sensor and number of faces from an external python code and prints them on an OLED screen but instead of values of variables it keeps printing 0, how can I solve it? (Sorry some parts are not in English but just consider them as random variable names.)
//dht11 kodu için ayarlamalar
#include <dht.h>
dht DHT;
#define DHT11_PIN 7
//ekran için ayarlamalar
#include "U8glib.h"
U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_DEV_0);
char bufferX [20];
char bufferY [20];
char bufferZ [20];
//fan kodu için ayarlamalar
int mot1 = 8;
int mot2 = 9;
int en1 = 10;
int dir = 6;
bool state = true;
int nob = A0;
int val = 0;
int fan_hizi = 0;
String faces_str;
int faces;
float sicaklik;
float nem;
void draw(void)
{
u8g.setFont(u8g_font_unifont);
u8g.drawStr( 0, 15, bufferX);
u8g.drawStr( 0, 30, bufferX);
u8g.drawStr( 0, 45, bufferY);
u8g.drawStr( 0, 60, bufferZ);
}
void setup() {
Serial.begin(9600); //iletişim ve dht11 verisi
// pin ayarları
pinMode(mot1,OUTPUT);
pinMode(mot2,OUTPUT);
pinMode(en1,OUTPUT);
pinMode(dir,INPUT_PULLUP);
}
void loop() {
//dht11 kodu
sicaklik = DHT.temperature;
nem = DHT.humidity;
delay(1000);
//iletişim kodu
if(Serial.available() > 0) {
faces_str = Serial.readString();
faces = faces_str.toInt();
}
Serial.print(faces);
//sınırlar
if(faces == 0 && sicaklik < 25 && nem < 65) {
fan_hizi = 50;
digitalWrite(13, HIGH);
digitalWrite(12, LOW);
}
if(faces >= 1 || sicaklik >= 25 || nem >= 65) {
fan_hizi = 250;
digitalWrite(13, LOW);
digitalWrite(12, HIGH);
}
//ekran
sprintf(bufferX, "Yuzler: %d", faces);
sprintf(bufferY, "Sicaklik: %d", sicaklik);
sprintf(bufferZ, "Nem: %d", nem);
u8g.firstPage();
do {
draw();
}
while ( u8g.nextPage() );
delay(10);
//fan kodu
analogWrite(en1, fan_hizi);
digitalWrite(mot1, HIGH);
digitalWrite(mot2, LOW);
delay(1000);
digitalWrite(mot1, LOW);
}