control servo motors using potentiometer using rf txr and rxr

Hi
I'm currently working on a project in which I have to control 2 servo motors with 2 potentiometers using 433Mhz rf transmitter and receiver.can anyone help me with a code that I can use to do same please.
I'm really running out of time please if anyone could help me please doo...!!! This is the code I wrote
Rxr code:
#include <VirtualWire.h>

const int numberOfAnalogPins = 2; // how many analog integer values to receive
int data[numberOfAnalogPins]; // the data buffer

// the number of bytes in the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int);
int val,val1;

byte msgLength = dataBytes;

void setup()
{
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(5,OUTPUT);
pinMode(4,OUTPUT);
Serial.begin(9600);
Serial.println("Ready");
digitalWrite(9,HIGH);
digitalWrite(8,LOW);
digitalWrite(5,HIGH);
digitalWrite(4,LOW);
// Initialize the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec

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*);*

  • if(i=0)*
  • {*
    _ val=data*;_
    _
    val=map(val,0,1023,0,255);_
    _
    analogWrite(9,val);_
    _
    }_
    _
    if(i=1)_
    _
    {*_

_ val1=data*;
val1=map(val1,0,1023,0,255);
analogWrite(5,val1);
}*_

* }*
* }*
* else*
* {*
* Serial.print("unexpected msg length of ");*
* Serial.println(msgLength);*
* }*
* Serial.println();*
* }*
}
Txr code:
#include <VirtualWire.h>
const int numberOfAnalogPins = 2; // how many analog pins to read
int data[numberOfAnalogPins]; // the data buffer
const int dataBytes = numberOfAnalogPins * sizeof(int); // the number of bytes
* // in the data buffer*
void setup()
{
* // Initialize the IO and ISR*
* vw_setup(2000); // Bits per sec*
}
void loop()
{
* int values = 0;*
* for(int i=0; i <= numberOfAnalogPins; i++)*
* {*
* // read the analog ports*
_ data = analogRead(i); // store the values into the data buffer
* }
send((byte)data, dataBytes);

* delay(1000); //send every second*
}
void send (byte *data, int nbrOfBytes)
{
* vw_send(data, nbrOfBytes);
vw_wait_tx(); // Wait until the whole message is gone*

}_

It sounds like you should have started earlier.

The main purpose of this section of the forum is to provide programming help rather than writing software for you. If you want the program written for you then the Gigs and Collaborations section of the forum would be more appropriate.

Below is some servo/pot test code setup to limit transmission of commands to just changes in position.

//zoomkat multi pot/servo test 3-23-13
//includes dead band for testing and limit servo hunting
//view output using the serial monitor

#include <Servo.h> 
Servo myservo1;  //declare servos
Servo myservo2;
Servo myservo3;
Servo myservo4;
Servo myservo5;

int potpin1 = 0;  //analog input pin A0
int potpin2 = 1;
int potpin3 = 2;
int potpin4 = 3;
int potpin5 = 4;

int newval1, oldval1;  //pot input values
int newval2, oldval2;
int newval3, oldval3;
int newval4, oldval4;
int newval5, oldval5;

void setup() 
{
  Serial.begin(9600);  
  myservo1.attach(2);  
  myservo2.attach(3);
  myservo3.attach(4);
  myservo4.attach(5);
  myservo5.attach(6);
  Serial.println("testing multi pot servo");  
}

void loop()
{ 
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179); 
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ //dead band 
    myservo1.write(newval1); //position the servo
    Serial.print(newval1); //print the new value for testing 
    Serial.print("a,");
    oldval1=newval1; //set the current old value
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){  
    myservo2.write(newval2);
    Serial.print(newval2);
    Serial.print("b,");
    oldval2=newval2;
  }

  newval3 = analogRead(potpin3);           
  newval3 = map(newval3, 0, 1023, 0, 179); 
  if (newval1 < (oldval3-2) || newval3 > (oldval3+2)){  
    myservo3.write(newval3);
    Serial.print(newval3);
    Serial.print("c,");
    oldval3=newval3;
  }

  newval4 = analogRead(potpin4);           
  newval4 = map(newval4, 0, 1023, 0, 179); 
  if (newval4 < (oldval4-2) || newval4 > (oldval4+2)){  
    myservo1.write(newval4);
    Serial.print(newval4);
    Serial.print("d,");
    oldval4=newval4;
  }

  newval5 = analogRead(potpin5);           
  newval5 = map(newval5, 0, 1023, 0, 179); 
  if (newval5 < (oldval5-2) || newval5 > (oldval5+2)){  
    myservo5.write(newval5);
    Serial.print(newval5);
    Serial.print("e,");
    oldval5=newval5;
  } 
  delay(50);  //to slow loop for testing, adjust as needed
}

I want to control servo motor on receiver side by using voltage regulator on transmitter side(433mHz).

And pigs want to fly. That is not going to happen any time soon. Get over it.

I m also working on same project

For goodness sake. read this then add code tags to your code to avoid it being mangled by the forum software.

How hard can it be to follow simple instructions ?

I m just confused about
this part (is it right)

Why not print
the value after
mapping, to answer
your own question?

If you are going to throw away half the data, why not save time, and throw the data away BEFORE sending?

Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html
then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Please read guys...

Also what tx and rx are you using, what Arduino are you using.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
(Not a Fritzy diagram please!!)

Thanks... Tom... :slight_smile: