433 mhz RF Servo control Potentiometer value

Hi!
cant found a sketch for servo control from potentiometer value with rf control.
i want to make a project.

i have:

2x Uno
1x rf tansmitter and receiver
2x potentiometer
2x servo

cant buy xbee or bluetooth shield cuz expensive.

i want servos control from potentiometer on rf module.

so i need help :frowning:

sorry for my english i now little bit :slight_smile:

thank you!

Servo/pot test code:

//zoomkat dual pot/servo test 12-29-12
//view output using the serial monitor

#include <Servo.h> 
Servo myservoS1;
Servo myservoS2;

int potpinS1 = 0;  //analog input pin A0
int potpinS2 = 1;

int newvalS1, oldvalS1;
int newvalS2, oldvalS2;

void setup() 
{
  Serial.begin(9600);  
  myservoS1.attach(2);  
  myservoS2.attach(3);
  Serial.println("testing dual pot servo");  
}

void loop() 
{ 
  newvalS1 = analogRead(potpinS1);           
  newvalS1 = map(newvalS1, 0, 1023, 0, 179); 
  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    myservoS1.write(newvalS1);
    Serial.print("1- ");
    Serial.println(newvalS1);
    oldvalS1=newvalS1;
  }

  newvalS2 = analogRead(potpinS2);
  newvalS2 = map(newvalS2, 0, 1023, 0, 179);
  if (newvalS2 < (oldvalS2-2) || newvalS2 > (oldvalS2+2)){  
    myservoS2.write(newvalS2);
    Serial.print("2- ");    
    Serial.println(newvalS2);
    oldvalS2=newvalS2;
  }
  delay(50); //slow down looping to better read serial monitor 
}

Thank you Zoomkat

But i dont understand, is it transmitter or reciever code? How can i use it?
Remember i. Have 2x uno , 1x reciever and transmitter.

mydnc:
Thank you Zoomkat

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
    }
  }
}

tx test code

  if (newvalS1 < (oldvalS1-2) || newvalS1 > (oldvalS1+2)){  
    //myservoS1.write(newvalS1);
    //Serial.print("1- ");
    //Serial.println(newvalS1);
    Serial.print(newvalS1);
    Serial.print("a,");
    oldvalS1=newvalS1;
  }

like this project

youtube.com/watch?v=HeSlLBSnGWo

is that possible with 433 mhz rf module ?

reciever code

 // êîä ¹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 :blush:

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.

:slight_smile: