I am planning to measure water level in a well, which is about 10 m deep with maximum water level up to 5 m. My plan is to use ultrasonic sensor HC SR04 to measure depth, transmit it via ZigBee to a Raspberry Pi inside my home.

As discussed in my previous question I need to select a micro controller to connect the ultrasound sensor and the ZigBee module together.

The parameters for selection is:

  1. Low power: I am planning to run this on battery, so low power usage is a priority. As of now I do not have any target for power usage or days between battery changes or even which battery to use. Since this is more of a learning project and it's in my home, I am flexible, but lower power usage is better.

  2. Low cost: This is a learning project for me, and I do not want to spend an outrageous amount of money on this, so lower cost is better.

  3. Working inside a well: The whole project will be working from inside a well and will be exposed to harsh sunlight and rain. I will be providing a good case and protection though.

  4. Easy to program.

I chose ZigBee as it is simple, meets my use case and low power. But my requirement is to transport the sensor data and I am open to other transports. The distance from my well to Raspberry Pi is about 6 meters with a wall in between. I am planning to measure the water depth every 10 minutes and twice a minute when the water pump is running (approx 20 minutes daily) .

  • 2
    This feels rather broad, or maybe off-topic. Any small MCU on a board would suit. If you'd not decided on Zigbee, I'd suggest looking at the BBC micro:bit, which has BLE onboard, and a battery connector. Commented Jan 26, 2017 at 13:51
  • 2
    If you want a zigbee radio, you should at least evaluate the parts that combine that with an MCU (typically ARM Cortex-M) CPU. Doesn't mean you have to go that route, but if you decide not to it should be for a good reason. Commented Jan 27, 2017 at 2:39
  • 2
    What do you mean by "inside a well"? Will the case be under water? Do not expect any transmission or reception from Xbee modules under water. Many operate on the 2.4 GHz band, which is well-absorbed by water; others operate around 900 MHz, which probably cannot penetrate water very well either. If the case is not underwater, 6m + wall should be fine with xbees. Commented Jan 27, 2017 at 8:11
  • "inside a well" means the device will be placed inside the well, but above water.
    – Raj
    Commented Jan 29, 2017 at 4:53

2 Answers 2


A general process of microcontroller selection.

  1. Sum up your requirements towards the microcontroller. For example in this case:
  • 1 hardware timer, to measure time between trigger and echo pulses.
  • 2 GPIO pins to interface the sensor Echo and Trigger pins.
  • Possibly UART to interface the RF communication module.
  • 1 ADC input to monitor the battery voltage.

You can get along with a 8 pin controller for this, which might requires usage of the programmer pins for general purposes as well.

  1. Decide the required CPU performance and memory requirements. Is it enough to use a 8-bit MCU or you need a 32-bit one instead? What CPU clock speeds are acceptable tens of MHz or 1 MHz is enough? How much program memory, RAM and ROM are needed?

Given the described application, you do not need high computing performance. Probably a 8-bit controller will suffice (though won't be much cheaper than a 32-bit one so you can decide here by the price maybe).

  1. Low power. When it is not crucial you can probably get along with almost any kind of controller using its low power mode with the lowest supply voltage and system clock frequency. If it is more important you can start narrowing down your search list by starting with dedicated low-power MCU cores like (ARM® Cortex®-M0 or M0+ CPU cores). Usually the datasheets contain tables for most of the low power modes/VCC/SysClk frequency, better ones will list the consumption of each peripherals as well.

  2. Developer tools. I consider it as a very important aspect. Dedicated hardware programmer tools can cost fortunes so usually I stick to MCUs I have already had programmers for. When you switch to another family or brand it is good to invest into a development board that has an on-board programmer which could be used later to program your custom boards. In general always check first that how much will it cost to be able to download programs to a microcontroller.

As @Sean has pointed out in the comments, a possible and cost effective solution would be to search for such RF modules that comes with an integrated, programmable application MCU, which can run your firmware while handling the RF communication part as well. Such modules exists for BLE, WiFi and ZigBee and possibly for many other technologies.

In addition about how will any MCU survive in the well. It will all comes down on the enclosure you will provide for the device. For example it won't matter much which MCU you choose if the enclosure is not 100% water resistant.

TL;DR; Here comes the product specific part.

  1. You can choose the ATtiny25 which costs 0.74$/1 piece on Farnell. 8-bit, 8-pin so won't take much space. In Power-down mode it consumes 0.2 μA with disabled watchdog, at 3 V. 2-4 μA if the watchdog is enabled. It is Arduino compatible so programming it won't cost you much (USBasp or AVRdude programmer costs about 2$ on eBay). (Note that: you should use Arduino Software Serial library to interface an RF communication module, as this MCU only has SPI by hardware.) All in all it is small, cheap, with relatively low power consumption, but the bit-banged UART might complicates it though. It has 2 kB program memory which should be enough for you.

  2. Or go with an ARM Cortex M0, which consumes 2 μA in Standby mode and 5 μA in Stop mode. Such MCU is for example STM32F030F4 which costs 1.17$/1 piece. It is a more powerful 32-bit controller with a maximum of 48 MHz system clock frequency, but as you can see only for +0.3$. It comes with 16 kB program memory, far than enough for this simple task. It has SPI, UART, I2C and plenty other peripherals. Programming it will costs more, dedicated programmer costs 20$ at Farnell. In my opinion, not worth it. Instead you can invest in a development board for the F0 family which has an on-board programmer (ST-LINK). STM32F0Discovery board costs ~10$. You can start prototyping with this board and use it as a programmer later.

  • 3
    Note that the ST-LINKs of discovery and nucleo boards can often be used for other MCUs than those on the board itself. Not sure about that specific board, but from the looks of it, it uses SWD and can be disconnected using the jumpers on the right. The good thing about that is that the ST-LINK are not only programmers, but in-circuit debuggers, easing development a lot. Commented Jan 27, 2017 at 8:09
  • 3
    Also, if you don’t care about the replies from the XBEE, you can use the Universal Serial Interface of the ATtiny to get a UART which is faster than the bit-banged software implementation. Commented Jan 27, 2017 at 8:09
  • 3
    Worth noting that radio modules frequently come with un-dedicated MCU resource (and modules exist to simplify type approcal). The CPU is typically shared with the RF stack, so you need to accept periodic interrupts, etc. Commented Jan 27, 2017 at 10:21
  • 3
    ULPBENCH is a good resource when low power operation (battery) is important.
    – neonzeon
    Commented Jan 27, 2017 at 14:46

Looking at ease of programming and low cost, I would probably start with some kind of Arduino module (or low-cost clone). Code for your ultrasonic sensor already exists, as does example code for ZigBee, for example using the Digi XBee modules. On the latter, you connect the XBee to a serial port, and after making the connection with the venerable old "AT" command interface, you then have a point-to-point channel that you can send any text down (to your Raspberry Pi). ZigBee is not the cheapest type of short-range communication, but the XBee modules have fallen in price in real terms over the last 5 years.

I know that some people have a problem with the C/C++ based language used on Arduino, but in this case you'd largely be merging together already existing scripts from other users.

If you Google around for "Arduino sleep mode", you'll find examples of how you can put the Arduino into low power mode, and wake up sporadically to take a reading, communicate it, then re-enter sleep mode.

  • 1
    While good power management is possible with an ATmega chip, a typical Arduino board has parasitic power drains that will sharply limit battery life. Commented Feb 2, 2017 at 4:23

Your Answer

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

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