Micro linear servo trouble...

Hello all :slight_smile:
I bought micro linear servo for my new project. (info)
Now I am bit confused by its behavior. I tried example sketches knob and sweep and works ok.
Then I tried my very simple sketch and it does nothing. :frowning:
I tried same things with SG90 and it works ok with all three sketches.

My setup: Arduino nano, Servo (5V, GND D9), Button (GND, D7)
My simple sketch:

#include <Servo.h>
Servo myservo; 
void setup() {
  myservo.attach(9);  
  pinMode(7,INPUT);
}
void loop() {
  if(digitalRead(7)==LOW){
     myservo.write(0);
  }  
  else{
     myservo.write(180);
  }
}

Could anybody help me please? Im total newbie, so I will try to follow :slight_smile:

WE can't see the sketches that work, so tell us what is the difference between the ones that work and the one you wrote.
Paul

Have you got a pull-up resistor on the switch? Add one or just change the pinMode to INPUT_PULLUP.

Steve

Paul_KD7HB:
WE can’t see the sketches that work, so tell us what is the difference between the ones that work and the one you wrote.
Paul

Sorry those sketches are included in Arduino IDE installation in examples.
Knob:

/*
 Controlling a servo position using a potentiometer (variable resistor)
 by Michal Rinott <http://people.interaction-ivrea.it/m.rinott>

 modified on 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Knob
*/

#include <Servo.h>

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

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

and Sweep:

/* Sweep
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

slipstick:
Have you got a pull-up resistor on the switch? Add one or just change the pinMode to INPUT_PULLUP.

Steve

No I have not. I changed the pinMode to INPUT_PULLUP. Still working with SG90 and linear is silent...

Then I guess the default 0 to 180 range is too much for the linear servo. Try narrowing it by changing the attach to myservo.attach(9, 1000, 2000). If that doesn't do it then also change your writes from 0 and 180 to 30 and 150. See if that helps.

Steve

slipstick:
Then I guess the default 0 to 180 range is too much for the linear servo. Try narrowing it by changing the attach to myservo.attach(9, 1000, 2000). If that doesn't do it then also change your writes from 0 and 180 to 30 and 150. See if that helps.

Steve

Thank you! This did the trick!!!! :smiley:

Double check your power supply isn't struggling with this servo - some of these tiny cylindrical
slotless/coreless motors can draw 2A or so peak at only 3.7V supply, i.e. more than a standard micro
servo. They are more likely to overheat if the movement of the servo arm is restricted,
due to the small size and lack of ventilation.

Typically they are used in forced airflow of a prop-wash and get hot anyhow.

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