Problems powering HC-SR04 using digital pins to reduce power usage during sleep.

Hello everyone!

I am working on a project that takes distance readings using an HC-SR04 sensor and communicates the data with a 433MHz transmitter. I am using an Arduino Nano v3.0. I have it working correctly. I would like to have it outdoors for 3 to 5 months without needing to replace the batteries. I worked with my multimeter to get an idea of the power requirements from the system.

When the system is fully operating, it uses about 35mA. When I put it to sleep (POWER_DOWN mode), it consumes 19mA. If I remove the HC-SR04 sensor, sleep mode consumes 7.8mA

Currently, I am powering the Nano using a 9 volt battery via Vin, which I know has some inefficiencies in it (on-board regulator from what I've read). I would be content as a first step to get it to the 7.8mA consuption level.

The SR04 appears to draw 9mA all on its own. So I was hoping to basically cut the power to it during the sleep periods and then turn it back on. 9-15mA sounds like it is within the realm of powering it from one of the Nano's digital pins set to OUTPUT and HIGH, and then set it to LOW to turn it off.

If I turn it to HIGH during setup and do not change it, it appears to power it correctly. But once I switch it LOW and then back HIGH, it only generates zero (0 cm) readings. Obviously I'm overlooking something. There are two other pins used by the SR04 (TRIGGER and ECHO) on the Nano for doing the readings, so I didn't know if it were somehow causing problems having the Vcc coming from a pin on the Nano also. Like a reference voltage getting out of whack.

My only other idea is to use a pin to make use of a transitor to control the current and see if that works, but I'm not sure it'll work any better if the TRIGGER and ECHO lines are getting 'confused' when I drop the voltage.

My minimum goal would be to get this all running for 4 months on some D cell batteries. Another option would be to setup a solar panel recharger. But I'd prefer to skip that option for a first run.

Thanks for any input!

Wes

My only other idea is to use a pin to make use of a transitor to control the current and see if that works,

That's the idea that popped up when reading your story.

Can you post your code to see it there is something missing? maybe the sensor need a reinitialize after power up?

furthermore a must read - http://www.gammon.com.au/forum/?id=11497 -

Thanks for the feedback. I was also considering that the sensor might have to be reinitialized before it could be used again.

I have also tried it using the Analog pins on the Nano with the same effect.

The link you provided is one of several that I spent the weekend looking through, and it did point me in the right direction on getting started. Some of it is still undigested in my mind.

I know to get to the next level of power savings, I pretty much will have to go with a minimal chip setup. It is just frustrating to not be able to minimize the power usage I have going on now.

Thanks again for the help!

Here is the current code:

I switched to the NewPing and LowPower libraries from doing it ‘by hand’ to avoid any errors I might have been introducing. But honestly, there isn’t much code involved.

#include <NewPing.h>
#include <VirtualWire.h>
#include <LowPower.h>


int trigger = 5;
int echo = 6;
int sonar_power = 7;

NewPing sonar(trigger, echo, 300);

int txpin = 8;

char buf[20];

void setup()
{
  pinMode(sonar_power, OUTPUT);
  digitalWrite(sonar_power, HIGH);
  Serial.begin(9600);
  vw_set_ptt_inverted(true);
  vw_setup(300);
  vw_set_tx_pin(txpin);
}


void loop()
{
  unsigned int distance = sonar.ping();

  distance = distance / US_ROUNDTRIP_CM;
  Serial.print(distance);
  Serial.println(" cm ");
  Serial.println("Transmitting");
  sprintf(buf,"%d", distance);
  vw_send((uint8_t *)buf, strlen(buf));
  
  vw_wait_tx();
  digitalWrite(sonar_power, LOW);
  delay(100);
  LowPower.powerDown(SLEEP_8S, ADC_ON, BOD_OFF);
  digitalWrite(sonar_power, HIGH);
  delay(2000);
}

what if you strip of the whole virtual Wire ?

#include <NewPing.h>
#include <LowPower.h>

int trigger = 5;
int echo = 6;
int sonar_power = 7;

NewPing sonar(trigger, echo, 300);

int txpin = 8;

char buf[20];

void setup()
{
  pinMode(sonar_power, OUTPUT);
  digitalWrite(sonar_power, HIGH);

  Serial.begin(9600);
}


void loop()
{
  float distance = sonar.ping();  // changed this line to float  

  distance = distance / US_ROUNDTRIP_CM;   // if distance is too small INT would truncate to zero.

  Serial.print(distance, 3);  / 3 decimals
  Serial.println(" cm ");
  
  digitalWrite(sonar_power, LOW);
  LowPower.powerDown(SLEEP_8S, ADC_ON, BOD_OFF);
  digitalWrite(sonar_power, HIGH);

  delay(2000);
}

Removing VirtualWire along with the transmitter, didn't appear to have any effect on the SR04 behavior. It still repots "0 cm" if Vcc is wired to the Nano digital pin. Switching the SR04 Vcc from the Nano pin back to the 5v line does work.

Figure I'll track down some BC548 transistors and see if that route helps.

If anyone else has suggestions, I'll be happy to try them out.

Thanks for the help!

Does the sonar_power pin actually gets HIGH after the sleep? Check with multiMeter / LED? Could it be that the pinMode falls back to INPUT?

do you have a link to the lowpower.h?

The low power library I am using is found here: https://github.com/rocketscream/Low-Power

I am not sure if the pin is falling back to input mode, but measuring the voltage with my multimeter gives me alternating values of 0v (or near 0v) and 4.7v during the corresponding sleep and delay periods. The 5v rail also reads as 4.7 on my meter. That seemed to me like it was going high and low as expected.

alternating values sounds good..

I have the same problem - just wanted to know if you have found a solution?

http://forum.arduino.cc/index.php?topic=214203.0

It works fine with a maxbotix lv-ez1 analog mode - will think it has something to do with who sit a microprocessor on hc-SR04 and you can not just take power as with an analog sensor.

Have've got it down to 10-20 uA in sleep mode with maxbotix lv-ez1 - but does not seem it is as good as a HC-SR04 / 05 because it is blind to everything less than 30 cm and not so stable measurements.

PS.: Have tried with an NPN trasitor without success;-(

How about setting the pin supplying power to be an input when powering off the SR04 - point being that if you set it to be an output at 0v power can flow back into the sensor via the other pins and upset it.