Thank you for replies,
yes, I have Arduino UNO rev 3, the point is, the "pulse width unstability", how I'd call it, occurs regardless the servo is connected or not, so I assume it shall not be a servo consumption related problem or power related problem. Just to answer - yes, I use the onboard power plug for power. But again, the pulse has the same behaviour regardles the servo is connected or not.
Shortened example of my code is below - only parts related to servo are left... (I use GSM shield as well, this part works OK), I posted basically only servo related stuff not to have a long code here, the GSM part is only for understanding when an how I invoke servo actions....
The servo pulse is the same all the time, regardless the myServo1.attach parameters - default or not, pulse is unstable, the same with servo write - regardless if write or writeMicroseconds is used, signal is unstable.
Next try will be do disassemble the entire thing and run just a basic code just for servo...
// libraries
#include <GSM.h>
#include <Servo.h>
#define PINNUMBER "xxxx"
// initialize the libraries instances
GSM gsmAccess;
GSM_SMS sms;
Servo myServo1;
// initialize variables
int Servopin1 = 9; // Servo pin
int Tonepin = 8; // tone output pin
int SensorPin = A0; //Temp sensor pin
float voltage;
float temperature;
int SensorVal;
char remoteNumber[20]; // telephone number which sent sms
char incomingMsg[200]; // incoming message
char c;
char TempVal[6];
String LEDREDStat(3);
String LEDGRStat(3);
String LEDBLStat(3);
String outgoingMsg(200); //outgoing message for formatting
char outgoingMsgChar[200]; //outgoing message as char for sending
int str_len;
void setup()
{
// initialize pins, variables and servo initial position
pinMode(LEDpin, OUTPUT);
pinMode(LEDREDpin, OUTPUT);
pinMode(LEDGRpin, OUTPUT);
pinMode(LEDBLpin, OUTPUT);
pinMode(Tonepin, OUTPUT);
myServo1.attach(Servopin1, 1000, 2000); //"AT THIS MOMENT THE Servopin1 STARTS TO BE ERRATIC"
Serial.begin(9600);
Serial.println("Test started");
digitalWrite(LEDpin, LOW);
digitalWrite(LEDREDpin, LOW);
digitalWrite(LEDGRpin, LOW);
digitalWrite(LEDBLpin, LOW);
myServo1.writeMicroseconds(1000);
boolean notConnected = true;
// Start GSM shield
while(notConnected)
{
if(gsmAccess.begin(PINNUMBER)==GSM_READY)
{
notConnected = false;
digitalWrite(LEDpin, HIGH);
digitalWrite(LEDREDpin, HIGH);
digitalWrite(LEDGRpin, HIGH);
digitalWrite(LEDBLpin, HIGH);
}
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
tone(Tonepin, 950,500);
}
void loop()
{
//Receiver
if (sms.available())
{
memset(incomingMsg, '\0', 200);
tone(Tonepin, 1200,1000);
sms.remoteNumber(remoteNumber, 20); // Get remote number
Serial.println(remoteNumber);
// Read message bytes
int i = 0;
while(c=sms.read())
{
incomingMsg [i] = c;
i++;
}
Serial.println("COMPILED MESSAGE");
Serial.println(incomingMsg);
sms.flush(); // delete message from modem memory
if (!strcmp(incomingMsg, "RED OFF"))
{
digitalWrite(LEDREDpin, LOW);
myServo1.writeMicroseconds(1500);
sendMsg("RED LED is OFF");
}
else if (!strcmp(incomingMsg, "RED ON"))
{
digitalWrite(LEDREDpin, HIGH);
sendMsg("RED LED is ON");
myServo1.writeMicroseconds(1000);
}
else
{
Serial.println("Invalid command");
sendMsg("Invalid command!");
}
}
}
// Sender
int sendMsg (char txtMsg [200])
{
Serial.print("Message sends to: ");
Serial.println(remoteNumber);
Serial.println("Message:");
Serial.println(txtMsg);
sms.beginSMS(remoteNumber); // send the message
sms.print(txtMsg);
sms.endSMS();
Serial.println("COMPLETE!");
}