Good evening all,
I am trying to send data to ThingSpeak using a Makerfabs 4g LTE and arduino IDE.
Makerfabs board: https://www.makerfabs.com/maduino-zero-4g-lte-sim7600.html
Sensor: Ultrasonic sensor SEN0311.
Using the code from https://how2electronics.com/http-post-with-sim7600-arduino-send-data-to-server/, I have managed to send temp and humidity data (from a DTH11) to Thingspeak. Also copied below (note, I have added my Thingspeak API in my code).
I have got the SEN0311 working on my arduino UNO R3 using the code from https://wiki.dfrobot.com/_A02YYUW_Waterproof_Ultrasonic_Sensor_SKU_SEN0311 (also below), but I cannot get it to work on the Makerfabs board. I receive the error message “Compilation error: SoftwareSerial.h: No such file or directory”.
I would be super grateful if this community could help me answer 2 questions please:
- How do I get the SEN0311 working on Makerfabs board? Is it possible or is it a hardware issue?
- How do I integrate these codes to send the SEN0311 data to thingspeak?
Thank you in advance for your help.
CODE 1: Send DHT11 data to thingspeak:
#include <stdio.h>
#include <string.h>
#include <DHT.h>
//Change the API key to yours
String Apikey = "XXXXXXXXXX";
#define DEBUG true
#define LTE_RESET_PIN 6
#define LTE_PWRKEY_PIN 5
#define LTE_FLIGHT_PIN 7
#define Sensor_PIN 3 //D3-DHT11
DHT dht(Sensor_PIN,DHT11);
void setup()
{
SerialUSB.begin(115200);
//while (!SerialUSB)
{
; // wait for Arduino serial Monitor port to connect
}
Serial1.begin(115200);
//Serial1.begin(UART_BAUD, SERIAL_8N1, MODEM_RXD, MODEM_TXD);
pinMode(LTE_RESET_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
pinMode(LTE_PWRKEY_PIN, OUTPUT);
digitalWrite(LTE_RESET_PIN, LOW);
delay(100);
digitalWrite(LTE_PWRKEY_PIN, HIGH);
delay(2000);
digitalWrite(LTE_PWRKEY_PIN, LOW);
pinMode(LTE_FLIGHT_PIN, OUTPUT);
digitalWrite(LTE_FLIGHT_PIN, LOW);//Normal Mode
delay(5000);
/*ModuleState = moduleStateCheck();
if (ModuleState == false) //if it's off, turn on it.
{
digitalWrite(PWR_KEY, LOW);
delay(3000);
digitalWrite(PWR_KEY, HIGH);
delay(10000);
SerialUSB.println("Now turnning the SIM7600 on.");
}*/
sendData("AT+CCID", 3000, DEBUG);
sendData("AT+CREG?", 3000, DEBUG);
sendData("AT+CGATT=1", 1000, DEBUG);
sendData("AT+CGACT=1,1", 1000, DEBUG);
sendData("AT+CGDCONT=1,"IP","wap.vodafone.co.uk"", 1000, DEBUG);
//sendData("AT+CIPSTART="TCP","www.mirocast.com",80", 2000, DEBUG);
SerialUSB.println("4G HTTP Test Begin!");
dht.begin();
delay(1000);
}
void loop()
{
//--------Get temperature and humidity-------------
float h = dht.readHumidity();
float t = dht.readTemperature();
SerialUSB.print("Humidity: ");
SerialUSB.print(h);
SerialUSB.println("%");
SerialUSB.print("Temperature: ");
SerialUSB.print(t);
SerialUSB.println("*C");
delay(1000);
//-----------HTTP---------------------
String http_str = "AT+HTTPPARA="URL","https://api.thingspeak.com/update?api_key=" + Apikey + "&field1=" + (String)t + "&field2=" + (String)h + ""rn";
SerialUSB.println(http_str);
sendData("AT+HTTPINITrn", 2000, DEBUG);
sendData(http_str, 2000, DEBUG);
sendData("AT+HTTPACTION=0rn", 3000, DEBUG);
sendData("AT+HTTPTERMrn", 3000, DEBUG);
delay(5000);
}
bool moduleStateCheck()
{
int i = 0;
bool moduleState = false;
for (i = 0; i < 5; i++)
{
String msg = String("");
msg = sendData("AT", 1000, DEBUG);
if (msg.indexOf("OK") >= 0)
{
SerialUSB.println("SIM7600 Module had turned on.");
moduleState = true;
return moduleState;
}
delay(1000);
}
return moduleState;
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
Serial1.println(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (Serial1.available())
{
char c = Serial1.read();
response += c;
}
}
if (debug)
{
SerialUSB.print(response);
}
return response;
**CODE 2: SEN0311 on Arduino UNO. **
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11,10); // RX, TX
unsigned char data[4]={};
float distance;
void setup()
{
Serial.begin(57600);
mySerial.begin(9600);
}
void loop()
{
do{
for(int i=0;i<4;i++)
{
data[i]=mySerial.read();
}
}while(mySerial.read()==0xff);
mySerial.flush();
if(data[0]==0xff)
{
int sum;
sum=(data[0]+data[1]+data[2])&0x00FF;
if(sum==data[3])
{
distance=(data[1]<<8)+data[2];
if(distance>30)
{
Serial.print("distance=");
Serial.print(distance/10);
Serial.println("cm");
}else
{
Serial.println("Below the lower limit");
}
}else Serial.println("ERROR");
}
delay(100);
}
I was able to send temp and humidity data to thingspeak. I plugged the SEN0311 to the Makerfabs board (Black > GND, Red > 3.3v, Green > 11, Blue > 10) and was expecting to use the same code that worked for the arduino UNO.