Advice for battery powered water level sensor

Hi, I would like to ask for advice about the implementation of code for my application.

I have an ESP32 mcu with Arduino, a Notecarrier and Notecard and a ultrasonic level sensor (A02YYUW Waterproof Ultrasonic Distance Sensor (3~450cm, UART, IP67) - DFRobot). I need the ESP32 and sensor to be in powered down and only power it once a day at 04:00h in the morning to make a water level measurement, transmit data and power down again.

Can you give me advice about the implementation/Arduino sketch for this?

1 Like

Yes! Let’s get you pointed in the right direction!

This might be a little much to digest at once, but please feel free to ask to some follow up questions.

Host Power Control Example

If you’ve gone through the "Building your first application " quickstart already, then take a look at this example:

This shows how the code is structured when booting the host MCU based on Notecard ATTN pin state. It also shows how to power down the host MCU via the call to the Notecard to change the state of the ATTN pin.

The high-level description of using these features, see: Low Power Design - Blues Developers

Sensor Example

Regarding putting in your own sensor, take a look at:

This is the source for Smart CO2 Sensor - Accelerators - Blues Developers

This may be a bit more sophisticated than what you’re looking for, but it has a lot of the components you’d look for in this type of application.

Notecarrier F Switch

Be sure to flip the ATTN pin switch to enable the Notecard to control the power to the host MCU.

Sensor Power

You may also want to cut the power supply to the sensor when the host MCU is off. According to the link you provided, the sensor supports 3.3V as a supply.

Looking at the schematic for the Notecarrier F

The ATTN pin control F_BAT voltage which broken out to the Notecarrier F headers. I didn’t check the current draw of the sensor, but if it’s too much, you may need a secondary converter wired to the battery that’s enabled by the ATTN pin. The ATTN pin is also broken out on the Notecarrier F headers.

Scheduling 4 AM measurements

The Notecard doesn’t have a way to wake up the host at a specific time, though that seems like a good feature request.

Prior to putting the host to sleep, use the card.time request to get the current time, and compute the number of seconds until the next 4AM, and use this as the input number of seconds the host MCU should sleep for. This may actually be the trickiest part of the whole application.

Remember the card.time request won’t return the time if it doesn’t have the Unix Epoch available yet, so you’ll need a strategy for resets of the device, and decide if you want the application to measure on device reset, or only at the selected interval.

Also card.time is in UTC. It does return an offset in minutes to compute the local time if you want to use 4AM local time. The local time offset is estimated from Notecard location. This will generally be based on cell tower location estimate (there are rare cases where the cell tower location will be wrong just because the information returned by the database lookup is wrong, so you may want an override mechanism in the Notecard environment variables to set the time zone offset manually if it’s way off)

Diagnostics

I recommend either using the hub.log request, or create your own Notefile to send some host MCU application diagnostics to the Notehub. That way when you’re device is behaving weird, you have some info about the behavior without needing to physically retrieve the device.

Host Firmware Updates

I recommend investing in enabling this feature prior to deploying the hardware. If you discover you need to change the host MCU firmware, and it’s not readily accessible, this will slow progress substantially. We’ve had other users in this situation before :wink:

3 Likes

Thank you very much for your kind response!

I will use Swan board as host MCU.

Average current comsumption for A02YYUW is 8mA. That is right to feed directly with a GPIO pin, right?

Finally, what do I need to do to ensure that firmware OTA with will work with Swan and Notecarrier F?

Thank you very much,

About ATTN pin switch, my Notecarrier F is different to the one you link. Probably older version. What should I do?

And a silly question. Why if I upload dummy Blink sketch (apparently uploads correctly in Arduino IDE), I don´t actually see LED blink?

It looks like you have an older Notecarrier F, but it does have the outboard DFU capabilities!

Use the switch labelled DFU, and make sure it’s pushed to “ON” side.


IMPORTANT

It is still possible to perform host firmware updates without these connections. But it requires the host MCU to manage it’s own update process. It can grab the bytes from the Notecard over it’s communication connection with the Notecard and install them manually.

So you don’t have to use this wiring to enable firmware updates, but it does make it easier from the point of view of developing the host MCU application.


1 Like

Use the Feather PWR switch instead.

You can see the features and connections here:note-hardware/Notecarrier-F/v1.0 at master · blues/note-hardware · GitHub

For the sketch not blinking the LED, I recommend reviewing the Swan Quickstart for Arduino IDE here: Using Arduino IDE with Swan - Blues Developers

and double-checking the correct board configuration is selected. If that doesn’t resolve it, please let us know.

Please find attached my code. I was hopping it would transmit data and power down my Feather board until 24 hours past by and does the measuring again. But it does not power down my Feather. What is wrong with my sketch?

Sketch.txt (7.7 KB)

Nothing is jumping out as a problem in the Sketch code.

Please check to make sure that

  1. The Feather does not have a USB cable plugged in
  2. The Notecarrier F Feather PWR switch is set to “switched”

USB Power

For (1), the power from the USB connector on the Feather bypasses the power supply that’s controlled by the ATTN pin on the Notecard.

If you want to output debug information from the Feather, use a F_RX/F_TX pair from the Feather with a USB<—> UART converter (usually an FTDI chip of some kind). For that you will need to set the debug serial in your sketch to be a different serial port. The Serial port you select depends on which Feather you are using.

Feather PWR Switch

This switch is set to either continuously provide power to the Feather, or only enable power when the Notecard ATTN pin is high.

To test if this pin is doing what it should be, I recommend following a procedure like the following:

  1. Find the Blink LED example for your Feather MCU.
  2. Compile, download, and run the Blink LED example for your Feather
  3. Verify the LED on the Feather is blinking
  4. Remove the USB from the Feather (if one is plugged in)
  5. Plug a USB into the connector on the Notecarrier F with a Notecard installed
    (if one is already plugged in, remove it, and all other power sources, then plug the USB back into the Notecarrier F. We want the Notecard to boot for this to be reproducible.)
  6. Using Chrome (or Chrome-based browser) navigate to In-Browser Terminal - Blues Developers
  7. Use the Connect button to connect to the Notecard
  8. Enter the following request in the terminal prompt
    {"req":"card.attn"}
    The response should include the pair "set": true in the response
  9. Enter the following request to set the ATTN pin low for 7 seconds
    {"req":"card.attn","mode":"rearm","seconds":7}
    The response should not include the "set" field. The LED on the Feather should be off, and not blink.
  10. Wait for 7 seconds
  11. Verify the Feather has rebooted, and the LED is now blinking.
  12. If that procedure does not cause the LED on the Feather to stop blinking, change the state of the Feather PWR switch on the Notecarrier F, and repeat steps 9 through 11
    (it’s possible I have the state definitions flip-flopped :wink: )
1 Like

Thank you very much. I want to switch fron Notecarrier F to notecarrier A. Does something change? Can you sketch a connection diagram of the MCU and notecarrier? Thank you very much!

I have done a project with same sensor and published on Hackster.io. maybe you could look.
Overhead tank water level monitoring using Blues Notecard - Hackster.io