0

I want to set a temperature and have Nano turn on for 2 minutes then off for 2 minutes and repeat using the same temperature originally set and have the ability to change temperature settings and do the same.

The following sketch works along with displaying battery voltage using MIT Inventor 2 app via Bluetooth HC-05 to my Android phone (without the on/off sequence I am looking to do).

I hope to keep my feet warm but also extend the battery life. Can you tell me what methods I should research to figure out how to do this? I have looked at millis(), blink without delay, and my own limited programming skills without success. Thanks.

#define right 5
#define left 6

int leftval = 0;
int val=0;
int vg=0;

void setup() {
  Serial.begin(9600);
  pinMode(left, OUTPUT);
  pinMode(right, OUTPUT);
  pinMode(A0, INPUT);
}

void loop() {
  int vg = analogRead(A0);  
  Serial.println(vg / 82.049, 1);
  delay(200);
  if (Serial.available() >= 2) {  
    unsigned int a = Serial.read();
    unsigned int b = Serial.read();
    unsigned int val = (b * 256) + a;

    if (val >= 0 && val <= 255) {
      analogWrite(right,val);
      delay(200);
    }

    if (val >= 1000 && val <= 1255) {
      leftval = val - 1000;  
      analogWrite(left, leftval);
      delay(200);
    }
  }
}
3
  • 1
    arduino.cc/en/Reference/ArduinoLowPower - however the Arduino's power consumption will pale into insignificance compared to the power consumption of your heating element.
    – Majenko
    Jan 20, 2021 at 15:30
  • @Majenko, why this comment? I don't see in question a request for lowering the consumption of the Nano. OP wants to turn on the heating element for 2 minutes then turn it off for 2 minutes
    – Juraj
    Jan 21, 2021 at 7:07
  • @Juraj Because the OP asked "have Nano turn on for 2 minutes then off for 2 minutes" - not turn the element on and off, but turn the Nano on and off. Maybe it's poor English?
    – Majenko
    Jan 21, 2021 at 10:39

1 Answer 1

1

With an electrical heating element powerful enough to warm your feet, the power to the heating element is hundreds or thousands of times greater than the power to your Arduino. Anything you do to reduce the power consumed by your Arduino will have no meaningful effect on your total power consumption. It's like trying to stop a drip in your faucet to save water while the main water pipe has water gushing out of a gaping hole.

Heating elements convert watts of power to calories of heat. The more watts you put in, the more heat you get.

Current • duty cycle • on-time = total power consumed AND total heat generated.

If you reduce the duty cycle to the heating element, you will reduce the power consumed, but you will also reduce the amount of heat generated.

Given that you already have the ability to vary the duty cycle to your heating element (via your analogWrite to right and left) the only meaningful way to reduce power consumption is to lower the heat setting. It looks like you already have that ability. Turn down the heat setting and have slightly colder feet, or use a higher capacity battery.

All that said, if you turn the heat setting down to 0, the heating element completely stops using power. At that point the Arudino will slowly drain your battery while your electric socks sit in your sock drawer. It would be worth putting your Arduino in ultra-low-power sleep mode (or even turning it off entirely) to avoid draining it while you're not using it.

Edit:

If you want to run the heating element on for 2 minutes, off for 2 minutes, that would give exactly the same power savings as running it at half the current power level, but constantly.

If you really want to implement the 2 minutes on, 2 minutes off approach, you will need to use millis() to keep track of the time when you last turned the elements on/off. I suggest refactoring your current code to remove delay and use millis as well.

Take a look at the "BlinkWithoutDelay" sketch (which I believe is included with the IDE, and is certainly available online) for an idea of how to handle timing things without using delay().

3
  • I don't see in question a request for lowering the consumption of the Nano. OP wants to turn on the heating element for 2 minutes then turn it off for 2 minutes
    – Juraj
    Jan 21, 2021 at 7:05
  • 1
    I edited my answer to address the issue of 2 minutes on, 2 minutes off vs. turning the power down, and provided a starting point for implementing it if that's what they really want to do. (As I pointed out, cycling the power on and off every 2 minutes will have exactly the same power savings as lowering the PWM duty cycle by half.)
    – Duncan C
    Jan 21, 2021 at 12:28
  • 1
    Thank you. The source battery for the heating element was my concern. I had looked at millis() as an option but needed someone to confirm as a potential option. I will study millis() and BlinkWithoutDelay. Jan 21, 2021 at 19:59

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.