Pages: [1]   Go Down
Author Topic: Wireless controll of servo  (Read 422 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey guys, im trying to control a servo through an 433MHz RF link.
the code:
Quote
 #include <ServoTimer2.h>
#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round

ServoTimer2 servo;

int i = 0;
void setup()
{
    Serial.begin(9600);   

// Initialise the IO and ISR
    vw_set_ptt_inverted(true);    // Required for RX Link Module
    vw_setup(2000);                   // Bits per sec
    vw_set_rx_pin(0);           // We will be receiving on pin 23 (Mega) ie the RX pin from the module connects to this pin.
    vw_rx_start();                      // Start the receiver
    servo.attach(A2);
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen)) // check to see if anything has been received
    {
    int i;
     // Message with a good checksum received.
        
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf);  // the received data is stored in buffer
        }
    Serial.println("");
     }
     else if(buf == 1){
       servo.write(0)d
       delay (50);
     }
     else {
         servo.write(875);
         delay(50);
       }
  //else if(buf == 1){
   // servo.write(0);
  //}
  //else if(buf == 0){
    //servo.write(1750);
  //}
  
}

But when i i upload the code to the boarf the servo dosent respond all the time. but the serial print does. can anynone see and error with the code?
Thanks in regards
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 7
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Code:
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf);  // the received data is stored in buffer
        }
    Serial.println("");
     }
     else if(buf == 1){
       servo.write(0)d
       delay (50);
     }
     else {
         servo.write(875);
         delay(50);
       }
  //else if(buf == 1){

This is junk. Specially the buf==1 part.
Also, a delay of 50 ms doesn't give your servo to move very far.

Korman
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

dunno why it put a d in there. its not in my code :/
and the buff == 1 should be buff == 1

but ill try and change the delay (:
Logged

Pages: [1]   Go Up
Jump to: