Reads the water flow sensor input

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a water flow sensor and a buzzer, it buzz when the sensor reach certain limit.

I've tested it using arduino IDE:

const int pin_1 = A0;
const int pin_2 = 2;
int X = 0;
float FREQUENCY = 0;
float RPM = 0;
float TOTAL = 0;

void setup (){
  Serial.begin (9600);
  pinMode(pin_1, INPUT);
  pinMode(pin_2, OUTPUT);
}
void loop (){
  X = pulseIn(pin_1,HIGH);
  FREQUENCY = 60000000/X; //per min
  RPM = FREQUENCY/1; //rpm
  TOTAL = RPM/1000;
  if(TOTAL>30){
    digitalWrite(pin_2, HIGH);
  }
  else if(1<TOTAL<30){
    digitalWrite(pin_2, LOW);
  }
}

 

To make it into assembly code, this is what i get so far:

.ORG   0x0000      
RJMP   main            
main:
        ldi r16, 0x00
        out ddrc, r16
        in r18, portc
        cpi r18, 0xFF
        breq sound
        rjmp main
sound:
        ldi r20, 0xFF
        out ddrd, r20
        ldi r22, 0xFF
        out portd, r22
        rjmp main    

 

It does not work as it should, how do I take values from the sensor? Is there any instruction that equivalent to PulseIn function in arduino?

Okay

Last Edited: Wed. Jan 8, 2020 - 05:17 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

onyxyliaa wrote:
I have a water flow sensor

What is the part number for your sensor?  Or better yet, a link to its datasheet.

All of the Arduino source code is open to look at, you can even have the compiler give you an assembly listing when you build your sketch.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd start by refactoring the C. When you transition to Asm I'm guessing "float" has no real place in your implementation. Also, when you refactor you may well find yourself scratching your head when you reach an expression such as:

RPM = FREQUENCY/1; //rpm

Also things like pulseIn() in Arduino may look fairly innocuous but there's a good deal of cleverness hiding behind that. It seems you are going to want to be running some kind of timer if you are going to time pulses in microseconds. Perhaps even input capture ?

 

PS:

  else if(1<TOTAL<30){

interesting ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

See Tip #1 (in my signature, below; may not be visible on mobile) for how to properly post source code.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

https://www.avrfreaks.net/forum/...

Interresting that similar code is posted the same day about water flow sensor in the above post, perhaps a school project?

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I thought it sounded familiar!

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

onyxyliaa wrote:
how do I take values from the sensor?

As you haven't said what sensor it is, that is impossible for us to answer!

 

From first principles, this is what you need to do:  http://www.8052mcu.com/forum/read/160143

 

However, as you're using an Arduino, someone has almost certainly done this already - and published a library for it. So you just need to find it!

 

Simply putting "Arduino" plus the part number of your sensor into your favourite internet search engine should get you there ...

 

Of course, you will still have to spend some time studying the documentation for the library in order to understand how to use it ...

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...