Pages: [1]   Go Down
Author Topic: Water usage and cost. Please help me programming  (Read 1015 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have Arduino Leonardo, ethernet shield Wiznet w5100 with sd card and poe,water meter with impulse out Minomess ETK-M pulse - Pulse value 10 l/Imp, i ordered DS1307 RTC, LCD 16x2 and Ubuntu 12.04 web server.How to create something this? Help me program!
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you want someone to write the code for you then you would be better off asking in Gigs and Collaborations http://arduino.cc/forum/index.php/board,26.0.html
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Global Moderator
Netherlands
Online Online
Shannon Member
*****
Karma: 227
Posts: 14010
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


it can look a bit like this project - http://www.ladyada.net/make/logshield/lighttemp.html -
merged with a pulse counter - http://playground.arduino.cc/Main/EEM12L-32AKWhMonitoring -
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

https://github.com/adafruit/Adafruit-Flow-Meter/blob/master/Adafruit_FlowMeter.pde

This works ok but how to i add to this water cost? 1m3 = 2,76€
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You would need to calibrate the sensor so that you had an accurate reading in liters or cubic meters, and then multiply that by your cost-per-liter or cost-per-cubic-meter to calculate the corresponding cost.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code you posted a link to tells you how many litres of water have passed through the sensor.  You know how many litres there are in a cubic metre.  You know how much a cubic metre of water costs.  So, the cost is just a matter of doing the maths and outputting the result.

Have you tried any of the example scripts that came with the Arduino ?
The arithmetic operators, add, subtract, multiply, divide and others are described in the Arduino reference installed with the IDE and accessible from the IDE menu (Help/Reference)
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK. I will try. I have water meter with pulse sensor. 1 pulse = 1 litre
Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post your code here if you get stuck.

Don't waste too much water when testing it though !
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not want pulses and freguency. Lcd could be shown only to liters and price. Water cost is 1m3 = 2,76 € . Water meter 1 pulse = 1 litre


Code:
/**********************************************************
This is example code for using the Adafruit liquid flow meters.

Tested and works great with the Adafruit plastic and brass meters
    ------> http://www.adafruit.com/products/828
    ------> http://www.adafruit.com/products/833

Connect the red wire to +5V,
the black wire to common ground
and the yellow sensor wire to pin #2

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada  for Adafruit Industries.  
BSD license, check license.txt for more information
All text above must be included in any redistribution
**********************************************************/
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
  
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
  
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}

void setup() {
   Serial.begin(9600);
   Serial.print("Flow sensor test!");
   lcd.begin(16, 2);
  
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);
   useInterrupt(true);
}

void loop()                     // run over and over again
{
  lcd.setCursor(0, 0);
  lcd.print("Pulses:"); lcd.print(pulses, DEC);
  //lcd.print(" Hz:");
  lcd.print(flowrate);
  //lcd.print(flowrate);
  //Serial.print("Freq: "); Serial.println(flowrate);
  Serial.print("Pulses: "); Serial.println(pulses, DEC);
  
  // if a plastic sensor use the following calculation
  // Sensor Frequency (Hz) = 7.5 * Q (Liters/min)
  // Liters = Q * time elapsed (seconds) / 60 (seconds/minute)
  // Liters = (Frequency (Pulses/second) / 7.5) * time elapsed (seconds) / 60
  // Liters = Pulses / (7.5 * 60)
  float liters = pulses;
  //liters /= 7.5;
  //liters /= 60.0;

/*
  // if a brass sensor use the following calculation
  float liters = pulses;
  liters /= 8.1;
  liters -= 6;
  liters /= 60.0;
*/
  Serial.print(liters); Serial.println(" Liters");
  lcd.setCursor(0, 1);
  lcd.print(liters); lcd.print(" Liters        ");
 
  delay(100);
}


Moderator edit: [code] [/code] tags added.
« Last Edit: February 12, 2013, 01:24:05 am by Coding Badly » Logged

East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 118
Posts: 4398
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I do not want pulses and freguency. Lcd could be shown only to liters and price. Water cost is 1m3 = 2,76 €

As I said
Quote
The code you posted a link to tells you how many litres of water have passed through the sensor.  You know how many litres there are in a cubic metre.  You know how much a cubic metre of water costs.  So, the cost is just a matter of doing the maths and outputting the result.
Remove any other output that you don't want.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 
#include "LiquidCrystal.h"
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

// which pin to use for reading the sensor? can use any pin!
#define FLOWSENSORPIN 2


// count how many pulses!
volatile uint16_t pulses = 0;
// track the state of the pulse pin
volatile uint8_t lastflowpinstate;
// you can try to keep time of how long it is between pulses
volatile uint32_t lastflowratetimer = 0;
// and use that to calculate a flow rate
volatile float flowrate;
// Interrupt is called once a millisecond, looks for any pulses from the sensor!
SIGNAL(TIMER0_COMPA_vect) {
  uint8_t x = digitalRead(FLOWSENSORPIN);
 
  if (x == lastflowpinstate) {
    lastflowratetimer++;
    return; // nothing changed!
  }
 
  if (x == HIGH) {
    //low to high transition!
    pulses++;
  }
  lastflowpinstate = x;
  flowrate = 1000.0;
  flowrate /= lastflowratetimer;  // in hertz
  lastflowratetimer = 0;
}

void useInterrupt(boolean v) {
  if (v) {
    // Timer0 is already used for millis() - we'll just interrupt somewhere
    // in the middle and call the "Compare A" function above
    OCR0A = 0xAF;
    TIMSK0 |= _BV(OCIE0A);
  } else {
    // do not call the interrupt function COMPA anymore
    TIMSK0 &= ~_BV(OCIE0A);
  }
}

void setup() {
   Serial.begin(9600);
   Serial.print("Flow sensor test!");
   lcd.begin(16, 2);
   
   pinMode(FLOWSENSORPIN, INPUT);
   digitalWrite(FLOWSENSORPIN, HIGH);
   lastflowpinstate = digitalRead(FLOWSENSORPIN);
   useInterrupt(true);
}

void loop()                     // run over and over again
{
  lcd.setCursor(0, 0);
  lcd.print(pulses, DEC);    lcd.print("Liitrit");
 
 
  Serial.println(pulses, DEC);   Serial.print("Liitrit ");
 

  float liters = pulses;
  liters *= 0.00276;
 


  Serial.print(liters, DEC); Serial.println(" EUR-i");
  lcd.setCursor(0, 1);
  lcd.print(liters); lcd.print(" EUR-i");
 
  delay(100);
}



All working ok but water cost in EUR looks 0,0027600000222 (sample) . I need 0,00000 format. This line :   Serial.print(liters, DEC); Serial.println(" EUR-i");
  I convert pulses to liters and liters to cost.

Sorry my english.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

All working very well.
This line :   Serial.print(liters,DEC);    Serial.println(" EUR-i");
was wrong
 I write :   Serial.print(liters,5);    Serial.println(" EUR-i");
and cost is 0,00000
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glad you fixed it. For future reference, when posting code please enclose it in [ CODE ] [ /CODE ] tags. The # button in the editing window inserts these for you.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 23
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Okay.

Then i want to add ethernet shield and send data to web server.I have Wiznet w5100.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ever get this working with the Ethernet?
Logged

Pages: [1]   Go Up
Jump to: