-2

I'm trying to use this code to get temperature and humidity values from DHT11 sensor and send it to Python and I need to write the temperature and humidity values in the same line. But I keep getting the error code

expected primary-expression before '%' token

How can I fix this?

#include <dht.h>
#include <stdio.h>
int a = 0;
int b = 0;
char buffer [64];

dht DHT;

#define DHT11_PIN 7

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

void loop(){
  a = DHT.temperature;
  b = DHT.humidity;
  int chk = DHT.read11(DHT11_PIN);
  sprintf(buffer, %d %d, a, b);
  Serial.print(buffer);
  delay(1000);
}
1
  • 1
    The error mentioned a line number. Did you look at that line? – timemage Jan 24 at 0:39
1

You are missing quotes on the second parameter of sprintf:

sprintf(buffer, "%d %d", a, b);
1
  • please don't answer syntax error questions. they are off-topic – Juraj Jan 24 at 7:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.