how to combine sim900 with waterflow sensor | ThingSpeak API | Forum

Avatar

Please consider registering
Guest

sp_LogInOut Log In sp_Registration Register

Register | Lost password?
Advanced Search

— Forum Scope —






— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

sp_Feed sp_TopicIcon
how to combine sim900 with waterflow sensor
No permission to create posts
December 7, 2018
4:43 am
Avatar
rizafajar
New Member
Members
Forum Posts: 4
Member Since:
July 27, 2018
sp_UserOfflineSmall Offline

I have a problem when combining a water flow sensor program with sim900. does anyone know this problem? it didn't work for several daysCryCry. when the program runs the LCD screen does not change in value.

#include
#include

SoftwareSerial mySerial(2, 3);

float temp=0.0;

void setup()
{
mySerial.begin(9600); // the GPRS baud rate
Serial.begin(9600); // the GPRS baud rate
delay(1000);
}

void loop()
{
temp=analogRead(A0);
temp=temp*0.4887;
delay(2);
Send2Pachube();

if (mySerial.available())
Serial.write(mySerial.read());
}
void Send2Pachube()
{
Serial.print("AT");
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=\"indosatgprs\"");//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=xxxxxxxxxxxxxxxxx&field1=" + String(temp);

//String str="GET https://api.thingspeak.com/update?api_key=xxxxxxxxxxxxxxxxx&field1=" + 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());
}

waterflow sensor

/*
Liquid flow rate sensor -DIYhacking.com Arvind Sanjeev

Measure the liquid/water flow rate using this code.
Connect Vcc and Gnd of sensor to arduino, and the
signal line to arduino digital pin 2.

*/

byte statusLed = 13;

byte sensorInterrupt = 0; // 0 = digital pin 2
byte sensorPin = 2;

// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;

volatile byte pulseCount;

float flowRate;
unsigned int flowMilliLitres;
unsigned long totalMilliLitres;

unsigned long oldTime;

void setup()
{

// Initialize a serial connection for reporting values to the host
Serial.begin(9600);

// Set up the status LED line as an output
pinMode(statusLed, OUTPUT);
digitalWrite(statusLed, HIGH); // We have an active-low LED attached

pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);

pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
totalMilliLitres = 0;
oldTime = 0;

// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}

/**
* Main program loop
*/
void loop()
{

if((millis() - oldTime) > 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);

// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;

// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();

// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;

// Add the millilitres passed in this second to the cumulative total
totalMilliLitres += flowMilliLitres;

unsigned int frac;

// Print the flow rate for this second in litres / minute
Serial.print("Flow rate: ");
Serial.print(int(flowRate)); // Print the integer part of the variable
Serial.print("L/min");
Serial.print("\t"); // Print tab space

// Print the cumulative total of litres flowed since starting
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres);
Serial.println("mL");
Serial.print("\t"); // Print tab space
Serial.print(totalMilliLitres/1000);
Serial.print("L");

// Reset the pulse counter so we can start incrementing again
pulseCount = 0;

// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}

/*
Insterrupt Service Routine
*/
void pulseCounter()
{

December 11, 2018
11:35 am
Avatar
cstapels
Moderator
Members


Moderators
Forum Posts: 512
Member Since:
March 7, 2017
sp_UserOfflineSmall Offline

Does your ThingSpeak channel update as you expect?

December 17, 2018
6:59 am
Avatar
rizafajar
New Member
Members
Forum Posts: 4
Member Since:
July 27, 2018
sp_UserOfflineSmall Offline

a little problem due to delay from sim900. value does not match what I expected. for example, measured in the serial monitor 45 degrees Celsius but at thingspeak 0.45 degrees Celsius. how do I change the delay to millis. I tried it and it didn't work.

void Send2Pachube()
{
Serial.print("AT");
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);

please help meCryCryCry

Forum Timezone: America/New_York

Most Users Ever Online: 166

Currently Online:
38 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

rw950431: 272

Vinod: 240

piajola: 95

turgo: 70

vespapierre: 63

Adarsh_Murthy: 62

Member Stats:

Guest Posters: 1

Members: 8665

Moderators: 1

Admins: 2

Forum Stats:

Groups: 3

Forums: 14

Topics: 1600

Posts: 5760

Newest Members:

Bbet1814On, Konstantintus, inalv69, bryancv1, priscillaql69, gay porn

Moderators: cstapels: 460

Administrators: Hans: 405, lee: 457