Hello,
I am using an Arduino UNO with a ZigBee mounted on top of it. So, I am using SoftwareSerial library to open a Serial terminal with the ZigBee pro S1 wire Antenna module, my Arduino version is 1.0. But, there is a weird problem, is that when the rate of the sent data to the zigBee increases, the Arduino becomes crazy, and some connected components to its PWM pins starts to move/ shake!. For ex, I am connecting a Electronic Speed Control (ESC) with a PWM pin, when I send more data to the zigBee the ESC arms the motor and it rotates!!!! then it stops immediately! So it's like the components have a huge voltage drop that forces them to power on then turn off again. The zigBee module and all extra components are powered up from an external battery. The zigbee module is mounted on top of a custom made board, which is mounted on top of the Arduino UNO board. I really don't know what I have to do it's my bachelor project and I am MAD! ANY HELP PLEASE! Here is my code
#include <Servo.h>
#include <SoftwareSerial.h>
#define RxD2 4
#define TxD2 5
Servo aileronsServo;
Servo elevatorServo;
Servo rudderServo;
Servo motorServo;
int motorPos=50;
SoftwareSerial zigbeeSerial(RxD2,TxD2);
char recvChar;
int num;
void setup()
{
elevatorServo.attach(9);
motorServo.attach(11);
rudderServo.attach(6);
aileronsServo.attach(10);
pinMode(RxD2, INPUT);
pinMode(TxD2, OUTPUT);
zigbeeSerial.begin(9600);
}
void loop()
{
if(zigbeeSerial.available() >= 4){
recvChar = zigbeeSerial.read();
if(recvChar == 'e'){
char Str3[3] = {
zigbeeSerial.read(), zigbeeSerial.read() , zigbeeSerial.read()};
num = atoi(Str3);
elevatorServo.write(num);
}
else if(recvChar == 'm'){
char Str3[3] = {
zigbeeSerial.read(), zigbeeSerial.read() , zigbeeSerial.read()};
num = atoi(Str3);
setSpeed(num);
}
else if(recvChar == 'r'){
char Str3[3] = {
zigbeeSerial.read(), zigbeeSerial.read() , zigbeeSerial.read()};
num = atoi(Str3);
rudderServo.write(num);
}
else if(recvChar == 'a'){
char Str3[3] = {
zigbeeSerial.read(), zigbeeSerial.read() , zigbeeSerial.read()};
num = atoi(Str3);
aileronsServo.write(num);
}
}
}
void setSpeed(int speed){
int angle = map(speed, 50, 170
, 50
, 180);
motorServo.write(angle);
}