1

I'm attempting to make a sensor that will record the duration and frequency of a pump going off. It always fires for at least 4 seconds, but the duration can be up to 7 days. The vibration sensor I have is a SW-420, which I think will work. I'm fairly new at this, and I don't mind figuring out the actual code myself, but I'm running into newb problems.

  1. Should I approach this as an interrupt that uses a callback while loop, or would it be better to look at it as a typical debounce sub? Is there a better solution?
  2. Since the duration can (very rarely) exceed running for more than a few minutes, I'm wondering if I need an RTC module. The time is not very important, it just needs to be "close".
  3. The duration info will be fed to node-red via MQTT. I can count frequency in that system... I'm trying to decide if I should do remote frequency calculations, or try and wrap it into the firmware on the Arduino. Any suggestions for this?

Bonus points if I can accomplish this without any additional libraries. I'd love to put this on an ESP8266.

Thanks for your help, I appreciate it.

1 Answer 1

1

Should I approach this as an interrupt that uses a callback while loop, or would it be better to look at it as a typical debounce sub?

No. If you want to use interrupts then just record the start time on one edge of the signal and subtract it from the current time on the other edge (not sure which edge is which on that sensor).

Since the duration can (very rarely) exceed running for more than a few minutes, I'm wondering if I need an RTC module. The time is not very important, it just needs to be "close".

It depends how you define "close". An RTC can give you better accuracy over long periods, yes, and the Arduino struggles with > 49 days by itself.

The duration info will be fed to node-red via MQTT. I can count frequency in that system... I'm trying to decide if I should do remote frequency calculations, or try and wrap it into the firmware on the Arduino. Any suggestions for this?

What kind of frequency are you wanting? The frequency of the vibration itself, or the frequency at which some vibration occurs? If the former the sensor you have won't do the job - that just tells you when there is vibration above a certain threshold.

To sense the actual frequency of vibration you need a more hands-on approach by the MCU. Either use the raw HDX-2 vibration sensor as used on the SW-420 (that's the blue tube at one end), or do it properly and use an accelerometer which you sample over time and perform an FFT on the sampled signal to isolate the different frequencies.

6
  • Thanks for responding. This sensor is normally closed, I'm pretty sure I can figure out which edge to use. It's just nice to have a direction to move towards. May 2, 2017 at 15:35
  • The sensor (HDX-2) is normally closed, but it integrates that with a capacitor and uses a comparator to set a threshold. It's the output of the comparator that gives you your two edges, and I haven't spent the time working out which edge would be which.
    – Majenko
    May 2, 2017 at 15:37
  • The frequency I'm looking for is how often the pump goes off, not the actual vibrations of the pump. I basically want to know that the pump went off for 6 seconds at 10:59:40 and then again at 11:04:20 for another 6 seconds. This is the frequency I'm looking for. The timestamps can be handled by the remote end based on when the MQTT message was received, so I only have to pass on a duration of X seconds. May 2, 2017 at 15:37
  • Then this sensor sounds fine to me.
    – Majenko
    May 2, 2017 at 15:38
  • I think that I may not have been clear on one point. When this sensor gets activated, it's not a simple ON and then OFF. it's a series of ON OFF readings that are between a few microseconds and several seconds. The hard part for me is determining the FIRST on and the LAST off. Any pointers on that one? I think that is what I was getting at when I mentioned the while loop... in my head, I see jumping into a while loop when the first ON is triggered, and then staying in that loop until last OFF was received > X MS ago. Does that make any sense, or am I just complicating things? May 2, 2017 at 17:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.