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 go a step further and upload the moisture and temperature values online. This is the part I am having difficulty with. I have tried to upload to temboo, thingspeak and google sheets via pushingbox. The only luck I had was using thingspeak. Unfortunately, the values loaded are not the values I am seeing on the serial monitor. The values are upward of 500 on the online chart but 29 on the Arduino serial monitor. I am using a GSM 900 shield, any advice with respect to uploading my data online for remote monitoring would be greatly appreciated.
Attached is the code i used for uploading to thingspeak.
#include <SoftwareSerial.h>
#include <String.h>
SoftwareSerial mySerial(11,12);
boolean pin2=LOW,pin3=LOW,pin4=LOW,pin5=LOW,pin6=LOW;
float temp=0.0;
void setup()
{
mySerial.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate
pinMode(2,INPUT);
pinMode(3,INPUT);
pinMode(4,INPUT);
pinMode(5,INPUT);
pinMode(6,INPUT);
delay(1000);
}
void loop()
{
temp=analogRead(A0);
temp=temp*0.4887;
delay(2);
Send2Pachube();
if (mySerial.available())
Serial.write(mySerial.read());
}
void Send2Pachube()
{
mySerial.println("AT");
delay(1000);
mySerial.println("AT+CPIN?");
delay(1000);
mySerial.println("AT+CREG?");
delay(1000);
mySerial.println("AT+CGATT?");
delay(1000);
mySerial.println("AT+CIPSHUT");
delay(1000);
mySerial.println("AT+CIPSTATUS");
delay(2000);
mySerial.println("AT+CIPMUX=0");
delay(2000);
ShowSerialData();
mySerial.println("AT+CSTT=\"myAPN\"");//start task and setting the APN,
delay(1000);
ShowSerialData();
mySerial.println("AT+CIICR");//bring up wireless connection
delay(3000);
ShowSerialData();
mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);
ShowSerialData();
mySerial.println("AT+CIPSPRT=0");
delay(3000);
ShowSerialData();
mySerial.println("AT+CIPSTART=\"TCP\",\"api.thingspeak.com\",\"80\"");//start up the connection
delay(6000);
ShowSerialData();
mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String str="GET https://api.thingspeak.com/update?api_key=421TXMLMB71W7Q3G&field1=0" + String(temp);
mySerial.println(str);//begin send data to remote server
delay(4000);
ShowSerialData();
mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();
ShowSerialData();
mySerial.println("AT+CIPSHUT");//close the connection
delay(100);
ShowSerialData();
}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}
Do you really have a mySerial connected to those pins? Can you post a picture of a mySerial?
Do you have a dog called myDog? A cat called myCat? A girlfriend called myGirlfriend? I seriously doubt it.
Why is the function to send data to thingsqueak called Send2Pachube()?
You know that you COULD Serial.print() the same stuff you are mySerial.print()ing, so you can see if the problem is on the sending end or on the receiving end.
Do you really have a mySerial connected to those pins? Can you post a picture of a mySerial?
Do you have a dog called myDog? A cat called myCat? A girlfriend called myGirlfriend? I seriously doubt it.
Why is the function to send data to thingsqueak called Send2Pachube()?
You know that you COULD Serial.print() the same stuff you are mySerial.print()ing, so you can see if the problem is on the sending end or on the receiving end.
Personally, I have ZERO use for Strings.
Thanks for the response. What you are saying is true and i have altered this code several times with little to no difference. This is the original code I started with therefore i wanted to post it and get advice based on the necessary corrections to be made. I have tried my best before asking for help as I know asking for help without trying is frowned upon. I have no programming experience but with research i was able to get the first part of the project functioning and with guidance from the more experienced guys on this platform I am hoping to get this part functioning. Thanks again for the reply.
#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());
}
Attempted adjusting the code, it works as I am still getting it to upload to thingspeak but I am not getting the temeprature value to reflect correctly.
I am guessing one of these lines may be the culprit or I am missing other lines entirely:
float temp=0.0;
int chk = DHT.read11(DHT11_PIN);
temp=analogRead(A0);
I am guessing one of these lines may be the culprit or I am missing other lines entirely:
I think that it is reasonable to guess that one of those lines, or one of the ones you didn't cite, or one of the ones that you don't have is where the problem is.
Now, you are using the DHT class for some reason. Presumably, you are using that class because you have some sensor that that class knows how to get data from. Is that a reasonable assumption?
If it is, why are you trying to read from the device like it is an analog device?
Now, even if you WERE getting a temperature as a result of reading the sensor that way (the analog reading is NOT a temperature), you have this code:
String str="GET https://api.thingspeak.com/update?api_key=QT7O3U5O8HFEFBY8&field1=0" + String(temp);
gprsSerial.println(temp);//begin send data to remote server
What data, exactly, are you sending to what server?
What was the reason for constructing that String?
When are you going to Serial.print() temp AND show us that data AND what appears in thingsqueak?
PaulS:
Now, you are using the DHT class for some reason. Presumably, you are using that class because you have some sensor that that class knows how to get data from. Is that a reasonable assumption?
If it is, why are you trying to read from the device like it is an analog device?
Now, even if you WERE getting a temperature as a result of reading the sensor that way (the analog reading is NOT a temperature), you have this code:
gprsSerial.println(temp);//begin send data to remote server
What data, exactly, are you sending to what server?
What was the reason for constructing that String?
When are you going to Serial.print() temp AND show us that data AND what appears in thingspeak?
Hey, thanks for the reply once again. I see that you're pointing me in the right direction based on your questions and I appreciate that. I just hope to figure it out soon lol.
The sensor I am using is the DHT11 temperature sensor.
Based on your other question, I should move the sensor from the analog pin to a digital pin.
The temperature reading is the data I want to upload to thingspeak.
As for the string, this was taken from the only code I got to work partially. Also based on your question you are hinting that I can upload without a string.
The DHT11 has three lines: GND, +5V and a single data line. By means of a handshake, the values are clocked out over the single digital line.
See that bit about "handshaking" and "clocked out"? It doesn't say that the module produces an analog output. It doesn't mean that digitalRead() will be useful.
There is a library, available from that page, and examples, that show how to properly get the temperature from that sensor.
Anonymous serial printing sucks. You have no way of knowing what you sent to the other device vs. what you read from the other device.
Writing to the serial port is NOT sufficient for the other device to know what you want to do.
I don't see where the other device learns that you want to make a GET request. All it knows, from what I can see, is that you have a temperature.
Of course I mean the GSM modem when I say "other device".
When you print something to the serial port, indicate in some way what is a response from the modem, and what is debug information.
Much thanks to you PaulS. As usual, I looked for the breadcrumbs in your post to figure where I am going wrong. Unfortunately, I was completely lost this time (no programming experience). Nevertheless, I checked the links you posted and again lost. I took to google to research the DHT11 sensor and found several claims of it being unreliable and troublesome. With this in mind, i decided to modify the code to work with my moisture sensor. Uploaded the new code and Eureka, it worked. I was able to upload the values to thingspeak and it was trending accurately.
I would still like to figure out how to get the temperature working as this is a great learning experience.