Durchfluss Sensor auswerten


hallo,

ich würde gerne mit einem arduino uno und dem lcd schild einen durchflusssensor auswerten.
diesen code habe ich gefunden, die puls und herz interessieren mich eigentlich nicht.
mich interessieren die liter und leiter/min.

kann mir da jemand helfen?

lg
timon


code: [select]
#include "liquidcrystal.h"
liquidcrystal lcd(8, 9, 4, 5, 6, 7);

// pin use reading sensor? can use pin!
#define flowsensorpin 2

// count how many pulses!
volatile uint16_t pulses = 0;
// track state of pulse pin
volatile uint8_t lastflowpinstate;
// can try keep time of how long between pulses
volatile uint32_t lastflowratetimer = 0;
// , use calculate flow rate
volatile float flowrate;
// interrupt called once millisecond, looks pulses sensor!
signal(timer0_compa_vect) {
 uint8_t x = digitalread(flowsensorpin);
 
 if (x == lastflowpinstate) {
   lastflowratetimer++;
   return; // nothing changed!
 }
 
 if (x == high) {
   //low high transition!
   pulses++;
 }
 lastflowpinstate = x;
 flowrate = 1000.0;
 flowrate /= lastflowratetimer; // in hertz
 lastflowratetimer = 0;
}

void useinterrupt(boolean v) {
 if (v) {
   // timer0 used millis() - we'll interrupt somewhere
   // in middle , call "compare a" function above
   ocr0a = 0xaf;
   timsk0 |= _bv(ocie0a);
 } else {
   // not call 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 on , on 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 plastic sensor use 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 brass sensor use 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);
}

die liter pro minute werden ja ende des sketches angezeigt.
code: [select]
// if plastic sensor use 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;


welchen sensor hast du?
grüße uwe


Arduino Forum > International > Deutsch (Moderator: uwefed) > Durchfluss Sensor auswerten


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support