today I tried to setup a servo motor running along with this sketch on Arduino. For some reason, when I add the setup lines for the servo, the software serial port doesn't receive data normally. I tried to change the software serial to the normal Serial port on Arduino but the same thing happens.
#include<SoftwareSerial.h>
#include<Servo.h>
Servo myServo;
SoftwareSerial BT1(3,2); // TX, RX
int val;
int servoPin = 7;
int ledPin = 10;
void setup() {
pinMode(ledPin,OUTPUT);
BT1.begin(9600);
myServo.attach(servoPin);
myServo.writeMicroseconds(2000); //2 ms for Tower Pro SG 90 Servo
myServo.write(90); //Initialize at servo's middle point
}
void loop() {
if (BT1.available()) {
int i = (int)BT1.read();
setIntensity(i);
}
}
void setIntensity(int value) {
if (value >= 0 && value <= 110) {
analogWrite(ledPin, value);
}
}
When I comment out the setup lines for myServo, the Arduino works like a charm. How can I solve this? I'm using an Arduino Duemilanove.
myServo.attach(servoPin); myServo.writeMicroseconds(2000); //2 ms for Tower Pro SG 90 Servo myServo.write(90); //Initialize at servo's middle point
, the SoftwareSerial doesn't work right. – karl_m