hello my friends
I am trying to complete a project but i have problem with code.
I want to send SMS (pin code ex. 1234) to arduino and arduino must answer me with the values of the sensors.
So far i made to read sms to serial monitor but arduino doesnt answer to me.
here is the code
#include <gprs.h>
#include <SoftwareSerial.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
#define TIMEOUT 5000
float h = dht.readHumidity();
float t = dht.readTemperature();
GPRS gprs;
#include "HX711.h"
#define calibration_factor -17.2
#define DOUT 4
#define CLK 5
float value;
HX711 scale(DOUT, CLK);
void setup() {
Serial.begin(9600);
scale.set_scale(calibration_factor);
scale.tare(); //Assuming there is no weight on the load cell at start up, this resets the output to 0
value = scale.get_units(), 0;
while (!Serial);
dht.begin();
Serial.println("scanninig");
float h = dht.readHumidity();
float t = dht.readTemperature();
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %");
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" *C");
Serial.print(value);
Serial.println(" gramms");
Serial.println("Starting SIM800 SMS Command Processor");
gprs.preInit();
delay(1000);
while (0 != gprs.init()) {
delay(1000);
Serial.print("init error\r\n");
}
//Set SMS mode to ASCII
if (0 != gprs.sendCmdAndWaitForResp("AT+CMGF=1\r\n", "OK", TIMEOUT)) {
ERROR("ERROR:CNMI");
return;
}
//Start listening to New SMS Message Indications
if (0 != gprs.sendCmdAndWaitForResp("AT+CNMI=1,2,0,0,0\r\n", "OK", TIMEOUT)) {
ERROR("ERROR:CNMI");
return;
}
Serial.println("Init success");
}
//Variable to hold last line of serial output from SIM800
char currentLine[500] = "";
int currentLineIndex = 0;
void loop()
{
value = scale.get_units(), 0;
//If there is serial output from SIM800
if (gprs.serialSIM800.available()) {
char lastCharRead = gprs.serialSIM800.read();
//Read each character from serial output until \r or \n is reached (which denotes end of line)
if (lastCharRead == '\r' || lastCharRead == '\n') {
String lastLine = String(currentLine);
if (lastLine.startsWith("+CMT:")) {
Serial.println(lastLine);
nextLineIsMessage = true;
}
else if (lastLine.length() > 0) {
if (nextLineIsMessage) {
Serial.println(lastLine);
//Read message content and set status according to SMS content
if (lastLine.indexOf("MELI") >= 0) {
gprs.serialSIM800.write("AT+CMGF=1\r\n");
delay(1000);
gprs.serialSIM800.write("AT+CMGS=\"+306985123172\"\r\n");
delay(3000);
float h = dht.readHumidity();
float t = dht.readTemperature();
gprs.serialSIM800.print("Humidity: ");
gprs.serialSIM800.print(h);
gprs.serialSIM800.print(" %");
gprs.serialSIM800.println();
gprs.serialSIM800.print("Temperature: ");
gprs.serialSIM800.print(t);
gprs.serialSIM800.print(" C");
gprs.serialSIM800.println();
gprs.serialSIM800.print("Weight: ");
gprs.serialSIM800.print(value);
gprs.serialSIM800.print();
gprs.serialSIM800.print(" gramms");
delay(1000);
gprs.serialSIM800.write((char)26);
delay(1000);
Serial.println("SMS Sent!");
} nextLineIsMessage = false;
}
}
//Clear char array for next line of read
for ( int i = 0; i < sizeof(currentLine); ++i ) {
currentLine[i] = (char)0;
}
currentLineIndex = 0;
} else {
currentLine[currentLineIndex++] = lastCharRead;
}
}
}
can anyone help me???