[RESOLVED] How to send data from my Arduino to Thingspeak using a GSM SIM800c ?
Show older comments
Hello :)
This is my first big project using Arduino components, so I don't really understand everything, that's why I encounter so many difficulties.
My goal is to send data from my ultrasonic sensor (HC-SR04) to Thingspeak using an Arduino UNO and a GSM SIM800c.
Material :
- Arduino UNO ;
- GSM SIM 800c shield (https://www.eagle-robotics.com/accueil/257-shield-sim800c-arduino.html) ;
- Ultrasonic sensor (HC-SR04) ;
- Cables for my ultrasonic sensor ;
- Cable to connect my Arduino to my computer.
I want to send data to Thinspeak from everywhere, so I can't use Wifi. I found a solution on google : https://github.com/707amitkumar/Send-Data-on-cloud-using-gsm-800c/blob/main/gsmangthingspeak.txt
In order to send data to my channel on thingspeak, I did use the code mentionned on the link and I just changed the part concerning the data to send (because I want to send data from my ultrasonic sensor) :
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7,8);
#include <String.h>
#include <HCSR04.h>
const int trigPin = 2 ;
const int echoPin = 3 ;
UltraSonicDistanceSensor distanceSensor(trigPin, echoPin) ;
void setup()
{
gprsSerial.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate
delay(1000);
}
void loop()
{
float distance = distanceSensor.measureDistanceCm();
Serial.print("Distance = ");
Serial.print(distance);
Serial.println(" cm");
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=\"tango.lu\"");//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=F2WFEAUL58M062LM&field1=0" + String(distance) ;
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());
delay(5000);
}
When I run this code to my Arduino, I notice 2 problems :
- The piece of information is "sent" to my Thingspeak Channel but it doesn't match with the data sent from my sensors (It always show "0" on Thingspeak while the sensor sends a positive value :

2. I can notice that my code doesn't run as well as expected because the Serial Monitor dislay this :

I really don't kow what to do... And I thank you in advance for any help you may give me.
I hope my english is not so bad and you cand understand me :)
I wish you a good day,
Cécilia.
2 Comments
L.Manoj
on 29 Jul 2024
Compilation error: 'UltraSonicDistanceSensor' does not name a type
Christopher Stapels
on 29 Jul 2024
Might mean you dont have the library installed.
Accepted Answer
More Answers (0)
Communities
More Answers in the ThingSpeak Community
Categories
Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!