Hi friends,
I'm try to make a project with rain gauge, i set code for the rain gauge without sim900 and its work very will
this :
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
const int REED = 9; //The reed switch outputs to digital pin 9
int val = 0; //Current value of reed switch
int old_val = 0; //Old value of reed switch
int REEDCOUNT = 0;
double RED = 0;//This is the variable that hold the count of switching
void setup(){
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
delay(3000); // wait for console opening
if (! rtc.begin()) {
while (1);
}
Serial.begin(9600);
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
pinMode (REED, INPUT_PULLUP); //This activates the internal pull up resistor
}
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
void loop(){
val = digitalRead(REED); //Read the status of the Reed swtich
DateTime now = rtc.now();
if ((val == LOW) && (old_val == HIGH)){ //Check to see if the status has changed
delay(10); // Delay put in to deal with any "bouncing" in the switch.
REEDCOUNT = REEDCOUNT + 1; //Add 1 to the count of bucket tips
RED = (REEDCOUNT*0.2794);
old_val = val; //Make the old value equal to the current value
Serial.print("Rainfall = ");
Serial.println(RED); //Output the count to the serial monitor
Serial.println("mm");
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
}
if((now.hour()== 0)&&(now.minute()== 0)) {
software_Reset() ;
}
else {
old_val = val; //If the status hasn't changed then do nothing
}
}
and i set the sim900 code without the rain gauge and its working normally
this one:
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7, 3);
void setup()
{
gprsSerial.begin(19200);
Serial.begin(19200);
Serial.println("OFFAS is Conecting...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
}
void loop()
{
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(100);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"taif\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
delay(100);
// set http param value
gprsSerial.print("AT+HTTPPARA=\"URL\",\"http:/xxxxxx/xxxxx/write_data.php?");
gprsSerial.print("data1=");
gprsSerial.print("11");
gprsSerial.print("&data2=");
gprsSerial.print("66");
gprsSerial.println("\"");
delay(2000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=0");
delay(6000);
toSerial();
// read server response
gprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300);
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
but when I'm try to put them together it did not work and give me "0" on database
im try on this way
#include <SoftwareSerial.h>
SoftwareSerial gprsSerial(7, 3);
#include <Wire.h>
#include "RTClib.h"
RTC_DS3231 rtc;
const int REED = 9; //The reed switch outputs to digital pin 9
int val = 0; //Current value of reed switch
int old_val = 0; //Old value of reed switch
int REEDCOUNT = 0;
double RED = 0;//This is the variable that hold the count of switching
void setup()
{
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
delay(3000); // wait for console opening
if (! rtc.begin()) {
while (1);
}
gprsSerial.begin(19200);
Serial.begin(19200);
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
Serial.println("OFFAS is Conecting...");
delay(2000);
Serial.println("Done!...");
gprsSerial.flush();
Serial.flush();
pinMode (REED, INPUT_PULLUP); //This activates the internal pull up resistor
}
void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
asm volatile (" jmp 0");
}
void loop()
{
delay(100);
val = digitalRead(REED); //Read the status of the Reed swtich
delay(100);
toSerial();
DateTime now = rtc.now();
delay(100);
if ((val == LOW) && (old_val == HIGH)){ //Check to see if the status has changed
delay(10); // Delay put in to deal with any "bouncing" in the switch.
REEDCOUNT = REEDCOUNT + 1; //Add 1 to the count of bucket tips
toSerial();
RED = (REEDCOUNT*0.2794);
toSerial();
old_val = val; //Make the old value equal to the current value
toSerial();
}
delay(100);
// attach or detach from GPRS service
gprsSerial.println("AT+CGATT?");
delay(100);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=3,1,\"APN\",\"taif\"");
delay(2000);
toSerial();
// bearer settings
gprsSerial.println("AT+SAPBR=1,1");
delay(2000);
toSerial();
// initialize http service
gprsSerial.println("AT+HTTPINIT");
delay(2000);
toSerial();
delay(100);
// set http param value
gprsSerial.print("AT+HTTPPARA=\"URL\",\"http://xxxxxxx/xxxx/write_data.php?");
gprsSerial.print("data1=");
gprsSerial.print(RED); //Output the count to the serial monitor
gprsSerial.print("&data2=");
gprsSerial.print(now.hour(), DEC);
gprsSerial.println("\"");
delay(2000);
toSerial();
// set http action type 0 = GET, 1 = POST, 2 = HEAD
gprsSerial.println("AT+HTTPACTION=0");
delay(6000);
toSerial();
// read server response
gprsSerial.println("AT+HTTPREAD");
delay(1000);
toSerial();
gprsSerial.println("");
gprsSerial.println("AT+HTTPTERM");
toSerial();
delay(300)
gprsSerial.println("");
delay(10000);
}
void toSerial()
{
while(gprsSerial.available()!=0)
{
Serial.write(gprsSerial.read());
}
}
i will be very thankful if anyone can help me, because I'm try more than 5 way and all of it dose not work