Upload DHT11 sensor values using GSM 900 | Arduino | Forum

Avatar

Please consider registering
Guest

Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

Register Lost password?
sp_Feed sp_TopicIcon
Upload DHT11 sensor values using GSM 900
Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
1
February 13, 2018 - 6:18 pm
sp_Permalink sp_Print

Good day folks, I am currently building a smart irrigation project using the Arduino UNO. 
Basically, a soil moisture sensor starts and stop a 12V DC water pump. A DHT 11 temperature sensor is just used for indication. I was able to get this part functioning correctly. 

I would like to upload these values to thingspeak using a GSM 900 sim. I am able to get a connection to thingspeak and update the channel field but the temperature values are not accurate that is they are 1020 on the channel graph and 29, 28 etc on my Arduino serial monitor. Any help rectifying this would be greatly appreciated. Below is the code I tried thus far.

#include <SoftwareSerial.h>
#include <String.h>
#include <dht.h>
int sensorPin = 0;    // set the input pin for the potentiometer
int sensorValue = 0;

dht DHT;

#define DHT11_PIN A0

 
SoftwareSerial gprsSerial(7,8);


float temp=0.0;


void setup()
{
  gprsSerial.begin(9600);               // the GPRS baud rate   
  Serial.begin(9600);    // the GPRS baud rate 

  delay(1000);
}
 
void loop()
{
      int chk = DHT.read11(DHT11_PIN);
      temp=analogRead(A0);
      delay(2);          
      
   
  if (gprsSerial.available())
    Serial.write(gprsSerial.read());

  gprsSerial.println("AT");
  delay(1000);

  gprsSerial.println("AT+CPIN?");
  delay(1000);

  gprsSerial.println("AT+CREG?");
  delay(1000);

  gprsSerial.println("AT+CGATT?");
  delay(1000);

  gprsSerial.println("AT+CIPSHUT");
  delay(1000);

  gprsSerial.println("AT+CIPSTATUS");
  delay(2000);

  gprsSerial.println("AT+CIPMUX=0");
  delay(2000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CSTT=\"myAPN\"");//start task and setting the APN,
  delay(1000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIICR");//bring up wireless connection
  delay(3000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIFSR");//get local IP adress
  delay(2000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSPRT=0");
  delay(3000);
 
  ShowSerialData();
  
  gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
  delay(6000);
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSEND");//begin send data to remote server
  delay(4000);
  ShowSerialData();
  
    String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0" + String(temp);
  gprsSerial.println(temp);//begin send data to remote server
  delay(4000);
  ShowSerialData();

  gprsSerial.println((char)26);//sending
  delay(5000);//waitting for reply, important! the time is base on the condition of internet 
  gprsSerial.println();
 
  ShowSerialData();
 
  gprsSerial.println("AT+CIPSHUT");//close the connection
  delay(100);
  ShowSerialData();
} 
void ShowSerialData()
{
  while(gprsSerial.available()!=0)
    Serial.write(gprsSerial.read());
}
Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
2
February 13, 2018 - 7:36 pm
sp_Permalink sp_Print sp_EditHistory

Should this line 

gprsSerial.println(temp);//begin send data to remote server

be 

gprsSerial.println(str);//begin send data to remote server

 

and I think

 String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0" + String(temp);

should be

String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=" + String(temp);

Although a leading zero probably wont make a difference.

If that doesn't help, please post the serial output too.

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
3
February 14, 2018 - 10:13 am
sp_Permalink sp_Print

    String str="GET https://api.thingspeak.com/update?api_key=421TXMLMB71W7Q3G&field1=0" + String(temp);
  mySerial.println(temp);//begin send data to remote server

Thanks for the reply. I realized that change had to be made and thanks for pointing that out.

String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=" + String(temp);

Tried this but still no change. I am using a DHT 11 temperature sensor connected to digital pin 2

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
4
February 14, 2018 - 2:31 pm
sp_Permalink sp_Print

Can you show what the serial monitor says for this line?

gprsSerial.println(temp);//begin send data to remote server

or do something like Serial.println(temp) so we can see what the format of the request is exactly when it is sent?

Do you get no update at all on your channel, or still just incorrect numbers?

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
5
February 14, 2018 - 3:43 pm
sp_Permalink sp_Print sp_EditHistory

SEND OK
347
AT+CIPSHUT

SHUT OK
AT+CREG?

+CREG: 0,1

OK
AT+CGATT?AT+CSTT="myApn"

OK
AT+CIICR

OK
AT+CIFSR

10.224.152.203
AT+CIPSPRT=0

OK
AT+CIPSTART="TCP","api.thingspeak.com","80"

OK

CONNECT OKAT+CIPSEND
GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&amp;

SEND OK
348

 

This is what the serial monitor says. And yes I get an update on the channel but incorrect values.

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
6
February 14, 2018 - 3:47 pm
sp_Permalink sp_Print sp_EditHistory

AT
AT+CPIN?
AT+CREG?
AT+CGATT?
AT+CIPSHUT
AT+CIPSTATUS
ATAT+CSTT="myApn"
AT+CIICR
AT+CIFSR
AT+CIPSPRT=0
AT+CIPSTART="TCP","api.thingspeak.com","80"
AT+CIPSEND
Temperature = 23.00
GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&amp;

SEND OK
359

This is what I am seeing on the serial monitor as I added:

Serial.print("Temperature = ");
Serial.println(DHT.temperature);

But the value I am seeing on thingspeak is 325.

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
7
February 14, 2018 - 4:57 pm
sp_Permalink sp_Print

Sorry, I repeated the same mistake I pointed out in your code above!

I meant for you to print str, not temp.

Can you add Serial.println(str) and share the output?

My concern is that I don't see the value, or even field1= at the end of the string you showed.

GET https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&amp;

I am looking for something similar to this:

GET https://api.thingspeak.com/update?api_key=XXXXXXXXXXXXXXXX&field1=23;

If the buffer is getting filled, you can try it in shorter segments. 

perhaps

gprsSerial.print("GET https://api.thingspeak.com/update");//begin send data to remote server

gprsSerial.println("?api_key=XXXXXXXXXXXXXXXX&field1=23");

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
8
February 14, 2018 - 7:17 pm
sp_Permalink sp_Print

cstapels said

Sorry, I repeated the same mistake I pointed out in your code above!

I meant for you to print str, not temp.

Can you add Serial.println(str) and share the output?

Hello no need to apologize, I am really grateful for the help and advice.

I added the Serial.println(str) and this is what I got on the serial monitor:

CONNECT OKAT+CIPSEND

GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=01.00

Temperature = 25.00

GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&amp;

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
9
February 15, 2018 - 9:53 am
sp_Permalink sp_Print

Does that code result in the value 1.00 being added to ThingSpeak? I realize that 25.00 is the value you want, but what you showed was requesting a value of 1.00 to be written.  

If all that is true, then either temp is not being updated before it gets added to str or there may be a memory problem using the string class.

I would try just hard coding a number and making sure it writes correctly to ThingSpeak first.  

you can write
 str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=123"

 then 

gprsSerial.println(str);

and make sure you see the value 123.

 

I am also curious about this line after you write the GET request:

gprsSerial.println((char)26);//sending 

why are you sending the value 26?

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
10
February 15, 2018 - 10:07 am
sp_Permalink sp_Print

#include <SoftwareSerial.h>
#include <String.h>
#include <dht.h>
int sensorPin = 0; // set the input pin for the potentiometer
int sensorValue = 0;

dht DHT;

#define DHT11_PIN A0

SoftwareSerial gprsSerial(7,8);

 

float temp=0.0;

void setup()
{
gprsSerial.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate

delay(1000);
}

void loop()
{
temp=analogRead(A0);
temp=temp*0.4887;
delay(2);

if (gprsSerial.available())
Serial.write(gprsSerial.read());

gprsSerial.println("AT");
delay(1000);

gprsSerial.println("AT+CPIN?");
delay(1000);

gprsSerial.println("AT+CREG?");
delay(1000);

gprsSerial.println("AT+CGATT?");
delay(1000);

gprsSerial.println("AT+CIPSHUT");
delay(1000);

gprsSerial.println("AT+CIPSTATUS");
delay(2000);

gprsSerial.println("AT+CIPMUX=0");
delay(2000);

ShowSerialData();

gprsSerial.println("AT+CSTT=\"myApn\"");//start task and setting the APN,
delay(1000);

ShowSerialData();

gprsSerial.println("AT+CIICR");//bring up wireless connection
delay(3000);

ShowSerialData();

gprsSerial.println("AT+CIFSR");//get local IP adress
delay(2000);

ShowSerialData();

gprsSerial.println("AT+CIPSPRT=0");
delay(3000);

ShowSerialData();

gprsSerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);

ShowSerialData();

gprsSerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();

String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0" + String(temp);
Serial.println(str);
gprsSerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();

gprsSerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
gprsSerial.println();

ShowSerialData();

gprsSerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}
void ShowSerialData()
{
while(gprsSerial.available()!=0)
Serial.write(gprsSerial.read());

 

int chk = DHT.read11(DHT11_PIN);
Serial.print("Temperature = ");
Serial.println(DHT.temperature);
Serial.print("Humidity = ");
Serial.println(DHT.humidity);
delay(5000);
sensorValue = analogRead(sensorPin);
delay(1000);
Serial.print("sensor = " );
Serial.println(sensorValue);
sensorValue = analogRead(sensorPin);
delay(5000);
Serial.print("sensor = " );
Serial.println(sensorValue);
}

This is the new code I uploaded and I placed the Serial.print("Temperature = "); code lines to the end of the code.

After using this code, the serial monitor shows this:

OK
CONNECT OKTemperature = 28.00
Humidity = 74.00
sensor = 1023
sensor = 1023
AT+CIPSEND
Temperature = 28.00
Humidity = 75.00
sensor = 1023
sensor = 1023
GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0499.94
GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&Temperature = 28.00
Humidity = 74.00
sensor = 1023
sensor = 1023
SEND OK
523Temperature = 28.00
Humidity = 74.00
sensor = 1023
sensor = 1023
CLOSED
Temperature = -999.00
Humidity = -999.00

 Based on what you said you were not seeing, I am now able to see:

GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0499.94
GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&Temperature = 28.00

as shown above. The problem is that the 28 value is not uploaded to thingspeak but the value I am seeing seems to be the 499.94.

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
11
February 15, 2018 - 10:32 am
sp_Permalink sp_Print

why are you sending the value 26?  

This line came with the code I sampled and made my adjustment too. I am yet to figure out what exactly it does

Avatar
cstapels
Moderator
Forum Posts: 158
sp_UserOfflineSmall Offline
12
February 16, 2018 - 9:44 am
sp_Permalink sp_Print

At the top of your loop, you have

temp=analogRead(A0);
temp=temp*0.4887;

If you want the value written to ThingSpeak to be 28, then set these lines to be

temp=(DHT.temperature);  ,

 

The value of 26 (gprsSerial.println((char)26);//sending ) may be a number of bytes sent.  I would try removing it and then investigating the difference.

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
13
February 17, 2018 - 3:17 pm
sp_Permalink sp_Print

cstapels said

The value of 26 (gprsSerial.println((char)26);//sending ) may be a number of bytes sent.  I would try removing it and then investigating the difference.  

Based on research this char 26 indicated the end of data.

Thanks again for your feedback. Based on your last reply I made some adjustments to the code and Eureka I got it to work. I removed the following code lines altogether:

float temp=0.0

temp=analogRead(A0);
temp=temp*0.4887;

and just replaced  (temp) with (dht.temperature) in code line:

String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=" + String(DHT.temperature);

With this, the temperature value is uploaded to thingspeak correctly. The sensor also has a humidity value and I would like to upload that to a second field on the channel, so I would get both temperature and humidity uploaded on two fields. I tried several adjustments to the code but no luck with the two values upload. Advice with this would be appreciated.

Avatar
seales

Silver
Forum Posts: 9
sp_UserOfflineSmall Offline
14
February 18, 2018 - 6:39 pm
sp_Permalink sp_Print

String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1="+String(DHT.temperature)+"?api_key=QT7O3U5O8HFEFBY8&field2="+String(DHT.humidity) ;

With more trial and error I got the two values to upload simultaneously. thanks once again for all the advice

Forum Timezone: America/New_York

Most Users Ever Online: 114

Currently Online:
32 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 252

Vinod: 164

cstapels: 96

piajola: 75

vespapierre: 63

Adarsh_Murthy: 59

Newest Members:

aogomaeqaza

ureomug

itixuwidouzuv

eilimir

memozupi

isejfujajku

Forum Stats:

Groups: 4

Forums: 17

Topics: 1313

Posts: 4565

 

Member Stats:

Guest Posters: 1

Members: 5703

Moderators: 0

Admins: 2

Administrators: Hans, lee