#include "DHT.h"
#define DHTPIN D1
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
#include "UbidotsMicroESP8266.h"
#define TOKEN "TOKEN" // Put here your Ubidots TOKEN
#define WIFISSID "SSID"
#define PASSWORD "PASSWORD"
int vs = A0;
int vs1 = D0;
int percentValue = 0;
Ubidots client(TOKEN);
unsigned long lastMillis = 0;
void setup(){
Serial.begin(115200);
dht.begin();
delay(10);
client.wifiConnection(WIFISSID, PASSWORD);
pinMode(vs ,INPUT);
pinMode(vs1 ,INPUT);
Wire.begin(2,0);
lcd.init();
lcd.backlight();
lcd.home();
}
void loop(){
if (millis() - lastMillis > 10000) { ///every 10S
float humedad = dht.readHumidity();
float temperatura = dht.readTemperature();
float data = analogRead(vs);
float data1 = digitalRead(vs1);
percentValue = map(data, 1023, 200, 0, 100);
lastMillis = millis();
client.add("humrel", humedad);
client.add("temperature", temperatura);
client.add("soil", percentValue);
client.add("LDR", data1);
client.sendAll(true);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("H:"); lcd.print(humedad); lcd.print("% S:"); lcd.print(percentValue); lcd.print("%");
lcd.setCursor(0,1);
lcd.print("T:"); lcd.print(temperatura); lcd.print("C L:"); lcd.print(data1); lcd.print("%");
delay(500);
}
}
fix what problem?
looks ubidots is some variant of MQTT.
i suggest you comment/#ifdef out use of your client and see if that is the cause
or maybe it's because you attempt to use the connection, "client", before it successfully connects.
with standard WiFI routines, after attempting to connect to WiFI
WiFi.begin (ssid, pass);
the code waits for the connection to complete
if (WL_CONNECTED != WiFi.status ()) {
printf (" not connected\n");
return false;
}
If you install the exception-decoder like described here
the exception-decoder will guide to to that line of code where the exception occurs
best regards Stefan
Which IDE-version are you using?
restart the arduino IDE.
and look again
sorry guys if i am bothoring you with questions but i really dont know much of programming and i do a lot of mistakes
1.8.18
You are welcome. And making mistakes is normal. As long as you show some own effort and answer questions that users post you will receive continious support.
There are threads that are 500 posts long and still growing.
best regards Stefan
Can you show us how you have everything connected.
Somehow the I2C pins on an ESP are D1 & D2, but you have defined the DHT pin as D1, Then you go for sw I2C but that may not work as expected. I'm not sure i never use I2C
idk it says Arduino
sensor_update:34:16: error: return-statement with a value, in function returning 'void' [-fpermissive]
34 | return false;
| ^~~~~
exit status 1
return-statement with a value, in function returning 'void' [-fpermissive]
the function you put this in returns a void.
you probably put this after the begin(). it shouldn't return. make it a while loop
The way that you communicate in this forum is non-optimal and somehow uneffective.
You should take 20 minutes of your own freetime to read this.
The result of taking the advice to your heart will be a faster finished project:
best regards Stefan
At the end of your millis()-based if( ) routine, you have "delay(500);" ─ and that will hose the deal.
change above to
void setup(){
Serial.begin(115200);
dht.begin();
delay(10);
client.wifiConnection(WIFISSID, PASSWORD);
while(WL_CONNECTED != WiFi.status ()) {
printf (" not connected\n");
delay (1000);
}
...
}
Can someone help me bc i found the mistakes with exception decoder but i dont know how to fix the lines bc i am bad at programmig
``
THIS IS THE CODE THAT NEEDS TO BE FIXED
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "UbidotsMicroESP8266.h"
#define DHTPIN D1
#define DHTTYPE DHT11
#define TOKEN "TOKEN" // Put here your Ubidots TOKEN
#define WIFISSID "SSID"
#define PASSWORD "PASSWORD"
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27,16,2);
Ubidots client(TOKEN);
unsigned long lastMillis = 0;
int vs = A0;
int vs1 = D0;
int percentValue = 0;
void setup(){
Serial.begin(115200);
dht.begin();
client.wifiConnection(WIFISSID, PASSWORD);
pinMode(vs, INPUT);
pinMode(vs1, INPUT);
Wire.begin(2,0);
lcd.init();
lcd.backlight();
lcd.home();
}
void loop(){
if (millis() - lastMillis > 10000) { ///every 10S
float humedad = dht.readHumidity();
float temperatura = dht.readTemperature();
float data = analogRead(vs);
float data1 = digitalRead(vs1);
percentValue = map(data, 0, 1023, 0, 100); // Fixed the mapping of the analogRead value
lastMillis = millis();
client.add("humrel", humedad);
client.add("temperature", temperatura);
client.add("soil", percentValue);
client.add("LDR", data1);
client.sendAll(true);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("H:"); lcd.print(humedad); lcd.print("% S:"); lcd.print(percentValue); lcd.print("%");
lcd.setCursor(0,1);
lcd.print("T:"); lcd.print(temperatura); lcd.print("C L:"); lcd.print(data1); lcd.print("%");
delay(500);
}
THIS ARE THE RESULTS OF EXCEPTION DECODER.CAN SOMEONE HELP ME FIX THE CODE
}`Exception 0: Illegal instruction
PC: 0x40201d8c
EXCVADDR: 0x00000000
Decoding stack results
0x402012e3: DHT::begin(unsigned char) at C:\Users\dejvi\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp line 69
0x40201072: setup() at C:\Users\dejvi\Desktop\sensor_update/sensor_update.ino line 24
0x40204d9c: loop_wrapper() at C:\Users\dejvi\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\3.0.0\cores\esp8266\core_esp8266_main.cpp line 198
`
Please do not post pictures of code or error messages
Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'
Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination
thank you i am gonna fix it now