Flow Switch to ESP-32S

hafiz.iot
Posts: 1
Joined: Mon Jan 14, 2019 10:25 am

Flow Switch to ESP-32S

Postby hafiz.iot » Mon Jan 14, 2019 10:31 am

Help me to code my flow switch (YF-S201), i tried this code works on arduino mega 2560, but why not worked here?

this is my code found in internet
volatile int flow_frequency; // Measures flow sensor pulses
unsigned int l_hour; // Calculated litres/hour
unsigned char flowsensor = 23; // Sensor Input
unsigned long currentTime;
unsigned long cloopTime;
void flow () // Interrupt function
{
flow_frequency++;
}
void setup()
{
pinMode(flowsensor, INPUT);
digitalWrite(flowsensor, HIGH); // Optional Internal Pull-Up
Serial.begin(115200);
attachInterrupt(0, flow, RISING); // Setup Interrupt
sei(); // Enable interrupts
currentTime = millis();
cloopTime = currentTime;
}
void loop ()
{
currentTime = millis();
// Every second, calculate and print litres/hour
if(currentTime >= (cloopTime + 1000))
{
cloopTime = currentTime; // Updates cloopTime
// Pulse frequency (Hz) = 7.5Q, Q is flow rate in L/min.
l_hour = (flow_frequency * 60 / 7.5); // (Pulse frequency x 60 min) / 7.5Q = flowrate in L/hour
flow_frequency = 0; // Reset Counter
Serial.print(l_hour, DEC); // Print litres/hour
Serial.println(" L/hour");
}
}
also, i tried this worked too
int TURBINE; //pengukuran SINYAL data yang bersifat incremental
int HSensor = 23; //nama alias pada pin 2
int Calc;

void speedrpm () //fungsi penghitungan dan interrupt
{
TURBINE++; //bersifat incrementing (dengan mode falling edge)
}

void setup()
{
pinMode(HSensor, INPUT); //inisialisasi sebagai input
Serial.begin(115200);
attachInterrupt(0, speedrpm, RISING); //cara penulisan perintah interrupt
}

void loop ()
{
TURBINE = 0; //data awal = 0
sei(); //perintah aktifnya mode interrupt
delay (1000); //nilai delay 1 detik
cli(); //perintah untuk matinya program interrupt
Calc = (TURBINE * 60 / 7.5); //Pulsa * 60 / 7.5

//satuan FLOW RATE benda cair yaitu L / hour

Serial.print(Calc, DEC); //menampilkan hasil pembacaan kalkulasi flow rate dalam bentuk dec di serial monitor
Serial.print(" L/hour\r\n"); //Tampilkan L / hour pada baris baru
}

ESP_Sprite
Posts: 8921
Joined: Thu Nov 26, 2015 4:08 am

Re: Flow Switch to ESP-32S

Postby ESP_Sprite » Wed Jan 16, 2019 8:18 am

Moved to the Arduino subforum, as you seen to use that. Furthermore, it helps if you tell us how it 'does not work', and what you already tried wrt debugging.

Who is online

Users browsing this forum: No registered users and 55 guests