Anyone encountered the same issue whereby the Flow sensor doesn't send the correct data to the serial monitor and the Bluetooth Low Energy does not work with other Pins?
Here is my code:
#include <SoftwareSerial.h> //including Software Serial Library.
//#define txPin 1
//#define rxPin 0
//#define sensorPin 2 //Digital pin 6
//SoftwareSerial HM10(rxPin, txPin); //The pins Rx and Tx as default to keystudio shield
int sensorInterrupt = 0; // interrupt 0 interrupting the execution of a program in order to take care of something else
int sensorPin = 2; //Digital Pin 4
int solenoidValve = 5; // Digital pin 5
unsigned int SetPoint = 400; //400 milileter
/*The hall-effect flow sensor outputs pulses per second per litre/minute of flow.*/
float calibrationFactor = 90; //You can change according to your datasheet
volatile byte pulseCount =0;
float flowRate = 0.0;
unsigned int flowMilliLitres =0;
unsigned long totalMilliLitres = 0;
unsigned long oldTime = 0;
void setup()
{
// Initialize a serial connection for reporting values to the host
Serial.begin(9600);
// HM10.begin(9600); // begin bluetooth serial port communication
Serial.println("HM10 serial started at 9600");
pinMode(solenoidValve , OUTPUT);
digitalWrite(solenoidValve, HIGH);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
/*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);
//you can use Rising or Falling
}
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(flowMilliLitres, DEC); // Print the integer part of the variable
Serial.print("mL/Second");
Serial.print("\t");
// Print the cumulative total of litres flowed since starting
Serial.print("Output Liquid Quantity: ");
Serial.print(totalMilliLitres,DEC);
Serial.println("mL");
Serial.print("\t");
if (totalMilliLitres > 40)
{
SetSolinoidValve();
}
// 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()
{
// Increment the pulse counter
pulseCount++;
}
void SetSolinoidValve()
{
digitalWrite(solenoidValve, LOW);
}
What would that be? Links to its datasheet please. The world is full of flow sensors of different kinds.
I used one 30 years ago and it needed special care...
The code for Flow meter looks OK, but just check that you are using a kosher pin for interrupt. That for Bluetooth is junk. You have to make up your mind as to whether you want to use hardware serial or software serial, but you cannot use software serial on the hardware serial pins 0,1. Also, you appear to be using HM-10 with HC-05 code. I don't think that will work and, if it looks like it will, I still wouldn't trust it. I'm afraid I don't know anything about using BLE as a plain-vanilla SPP device.
I find displaying flow Rate at one second intervals makes it impossible to read.
Okey, You tried. That's not a datasheet but someone showing how to connect it. The characteristics showing pulses per unit volume at different flows is what I hoped to read.
Usually sensors like this are highly none linear. That means the number of pulses per volume varies a lot depending on the flow. High flow, one puls per volume, low flow less pulses per the same volume.
Using pin 3 as digital pin for the flow sensor compiles and works properly,
int sensorInterrupt = 0; // interrupt 0 interrupting the execution of a program in order to take care of something else
int sensorPin = 3; //Digital Pin 3
int solenoidValve = 5; // Digital pin 5
unsigned int SetPoint = 400; //400 milileter
Now to connect the Bluetooth Shield doesn't display my values on the serial monitor nor on my custom app
I understand that, however is it possible if i change the interrupt pin to another value:
int sensorInterrupt = 6;
I tried and the Monitor reads:
09:45:36.927 -> Flow rate: 0mL/Second Output Liquid Quantity: 0mL
09:45:37.923 -> Flow rate: 0mL/Second Output Liquid Quantity: 0mL
No, you don't make sense. I understand your flow meter works properly, so I don't understand why it is being discussed. Furthermore this:
is utter gibberish, but some points arise.
how do you know the flow meter works?
are you expecting the serial monitor to display results via Bluetooth?
God only knows, or won't dare guess, what the "custom app" is, but it will surely be best left out of the game and a standard Bluetooth terminal used to test the situation.
As noted above, the serial code is junk. There is no indication of what pins are used for Bluetooth, just a hint they are probably the wrong ones. You have included the Software serial library but you are not using it, there is no hint of what your wiring might be like, and no hint of what your intentions are either.
A proof of what the code is up to is in the single line
which is just a meaningless lie.
If your communication is between Arduino and phone only, it is quite OK to have Bluetooth on pins 0,1 hardware serial, preferable even, but you may need to have Bluetooth disconnected when you upload your programme. If you use software serial, it seems that altsoft serial is the preferred library when using HM-10.
@Nick_Pyner Thank you nick for your input but since you stated " I'm afraid I don't know anything about using BLE as a plain-vanilla SPP device." Then your input is irrelevant.
This project needs to read data from a water flow sensor.
The flow sensor should the pass on the parameters to the HM-10 Bluetooth shield Module that stacked on the arduino board.
I'm not familiar with using BLE for spp data, but that doesn't alter the fact that you don't know what you are doing, and your serial/Bluetooth code is junk. For all that, I might point out that my comment about using "HC-05 code for HM-10" is probably not well-founded, as the latter have been upgraded in recent times. Once you make a proper decision about what you want to do, you will probably get what you need on the Martyn Currey website, where he specifically refers to HM-10.
(Ed)
On second thoughts, you might as well check Currey's HM-10 notes before you sort out which serial path you want to go down...
No comment on your "custom app", and none warranted. The picture looks like a standard terminal by Karl Morisch, which is fine.