Servo motor vibration when connected power supply.

//YWROBOT
//Comible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#define SD_ChipSelectPin 4
#include <TMRpcm.h>
#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

TMRpcm tmrpcm;

LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 20 chars and 4 line display

int L1 = 2;
int L2 = 3;
int L3 = 5;
int L4 = 6;
int L5 = 8; //5 LED pin

int buttonPin = 7; //the number of the pushbutton pin

int de=5000; // delay time

int p=0; // variable for patten

int buttonState = 0; //variable for reading the pushbutton status

unsigned long servoMillis = 0;
unsigned long servointerval = de;

void setup()
{
lcd.init(); // initialize the lcd
lcd.init(); // Print a message to the LCD.

Serial.begin(9600);
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(L4, OUTPUT);
pinMode(L5, OUTPUT);

pinMode(buttonPin, INPUT);

tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)){
Serial.println("SD fail");
return;
}

myservo.attach(10); // attaches the servo on pin 10 to the servo object
tmrpcm.setVolume(5);
tmrpcm.play("0.wav");
lcd.backlight();
lcd.setCursor(6,0);
lcd.print("HELLO");
lcd.setCursor(0,1);
lcd.print("TALKING DISCHARGEROD");
lcd.setCursor(4,2);
lcd.print("WELCOMES YOU");
lcd.setCursor(0,3);
lcd.print("PLEASE FOLLOW INST..");
delay(8000);
lcd.clear();

tmrpcm.setVolume(5);
tmrpcm.play("1.wav");
lcd.setCursor(1,1);
lcd.print("WEAR ELECTRICAL PPE");
delay(de);
}
void loop()
{

buttonState = digitalRead(buttonPin);

if (buttonState == HIGH)
{
p++;
delay(2000);
}
if(p == 1)
{
if(millis() - servoMillis > servointerval) {
servoMillis = millis();
digitalWrite(L1,1);
digitalWrite(L2,0);
digitalWrite(L3,0);
digitalWrite(L4,0);
digitalWrite(L5,0); //1
lcd.clear();
lcd.setCursor(2,0);
lcd.print("CHECK NO VOLTAGE");
lcd.setCursor(7,1);
lcd.print("USING");
lcd.setCursor(2,2);
lcd.print("VOLTAGE DETECTOR");
tmrpcm.setVolume(5);
tmrpcm.play("2.wav");
}
}

if(p == 2)
{
if(millis() - servoMillis > servointerval) {
servoMillis = millis();
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,0);
digitalWrite(L4,0);
digitalWrite(L5,0); //2

tmrpcm.setVolume(5);
tmrpcm.play("3.wav");
lcd.clear();
lcd.setCursor(3,1);
lcd.print("CONNECT CLAMP");
lcd.setCursor(2,2);
lcd.print("WITH EARTH STRIP");
}
}

if(p == 3)
{
if(millis() - servoMillis > servointerval) {
servoMillis = millis();
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,0);
digitalWrite(L5,0); //3

tmrpcm.setVolume(5);
tmrpcm.play("4.wav");

lcd.clear();
lcd.setCursor(2,0);
lcd.print("CHECK CONTINUITY");
lcd.setCursor(6,1);
lcd.print("BETWEEN");
lcd.setCursor(2,2);
lcd.print("CLAMP AND GROUND");
}
}

if(p == 4)
{
if(millis() - servoMillis > servointerval) {
servoMillis = millis();
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,1);
digitalWrite(L5,0); //4

tmrpcm.setVolume(5);
tmrpcm.play( "5.wav");

lcd.clear();
lcd.setCursor(1,1);
lcd.print("WE ARE GOOD TO GO");
lcd.setCursor(1,2);
lcd.print("FOR SAFE DISCHARGE");

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

if(p == 5)
{
if(millis() - servoMillis > servointerval) {
servoMillis = millis();
digitalWrite(L1,1);
digitalWrite(L2,1);
digitalWrite(L3,1);
digitalWrite(L4,1);
digitalWrite(L5,1);

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

Read the how get the most out of this forum sticky to see how to properly post code. Remove useless white space and format the code with the IDE autoformat tool (crtl-t or Tools, Auto Format) before posting code in code tags.

Please read the Read this before posting a programming question ... post. It makes it easier on every one if we don't have to waste time finding out fundamental information.

What Arduino? What servo? What power supply? Wiring? Is the external supply ground connected to Arduino ground?

I don't know how tmrpcm works but I do know that servo.h use disables PWM on pin 9. So perhaps try moving the tmrpcm output to a different pin.

But most servo jittering problems are caused by insufficient power supply e.g. powering the servo from the Arduino 5V, always a bad idea.

Steve

Servo.h uses timer1, TMRpcm uses timer1 by default I believe, but can be configured to use timer2.

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