Slow down servo when returning to position 0

I mean the code does not offer any opportunity for a slams shut outside setup and we know setup is not being called when that happens.

The only two other places where the servo is touched is in two gentle sweep for loops that are blocking.

if it does "slams shut" then there is something else at play that is not related to a wrong state causing the race condition.

Still waiting.

(uh oh... I see the helicopter entering the chat... time for me to shovel rocks)

come on...

explain how a wrong state or a race condition is transforming

for (pos = maxPos; pos >= 1; pos -= 1) { // goes from max to 0 degrees @ 1 degree steps
      shutterServo.write(pos);  // tell servo to go to position in variable 'pos'
      delay(15);                // waits 15 ms for the servo to reach each position
    }

into a mere shutterServo.write(0);

whilst

for (pos = maxPos; pos >= 1; pos -= 1) { // goes from max to 0 degrees @ 1 degree steps
      shutterServo.write(pos);  // tell servo to go to position in variable 'pos'
      delay(20);                // waits 15 ms for the servo to reach each position
    }

would not

I don't see it. that code is blocking, there is no outside variables being taken into consideration

sure maxPos could somehow have been overwritten if there was some kind of memory overflow somewhere but there is no pointer or array walkthrough that could do that, it's pretty straightforward code

My bet is that it's not code related but there is something else at play, hardware wise possibly.

Why have four states (ab = 00, 01, 10, 11) represent two (a = out of range / not out of range)?

Let the temperature determine servo movement [0 to 90] or [90 minus (0 to 90)]

void setup() {
.
.
.
    if (sensorValue >= highTemp || sensorValue <= lowTemp)
      checkTemp();
  }
}

void checkTemp() {
  if (sensorValue >= highTemp) {
    for (pos = 0; pos <= maxPos; pos += 1) {
      shutterServo.write(pos);
      delay(15);
    }
  }
  if (sensorValue <= lowTemp) {
    for (pos = 0; pos <= maxPos; pos += 1) { // same loop as "too high"
      shutterServo.write(90 - pos); // just subtract pos from 90
      delay(15);
    }
  }

Perhaps my code is, uh, inelegant...

There are two things being controlled:
Shutters which open at, let's say, 80 F and close at 75 F,
and a fan, which turns on at say 85 F and off at 80 F.

Based on a similar program I saw, I thought I'd need two flag variables apiece.
If I understand you correctly, I just need one for each operation.
Thanks for pointing this out - I'll play with the code some more...

How do you separate temperature range from fan speed when using the same variable "sensorValue"?

that sounds like a possibility

Not fan speed, just fan on/off. It's just a temperature reading from the sensor.
Tells the code to do different things depending on temperature.
Not OK?

That sounds like what I'm experiencing, running the servo from a 5V 2A source. For some reason, increasing the delay to write servo position seems to have resolved the issue. The strange thing was that it only affected the servo rotation in one direction, so increased load one way was suspected -- but there was no load on servo.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.