#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
#include <LiquidCrystal.h>
#include <stdlib.h>
#include <DHT.h>
#define DHTPIN A0 // DHT data pin connected to Arduino pin 2
#define DHTTYPE DHT11 // DHT 22 (or AM2302)
#include <dht11.h>
#define RX 2
#define TX 3
#define dht_apin A0 // Analog Pin sensor is connected to
dht11 dhtObject;
String AP = "Redmi"; // AP NAME
String PASS = "Sunny898"; // AP PASSWORD
String API = "ABY09QBF56MZ59QL"; // Write API KEY
String HOST = "api.thingspeak.com";
String PORT = "80";
int countTrueCommand;
int countTimeCommand;
boolean found = false;
int valSensor = 1;
SoftwareSerial esp8266(RX,TX);
DHT dht(DHTPIN, DHTTYPE); // Initialize the DHT sensor
float temp;
int hum;
int error;
String tempC;
LiquidCrystal lcd (4,5,6,7,8,9);
void setup()
{
lcd.begin(16, 2);
lcd.print("MonitoringValues");
delay(100);
lcd.setCursor(0,1);
lcd.print("GettingData...");
Serial.begin(9600);
esp8266.begin(115200);
sendCommand("AT",5,"OK");
sendCommand("AT+RESTORE",5,"OK");
sendCommand("AT+CWMODE=1",5,"OK");
sendCommand("AT+CWJAP=""+ AP +"",""+ PASS +""",20,"OK");
}
void loop()
{
String getData = "GET /update?api_key="+ API +"&field1="+getTemperatureValue()+"&field2="+getHumidityValue();
sendCommand("AT+CIPMUX=1",5,"OK");
sendCommand("AT+CIPSTART=0,"TCP",""+ HOST +"","+ PORT,15,"OK");
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
esp8266.println(getData);delay(1500);countTrueCommand++;
sendCommand("AT+CIPCLOSE=0",5,"OK");
}
String getTemperatureValue(){
dhtObject.read(dht_apin);
Serial.print(" Temperature(C)= ");
int temp = dhtObject.temperature;
Serial.println(temp);
delay(50);
return String(temp);
}
String getHumidityValue(){
dhtObject.read(dht_apin);
Serial.print(" Humidity in %= ");
int humidity = dhtObject.humidity;
Serial.println(humidity);
delay(50);
return String(humidity);
}
void sendCommand(String command, int maxTime, char readReplay[])
{
Serial.print(countTrueCommand);
Serial.print(". at command => ");
Serial.print(command);
Serial.print(" ");
while(countTimeCommand < (maxTime*1))
{
esp8266.println(command);//at+cipsend
if(esp8266.find(readReplay))//ok
{
found = true;
break;
}
countTimeCommand++;
}
if(found == true)
{
Serial.println("Ok");
countTrueCommand++;
countTimeCommand = 0;
}
if(found == false)
{
Serial.println("Fail");
countTrueCommand = 0;
countTimeCommand = 0;
}
found = false;
}
lcd.clear();
//Read temperature and humidity values from DHT sensor:
start: //label
error=0;
temp = dht.readTemperature();
hum = dht.readHumidity();
lcd.setCursor(0, 0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.print(" C");
delay (100);
lcd.setCursor(0, 1); // set the cursor to column 0, line 2
lcd.print("Humi = ");
lcd.print(hum);
lcd.print(" %");
delay(1000);
}
Error Message-
Arduino: 1.8.12 (Windows 10), Board: "Arduino Uno"
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: In function 'void setup()':
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:39:26: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT",5,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:40:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+RESTORE",5,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:41:35: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CWMODE=1",5,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:42:61: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CWJAP=""+ AP +"",""+ PASS +""",20,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: In function 'void loop()':
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:49:34: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CIPMUX=1",5,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:50:67: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CIPSTART=0,"TCP",""+ HOST +"","+ PORT,15,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:51:63: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CIPSEND=0," +String(getData.length()+4),4,">");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino:53:36: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
sendCommand("AT+CIPCLOSE=0",5,"OK");
^
C:\Users\Sunny Gaikwad\Pictures\temp_level\sketch_mar13b\sketch_mar13b.ino: At global scope:
sketch_mar13b:106:3: error: 'lcd' does not name a type
lcd.clear();
^~~
sketch_mar13b:108:8: error: found ':' in nested-name-specifier, expected '::'
start: //label
^
sketch_mar13b:108:3: error: 'start' does not name a type; did you mean 'sqrt'?
start: //label
^~~~~
sqrt
sketch_mar13b:110:5: error: 'temp' does not name a type
temp = dht.readTemperature();
^~~~
sketch_mar13b:111:5: error: 'hum' does not name a type
hum = dht.readHumidity();
^~~
sketch_mar13b:112:5: error: 'lcd' does not name a type
lcd.setCursor(0, 0);
^~~
sketch_mar13b:113:5: error: 'lcd' does not name a type
lcd.print("Temp = ");
^~~
sketch_mar13b:114:5: error: 'lcd' does not name a type
lcd.print(temp);
^~~
sketch_mar13b:115:5: error: 'lcd' does not name a type
lcd.print(" C");
^~~
sketch_mar13b:116:11: error: expected constructor, destructor, or type conversion before '(' token
delay (100);
^
sketch_mar13b:117:5: error: 'lcd' does not name a type
lcd.setCursor(0, 1); // set the cursor to column 0, line 2
^~~
sketch_mar13b:118:5: error: 'lcd' does not name a type
lcd.print("Humi = ");
^~~
sketch_mar13b:119:5: error: 'lcd' does not name a type
lcd.print(hum);
^~~
sketch_mar13b:120:5: error: 'lcd' does not name a type
lcd.print(" %");
^~~
sketch_mar13b:121:10: error: expected constructor, destructor, or type conversion before '(' token
delay(1000);
^
sketch_mar13b:122:3: error: expected declaration before '}' token
}
^
Multiple libraries were found for "Adafruit_Sensor.h"
Used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Adafruit_Sensor-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Adafruit_Unified_Sensor
Multiple libraries were found for "SoftwareSerial.h"
Used: C:\Users\Sunny Gaikwad\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.2\libraries\SoftwareSerial
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\EspSoftwareSerial
Multiple libraries were found for "LiquidCrystal.h"
Used: C:\Program Files (x86)\Arduino\libraries\LiquidCrystal
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\NewLiquidCrystal_lib
Multiple libraries were found for "DHT.h"
Used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\DHT-sensor-library-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\arduino-DHT-master
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\Grove_Temperature_And_Humidity_Sensor
Not used: C:\Users\Sunny Gaikwad\Documents\Arduino\libraries\DHT_sensor_library
exit status 1
'lcd' does not name a type
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.