Servo TowerPro MG995

Hello,
I have a problem with my servo when I try to add it to my programe in the project I'm doing (an automatic geenhouse). I want it to turn 0 to 90 degrees when the vent (ventilator) is turned because the temperature is over 30º. But when i want it to turn from 90 to 0 when the temperature is under 29º, it start normal, but then turns to 90 1 second and returns to 0.

Prova_1.ino (4.3 KB)

Before i can have a serious look, you will need to create some function to perform the tasks that you want performed. Also your code is small enough to be posted within </> code-tags (rather than as an attachment.)

Be sure to use a separate 5 to 6V, 2 Ampere power supply for the servo, and connect the grounds.

Your compares are the wrong way round...you have while <30 and while > 29 which ain't what you said in your description. And you have so many long delays in there that any action will take ages.

Steve

Actually i had a look, and the confusion is here, at the end of the first while loop, you have

 for(Angulo= 180;Angulo >90; Angulo -= 1)  
  {                                  
    servo.write(Angulo);                  
    delay(15);                              
  } 
  delay(500);

it would have show up better if you would have used auto-format (ctrl-t) but that makes the servo turn from 180 deg to 90 deg over a period of 90 x 15 = 1350ms, then it wait 500 ms and then it does it again after it has written to the LCD, which does take some time.

at the end of the second while loop you have

for(Angulo= 90;Angulo < 180; Angulo += 1)  
  {                                  
    servo.write(Angulo);                  
    delay(15);                              
  } 
  delay(500);

which sort of does it in the opposite direction but it will look fairly similar, just reversed direction but still over 1.35ms in one direction, wait 3/4 of a second and again start from the top. I suspect if you pull both for loops out of these while loops you will have to result you want (i think, your explanation of what you want is not super clear.)