But i dont understand, is it transmitter or reciever code? How can i use it?
Remember i. Have 2x uno , 1x reciever and transmitter.
The code posted would be on the transmit side. Note that I would get the two arduinos communicating with wiring between the tx/rx/gnd on the boards before trying to add the RF part of the project. I'd start with the rx code first and test with the serial monitor, then work on the tx code. Below is some rx cervo test code that might be of use. Try the code with the serial monitor and verify you can control the servos. If that works, If the rx code works, then you could modify the tx code like bottom to accomidate the receiving code.
rx test code
//zoomkat 11-22-12 simple delimited ',' string parse
//from serial port input (via serial monitor)
//and print result out serial port
//multi servos added
String readString;
#include <Servo.h>
Servo myservoa, myservob, myservoc, myservod; // create servo object to control a servo
void setup() {
Serial.begin(9600);
//myservoa.writeMicroseconds(1500); //set initial servo position if desired
myservoa.attach(6); //the pin for the servoa control
myservob.attach(7); //the pin for the servob control
myservoc.attach(8); //the pin for the servoc control
myservod.attach(9); //the pin for the servod control
Serial.println("multi-servo-delimit-test-dual-input-11-22-12"); // so I can keep track of what is loaded
}
void loop() {
//expect single strings like 700a, or 1500c, or 2000d,
//or like 30c, or 90a, or 180d,
//or combined like 30c,180b,70a,120d,
if (Serial.available()) {
char c = Serial.read(); //gets one byte from serial buffer
if (c == ',') {
if (readString.length() >1) {
Serial.println(readString); //prints string to serial port out
int n = readString.toInt(); //convert readString into a number
// auto select appropriate value, copied from someone elses code.
if(n >= 500)
{
Serial.print("writing Microseconds: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.writeMicroseconds(n);
if(readString.indexOf('b') >0) myservob.writeMicroseconds(n);
if(readString.indexOf('c') >0) myservoc.writeMicroseconds(n);
if(readString.indexOf('d') >0) myservod.writeMicroseconds(n);
}
else
{
Serial.print("writing Angle: ");
Serial.println(n);
if(readString.indexOf('a') >0) myservoa.write(n);
if(readString.indexOf('b') >0) myservob.write(n);
if(readString.indexOf('c') >0) myservoc.write(n);
if(readString.indexOf('d') >0) myservod.write(n);
}
readString=""; //clears variable for new input
}
}
else {
readString += c; //makes the string readString
}
}
}
// êîä ¹2 (receiver)
// Arduino NRF24L01+ Servo radio potentiometer wireless Control
#include <Servo.h>
#include <SPI.h>
#include "RF24.h"
Servo myservo; // create servo object to control a servo
//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 10//CE -> 9
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int msg[1];
void setup()
{
// Serial.begin(9600);
myservo.attach(3); // attaches the servo on pin 3 to the servo object
radio.begin();
radio.openReadingPipe(1,pipe);
radio.startListening();
}
void loop()
{
if (radio.available()){
bool done = false;
while (!done){
done = radio.read(msg, 1);
myservo.write (msg[0]);
//Serial.println(msg[0]);
}
}
}
transmitter code
#include <SPI.h>
#include "RF24.h"
int msg[1];
//SCK -> 13//MISO -> 12//MOSI -> 11//CSN -> 10//CE -> 9
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
RF24 radio(9,10);
const uint64_t pipe = 0xE8E8F0F0E1LL;
int potpin = 4; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup(void){
radio.begin();
radio.openWritingPipe(pipe); //
}
void loop(void){
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
msg[0] = val;
radio.write(msg, 1);
}
can we change rf24 library ?
maybe we can add virtualwire is that possible?
check this pls
You need a full duplex radio link to do this , as you need feedback from the servo as to what its position is .
You can do this with the NRF type radio modules as they are bi directional, but the 433 Mhz modules are not.
mauried:
You need a full duplex radio link to do this , as you need feedback from the servo as to what its position is .
You can do this with the NRF type radio modules as they are bi directional, but the 433 Mhz modules are not.
I didn't see any of what appears to be bidirectional communication in the youtube video. The servo looks to be a standard hobby type, which provides no feedback external to the servo itself.