Is it possible to use an ultrasonic sensor to wake up an Arduino which is in deep sleep when an object is detected within a few cm and then do stuff?
-
2\$\begingroup\$ It's an active sensor: it applies sends pings gather information about its surroundings. To produce pings, it has to consume power. How much power will the sensor be consuming? How does it compare to the Arduino's deep sleep? Is keeping the Arduino in deep sleep worth the trouble? \$\endgroup\$– Nick AlexeevCommented Mar 6, 2017 at 0:24
2 Answers
For a truly low-power, Arduino-based solution at least the following is needed:
A) HARDWARE SIDE:
- Use a supply voltage and clock frequency as low as possible. The Arduino Pro Mini 3.3V @ 8Mhz board is a good starting point for a first project.
- Get rid of all the LEDs in the board. Their consumption is in the mA range, way too high.
- Get rid of the onboard regulator and replace it with a low quiescent current, low dropout regulator like the MCP1700. It can source only 250 mA whereas the AMS1117 is rated up to 1A, but 250 mA will probably be good enough for your low-power application. OTOH, just in case you were wondering: you don't need a switching regulator unless your Arduino spends most of the time awake and consuming a lot of current, which is a very unlikely scenario. The high quiescent current of switching regulators rules them out for this kind of applications.
- Select a low-power consumption sensor and signal conditioning circuitry. PIR and CMOS logic family 74HC are good technologies for this. As pointed by Nick Alexeev, an ultrasonic sensor will be constantly emitting, thus rendering useless your power savings on the Arduino. Avoid it.
- The signal conditioning circuit must generate a level interrupt from whichever signal is delivered by the sensor. Timing elements (like capacitors) or latches may be required for this. To be on the safe side, design it for a 100 ms resettable pulse.
B) SOFTWARE SIDE:
- Install a low power Arduino library like this one. Use the ATmega328p power-down sleep mode.
- Write a interrupt service routine (ISR). This is the piece of code that will deal with whichever needs to be done upon an interrupt event.
- Configure (attach) the interrupts as required. Note that only level-triggered interrupts can wake up ATmega328p from power-down sleep mode, as per its datasheet:
Here you can find really good, practical information on the way to go low power. For a more thorough guide, read this as well.
-
\$\begingroup\$ Hi @Enric, so my question is dose ping sensor working in background while ATMega is in deep sleep? \$\endgroup\$– VladimirCommented Mar 6, 2017 at 11:22
-
\$\begingroup\$ Yes, ATMega will be in deep sleep but the regulator will not (it's an external IC), so the sensor will still get from it the current it needs. But keep in mind that, as Nick said, the power consumed by the sensor can be high enough to shadow any power saving coming from keeping the MCU in deep sleep! \$\endgroup\$ Commented Mar 6, 2017 at 11:44
-
\$\begingroup\$ Circuit currently draw about 22mA, it has: regulator,ATMega 328PU, RF module and ping module... What takes the most current? \$\endgroup\$– VladimirCommented Mar 6, 2017 at 12:01
-
\$\begingroup\$ You should find out by closer examination of the datasheets. Look also at this: gammon.com.au/power If your circuit draws 22 mA with ATmega sleeping, that's bad. \$\endgroup\$ Commented Mar 6, 2017 at 12:26
-
\$\begingroup\$ Without sleep it draws 22mA... \$\endgroup\$– VladimirCommented Mar 6, 2017 at 13:26
If you really want to minimize power, you need to not only have a low-power MCU circuit, but an ultrasonic receiver which you can disable.
Wake up the MCU from a low power periodic timer and fire a pulse, then go back to sleep for at least the sensor ringing time, or the time of the minimum range of interest.
Wake the MCU and the receiver up again at the point in time where you first expect an interesting echo, and stay awake only until you see one or for the range of time at which your echo could arrive.
Take action if you hear an echo.
Once you hear an echo or the window of interest expires, turn everything but the low power timer off again until the next measurement interval.
How frequently you need to repeat the measurement depends on how quickly your objects can be moving and/or how short an actuation of the output is meaningful and/or the maximum permitted latency in responding to one appearing or disappearing. As a lower bound, you want to make sure not to take a new measurement until any multi-bounce or distant-wall reflections of the old transmit pulse have died out.