Quantcast
Channel: Arduino Forum - Latest topics
Viewing all articles
Browse latest Browse all 15514

Servo control not working

$
0
0

I have done a search across the internet for info on servo.h Arduino library and my issue but have not found anything that answers my question.

Background:
I am building a larger project for friend to control his project car HVAC unit with an LCD and Arduino Mega. I have completed the full project and been using high torque servos to control the heater temperature and the interior/dash interior lights. The unit has been working well and servos have been responding to inputs but recently stopped working. I have no idea why so I took the core functions from the HVAC code and set up a test project to run the servo to see if I can isolate the issue.

Test code is below and essentially replicates the calls and functionality of the functions I have in the other project.

I created a test bed with 110-6V power reducers per my HVAC unit, and that is confirmed to be running correctly and producing 6 v to the servo per specs.
I connected the output control pin to pin 7 and then pin 9 and then pin 11 on an Arduino Uno so it is confirmed digital output. I also added printouts to see what the values are at each step of the process and al that seems to be wat is expected from the coding.

When I input a 1 into the Serial Monitor, it will read it and confirm the value and when correct, calls the temp_Set() function. In the temp_Set() function, I map the temp input value to servo sweep. In the HVAC code, the sweep values are from 20-86 as the temp door has a fairly small sweep. Map works fine and increments the position value properly.

The code then writes to the servo object per design and the code moves on. For some reason, the write no longer seems to work but there are no outputs from the servo code to confirm whether the write was successful or not. Or at least what I can find.

When testing power output on the pin, I get the value of the servo angle mapped in the line on the signal line.

As an additional item, I found a servo test project that sweeps the servo on the internet and ran that and the servo sweeps per that code base. It uses a for loop though to sweep the servo 180* but uses single angle for the other two tests so it uses both methods to show the functionality. I am using angle method.

Are there different ways to control a servo that is more reliable or different so I can try that?

Any help would be greatly appreciated as I am at a complete loss at this point.

/* Servo test
 by Don O
 March 16 2024
 This code created to test the servo library for another project that manages temperature control with a servo.
 The code receives a specific input (I used a 1 for simplicity in the test) and if it is the correct input, calls temp_Set() function
 temp_Set reads the memory value and if in range, maps the memory value to an angl esweep between 20 and 180 and then writes to the servo motor
 If successful, return success and if not, sends error from temp_Set() back to calling function
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

String temp_Set();
int mem[1] = {19};
String input = "";
String rtn = "";
int tempPos = 0;

Servo tempServo;

void setup() {
  pinMode(11, OUTPUT);  //sets pin 11 to output.  Not sure I need this with attaching myservo below....
  myservo.attach(11);  // attaches the servo object on pin 11
  Serial.begin(9600);
}

void loop() {
 if (Serial.available() > 0){
    input = Serial.readString();
    Serial.println("Input '" + String(input) + "'");

    if (input == "1") {
      Serial.println(String(input));
      Serial.println("mem  < if =" + String(mem[0]));
      // Step the motor in incremnents to reduce by 1 degree C:
      if ((mem[0] >= 19) && (mem[0] < 30)){
        //Increase temperature by 1 degree.
        mem[0] ++;
        Serial.println("mem=" + String(mem[0]));
        rtn = temp_Set();
        Serial.println("Success =" + rtn);
      } else {
        Serial.println("Error =" + rtn);
      }
    } else {
      Serial.println("not entering Up function");
    }
 }
}

String temp_Set(){
  // Step the motor in increments by 1 degree:
  if ((mem[0] >= 19) && (mem[0] <= 30)){
    //increment temperature by 1 degree and servo position
    tempPos = map(mem[0], 19, 30, 20, 180);
    //Move temp servo by mapped increment
    tempServo.write(tempPos);
    delay(20);
    Serial.println("tempPos = " + String(tempPos));
   return "success in Temp_Set";
  } else {
    return "Err temp_Set";
  }
}

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 15514

Trending Articles