(ARDUINO) Servos not responding to the updated values

Discussion in 'Embedded Systems and Microcontrollers' started by onlyvinod56, Aug 14, 2016.

  1. onlyvinod56

    Thread Starter Active Member

    Oct 14, 2008
    362
    1
    Hello All,

    As a part of my audio amplifier project, I want to design a RF based remote volume controller. I am using 433 MHz transceiver pair. I wired three 10K pots to analog pins A0,A1 and A2 of an ARDUINO board with the 433 Tx module.

    Then I wired three servos to another ARDUINO board with 433 Rx module.

    I took the example codes from VirtualWire.h.

    The Tx and Rx modules are successfully communicating. The POT values from Tx are being displayed in the COM port of Rx Arduino. The values are updating successfully but the servos are not responding.

    To check the servos, I used another code (without Tx Rx modules) just to make them rotate. They are working.
    Please see the attachments.

    Tx code:

    Code (C):
    1.  
    2. // transmitter.pde
    3. //
    4. // Simple example of how to use VirtualWire to transmit messages
    5. // Implements a simplex (one-way) transmitter with an TX-C1 module
    6. //
    7. // See VirtualWire.h for detailed API docs
    8. // Author: Mike McCauley (mikem@airspayce.com)
    9. // Copyright (C) 2008 Mike McCauley
    10. // $Id: transmitter.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
    11.  
    12. #include <VirtualWire.h>
    13.  
    14. const int led_pin = 13;
    15. const int transmit_pin = 12;
    16. const int receive_pin = 2;
    17. const int transmit_en_pin = 3;
    18.  
    19. void setup()
    20. {
    21.     // Initialise the IO and ISR
    22.     vw_set_tx_pin(transmit_pin);
    23.     vw_set_rx_pin(receive_pin);
    24.     vw_set_ptt_pin(transmit_en_pin);
    25.     vw_set_ptt_inverted(true); // Required for DR3100
    26.     vw_setup(2000);       // Bits per sec
    27.     pinMode(led_pin, OUTPUT);
    28. }
    29.  
    30. byte count = 1;
    31.  
    32. void loop()
    33. {
    34.   char msg[5] = {analogRead(A0),analogRead(A1),analogRead(A2)};
    35.  
    36.   //msg[6] = count;
    37.   digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
    38.   vw_send((uint8_t *)msg, 3);
    39.   vw_wait_tx(); // Wait until the whole message is gone
    40.   digitalWrite(led_pin, LOW);
    41.   delay(1000);
    42.   //count = count + 1;
    43. }
    44.  






    Rx Code

    Code (C):
    1.  
    2. // receiver.pde
    3. //
    4. // Simple example of how to use VirtualWire to receive messages
    5. // Implements a simplex (one-way) receiver with an Rx-B1 module
    6. //
    7. // See VirtualWire.h for detailed API docs
    8. // Author: Mike McCauley (mikem@airspayce.com)
    9. // Copyright (C) 2008 Mike McCauley
    10. // $Id: receiver.pde,v 1.3 2009/03/30 00:07:24 mikem Exp $
    11.  
    12. #include <VirtualWire.h>
    13. #include <ServoTimer2.h>
    14.  
    15. #define rollPin  6
    16. #define pitchPin 9
    17. #define yawPin   10
    18.  
    19. ServoTimer2 servoRoll;    // declare variables for up to eight servos
    20. ServoTimer2 servoPitch;
    21. ServoTimer2 servoYaw;
    22.  
    23.  
    24. const int led_pin = 13;
    25. const int transmit_pin = 12;
    26. const int receive_pin = 11;
    27. const int transmit_en_pin = 3;
    28.  
    29. int x,y,z;
    30.  
    31. void setup()
    32. {
    33.  
    34.    servoRoll.attach(rollPin);     // attach a pin to the servos and they will start pulsing
    35.   servoPitch.attach(pitchPin);
    36.   servoYaw.attach(yawPin);
    37.   delay(1000);
    38.     Serial.begin(9600);    // Debugging only
    39.     Serial.println("setup");
    40.  
    41.     // Initialise the IO and ISR
    42.     vw_set_tx_pin(transmit_pin);
    43.     vw_set_rx_pin(receive_pin);
    44.     vw_set_ptt_pin(transmit_en_pin);
    45.     vw_set_ptt_inverted(true); // Required for DR3100
    46.     vw_setup(2000);    // Bits per sec
    47.  
    48.     vw_rx_start();       // Start the receiver PLL running
    49.  
    50.     pinMode(led_pin, OUTPUT);
    51. }
    52.  
    53. void loop()
    54. {
    55.     uint8_t buf[VW_MAX_MESSAGE_LEN];
    56.     uint8_t buflen = VW_MAX_MESSAGE_LEN;
    57.  
    58.     if (vw_get_message(buf, &buflen)) // Non-blocking
    59.     {
    60.     int i;
    61.  
    62.         digitalWrite(led_pin, HIGH); // Flash a light to show received good message
    63.     // Message with a good checksum received, dump it.
    64.     Serial.print("Got: ");
    65.  
    66.     for (i = 0; i < buflen; i++)
    67.     {
    68.        //Serial.print(buf[i], DEC);
    69.      
    70. if(i==0)
    71. {x=buf[0];x=map(x,0,255,0,179); servoRoll.write(x);Serial.print("x= ");Serial.print(x);Serial.print(' ');}
    72. if(i==1)
    73. {y=buf[1];y=map(y,0,255,0,179);servoPitch.write(y);Serial.print("y= ");Serial.print(y);Serial.print(' ');}
    74. if(i==2)
    75. {z=buf[2];z=map(z,0,255,0,179);servoYaw.write(z);Serial.print("z= ");Serial.print(z);Serial.print(' ');}
    76.  
    77.  
    78.  
    79.     }
    80.     Serial.println();
    81.         digitalWrite(led_pin, LOW);
    82.     }
    83. }
    84.  
    IMG_20160814_211440.jpg IMG_20160814_211500.jpg Untitled.png
     
  2. shteii01

    AAC Fanatic!

    Feb 19, 2010
    3,387
    497
    Schematic.
     
  3. onlyvinod56

    Thread Starter Active Member

    Oct 14, 2008
    362
    1
    I am attaching the circuits. I used additional USB cable to power the SERVOs.

    Rxxxxxxxxxxxxxxx.png

    txxxxx.png
     
  4. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,802
    832
    You are mapping your input values to degrees.

    ServoTimer2 is different from the Arduino Servo library in that it's input is in microseconds, not degrees. So you are providing the wrong value to the servo routine.

    The valid range for the input value depends on the make of servo you have. Generally, it ranges from 750 to 2250 microseconds. 1500 microseconds is the 90 degree position per the standard.

    So, the range you are mapping to - 0 to 179 - is out of the valid range for RC servos.
     
  5. be80be

    Senior Member

    Jul 5, 2008
    431
    57
    Code (Text):
    1. map(x,0,255,1000,2000)
    But that's not going to give you the control id say you would want.
    You probably need to send your adc value 0 to 1000 then map that 1000 to 2000
    but you need to test the range of your servo not all are dead on.
    Some take a lower and higher value to get full swing.
     
  6. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,802
    832
    Actually, I'd do it like this:

    Code (Text):
    1. const int servoMin=1000;
    2. Const int servoMax=2500;
    3. .
    4. .
    5. .
    6. map(x,0,255,servoMin,servoMax);
    7.  
     
  7. onlyvinod56

    Thread Starter Active Member

    Oct 14, 2008
    362
    1
    Thank you djsfantasi and be80be. I will do the modifications and update the result.
     
Loading...