arduino-uno


arduino uno R3 input pins with gsm shield


In my project i need to read input data from water flow sensor. It works well when i wire water flow with pin 2 or 3 , but does not work work when i wire it to any other pins. It becomes a problem because i need to use GSM shield and you know pins 2,3 and 7 reserved for arduino and modem
the code:
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
LiquidCrystal lcd(5, 6, 9, 10, 11, 12);
volatile int TopsFan; //measuring the rising edges of the signal
int result;
int pin = 2; //The pin location of the sensor
void rpm () //This is the function that the interrupt calls
{
TopsFan++; //This function measures the rising and falling edge of the hall effect sensors signal
}
// The setup() method runs once, when the sketch starts
void setup()
{
pinMode(pin, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the
serial port is initialized(USB port)
attachInterrupt(0, rpm, RISING); // the interrupt is attached
}
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("The water flow: "); // Print a message to the LCD.
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()
{
TopsFan = 0; //Set TopsFan to 0 ready for calculations
sei(); //Enables interrupts
delay (1000); //Wait 1 second
cli(); //Disable interrupts
result = (TopsFan * 60 / 7.5); //(Pulse frequency x 60) /
7.5Q, = flow rate in L/min
lcd.setCursor(0, 1); //prepare the cursor on the screen
lcd.print(result, DEC); //Prints the number calculated above
lcd.print(" L/min\r\n"); //Prints "L/min" and returns a new
line
}
Pls read https://www.arduino.cc/en/Reference/AttachInterrupt :
...
...
The first parameter to attachInterrupt is an interrupt number. Normally you should use digitalPinToInterrupt(pin) to translate the actual digital pin to the specific interrupt number. For example, if you connect to pin 3, use digitalPinToInterrupt(3) as the first parameter to attachInterrupt.
Board Digital Pins Usable For Interrupts
Uno, Nano, Mini, other 328-based 2, 3
...
...
It would seem you need to try a different approach, perhaps bypassing interrupts altogether. Something like the following:
#include <LiquidCrystal.h> // initialize the library with the numbers of the interface pins
int count_rpm(void) ;
LiquidCrystal lcd(5, 6, 9, 10, 11, 12);
int flow_pin = 5 ; //The pin location of the sensor (5 or whatever suits you)
// The setup() method runs once, when the sketch starts
void setup()
{
pinMode(flow_pin, INPUT); //initializes digital pin 2 as an input
Serial.begin(9600); //This is the setup function where the serial port is initialized(USB port)
lcd.begin(16, 2); // set up the LCD's number of columns and rows
lcd.print("The water flow: "); // Print a message to the LCD.
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop ()
{
int result;
result = (count_rpm() * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate in L/min
lcd.setCursor(0, 1); //prepare the cursor on the screen
lcd.print(result, DEC); //Prints the number calculated above
lcd.print(" L/min\r\n"); //Prints "L/min" and returns a new line
}
int count_rpm(void)
{
long start = millis() ;
int count = 0 ;
boolean current_state ;
boolean previous_state = digitalRead(flow_pin) ;
for( ; millis()-start <= 1000 ; )
{
current_state = digitalRead(flow_pin) ;
if (current_state && !previous_state)
count++ ;
previous_state = current_state ;
}
return count ;
}

Related Links

Error in using IF statement
Arduino not displaying results
Python ImportError: No module named yahoo_finance
Can I take solar panel's output as an input to Arduino
I cannot find UID of my Arduino
Arduino Program Reset Bug
arduino uno R3 input pins with gsm shield
Light weight machine to machine communication with Arduino
Interfacing RM5 evolution coin acceptor with arduino
Arduino-ESP8266 Sending URL from a client browser connected to the esp8266 AP and receiving the entered URL in the arduino board
Need explanations about a code relative to MPU6050
Arduino Programmer only works after unlugging and plugging back in
How do I communicate between Arduino board and Intel Edison Arduino board using XBee S2?
I cannot solve my arduino program error
2.4 inch TFT LCD SPFD5408 with Arduino Uno - touch not working
DAC0808 doesn't want tranfer to analog

Categories

HOME
ibm-bluemix
image
isabelle
mediawiki
push-notification
smarty
relative-path
yarn
ckeditor
cross-browser
django-imagekit
podio
python-unittest
google-translate
vifm
usergrid
fallback
telephony
foselasticabundle
openrefine
windows-7-x64
google-cloud-speech
openedx
viewport
firefox-webextensions
custom-wordpress-pages
amazonsellercentral
sox
mustache.php
pass-by-reference
tibco-mdm
restful-authentication
crosstab
sparse-matrix
bootstrap-duallistbox
entitlements
maxmind
typo3-6.2.x
xacml
elasticsearch-net
webkitspeechrecognition
lightswitch-2013
bluestacks
javascriptcore
siesta-swift
uiswipegesturerecognizer
geopositioning
environment-modules
overriding
reportbuilder
opshub
acoustics
slick-3.0
google-datalayer
rainbowtable
hibernate-tools
upstart
komodoedit
jquery-nestable
alphabet
directory-structure
nodebb
np-complete
dtexec
boost-preprocessor
linode
synchronous
pycaffe
yt-project
watchconnectivity
cubes
probability-density
gridview-sorting
ubuntu-10.04
actionbardrawertoggle
qgraphicsview
dataview
suffix-tree
cloudbees
phpcas
hsv
rtbkit
separator
metaclass
iis-arr
wyam
sysinternals
operation
createprocessasuser
nsight
angular-local-storage
inmobi
apache-commons-net
kineticjs
python-green
facebook-graph-api-v2.4
markers
websocket4net
rdl
monomac
ora-00911
chuck
errai
regsvr32
chrono
buildr
postgresql-performance
pydot
subgurim-maps
horizontal-accordion
cinema-4d
yui-datatable
google-friend-connect
infrastructure
revisions
database-management
adrotator
xetex
putchar
zune
windows-live-messenger

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App