#include <dht.h>
dht DHT;
#define DHT11_PIN 2 // what pin we're connected to // DHT 11
String TextForSms ;
String humidity = " Humidity: %";
String temperature = " Temperature";
String sign = " *C";
char fromc;
void setup() {
Serial.begin(9600);
}
void loop() {
int chk = DHT.read11(DHT11_PIN);
float h = DHT.humidity;
float t = DHT.temperature;
delay(2000);
}
TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms);
TextForSms = "";
delay(1000);
What are those lines :
[code
TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms);
TextForSms = "";
delay(1000);
/code]
outside of the loop or any function.
Please post all the error message.
Regards,
bidouilleelec
Basically Im using that in order to split the values of t and h into separate textboxes in visual basic.
The error message is this
sketch_dec31c:22: error: expected constructor, destructor, or type conversion before '.' token
sketch_dec31c:23: error: expected constructor, destructor, or type conversion before '.' token
sketch_dec31c:25: error: expected declaration before '}' token
void loop() {
int chk = DHT.read11(DHT11_PIN);
float h = DHT.humidity;
float t = DHT.temperature;
delay(2000);
}
That is the extent of your loop function.
The code immediately after this is not in a function, but must be.
Thanks but now I get this error:
expected declaration before '}' token
Havent it already been declared at the top as String TextForSms
#include <dht.h>
dht DHT;
#define DHT11_PIN 2
String TextForSms;
String h = " Humidity: %";
String t = " Temperature";
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
}
void loop() {
delay(2000);
int chk = DHT.read11(DHT11_PIN);
float h = DHT.humidity;
Serial.print(h);
float t = DHT.temperature;
Serial.print(t);
}
}
TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms);
TextForSms = "";
delay(1000);
{
You've still got code outside of any function.
Please remember to use code tags when posting code
Thanks a lot AWOL,how about now?Im still getting errors.
#include <dht.h> // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
#define DHT11_PIN 2
// Initialize DHT sensor for normal 16mhz Arduino
String TextForSms ;
String humidity = " Humidity: %";
String temperature = " Temperature";
String sign = " *C";
char fromc; // character from computer
void setup() {
Serial.begin(9600);
// Serial.println("DHT11 test!");
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)
int h = dht.readHumidity();
// Read temperature as Celsius
int t = dht.readTemperature();
// Read temperature as Fahrenheit
int 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;
}
// Compute heat index
// Must send in temp in Fahrenheit!
int hi = dht.computeHeatIndex(f, h);
TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms);
TextForSms = "";
delay(1000);
}
With the String constructor you need it in brackets ( )
Read the how to use this forum-please read sticky to see how to post code properly and how to get the most from this forum.
You forgot to put this line above setup():
DHT dht(DHTPIN, DHTTYPE);
It looks like you're changing stuff at random in the vain hope that it will start working.
I'd suggest that you find the most basic example that came with the library you're using and start there.
Also posted at:
- arduino uno - I keep gettint the error expected construcotr,destructor or type conversion before = token - Arduino Stack Exchange
- https://arduino.stackexchange.com/q/60198
If you're going to do that then please be considerate enough to add links to the other places you cross posted. This will let us avoid wasting time due to duplicate effort and also help others who have the same questions and find your post to discover all the relevant information. When you post links please always use the chain links icon on the toolbar to make them clickable.
Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. If your browser doesn't show the posting toolbar then you can just manually add the code tags:
[code]
[color=blue]// your code is here[/color]
[/code]
Using code tags and other important information is explained in the How to use this forum post. Please read it.
Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read. If you're using the Arduino Web Editor you will not have access to this useful tool but it's still unacceptable to post poorly formatted code. I recommend you to use the standard IDE instead.
Please remove unnecessary blank lines from your code before posting to the forum. One or two to separate code into logical sections is fine but large spaces for no reason or random blank lines just make for more scrolling when we're trying to read your code.
When your code requires a library that's not included with the Arduino IDE please always post a link (using the chain link icon on the toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger(Sketch > Include Library > Manage Libraries) then say so and state the full name of the library.