hi every body , i've been looking for how i can control servos by a wireless way , i recently found a way to do that , i have the codes for two arduinos transmitter and receiver controlling 4 servos , i have received data from the transmitter on the serial monitor of the receiver , but unfortunately with no movement of any servos , in addition that i have changed the location for (servo: refresh ) , but i've got the same result , no movement , can any one till me why is that , what is the problem , how to solve , and i will be so thankful .
here are the codes:
transmitter:
#include <SoftwareServo.h>
#include <VirtualWire.h>
const int numberOfAnalogPins = 4; // how many analog pins to read
int data[numberOfAnalogPins]; // the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int);
void setup() {
vw_set_ptt_pin(12);
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
void loop() {
int values = 0;
for(int i=0; i <= numberOfAnalogPins; i++) {
data = analogRead(i); // store the values into the data buffer
}
send((byte*)data, dataBytes);
delay(500); //send every second
}
void send (byte *data, int nbrOfBytes) {
vw_send(data, nbrOfBytes);
vw_wait_tx(); // Wait until the whole message is gone
}
and the receiver :
#include <SoftwareServo.h>
#include <VirtualWire.h>
SoftwareServo myservo1;
SoftwareServo myservo2;
SoftwareServo myservo3;
SoftwareServo myservo4;
const int numberOfAnalogPins = 4; // how many analog integer values to receive
int data[numberOfAnalogPins]; // the data buffer
int value[numberOfAnalogPins];
// the number of bytes in the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int);
byte msgLength = dataBytes;
int dl=20;
void setup() {
myservo1.attach(9);
myservo2.attach(10);
myservo3.attach(8 );
myservo4.attach(12);
Serial.begin(9600);
Serial.println("Ready");
// Initialize the IO and ISR
//vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_set_rx_pin(11);
vw_rx_start(); // Start the receiver
}
void loop(){
if (vw_get_message((byte*)data, &msgLength)) { // Non-blocking
Serial.println("Got: ");
if(msgLength == dataBytes){
for (int i = 0; i < numberOfAnalogPins; i++) {
Serial.print("pin ");
Serial.print(i);
Serial.print("=");
Serial.println(data);
value=map(data,0,1023,0,179); // Write into the servo
}
myservo1.write(value[0]);
delay(dl);
myservo2.write(value[1]);
myservo3.write(value[2]);
SoftwareServo::refresh(); //refresh the servo
myservo4.write(value[3]);
SoftwareServo::refresh(); //refresh the servo
delay(dl);
}
else {
Serial.print("unexpected msg length of ");
Serial.println(msgLength);
}
Serial.println();
}
}