how to use dc motor and servo same time with multiple rf channel

i am newbie to arduino, i like arduino alot, well i have made a RF control mini car using 433Mhz transmitter and reveiver with two arduinos. now i want to use servo for steering so how can i control a dc motor, a servo and some LEDs at the same time. i mean like in RC CARS i want to go forward and turn left and right at same time. i searched for some sources and found multiple channel in RF module would help but i couldnt understand. I have a pair of 433Mhz reveiver/ transmitter as well as 2x nrf24L01. can anyone please help me?

Thanks :slight_smile: :slight_smile:

Can you give us some more information on your setup. Is the 433Mhz transmitter a hobby transmitter like one for RC cars or planes, a serial data transmitter that would plug into your computer, a TV remote control like unit, or something else.

Depending on the type of transmitter the solution will vary a lot. An RC hobby transmitter could do this without an Arduino, while the other two would take an Arduino.

If you do need the Arduino, you also need to interface with the hobby servo and the DC motor. The hobby servo will just need a 5V supply (taking this from the Arduino is usually a bad idea). The servo library makes controlling these quite simple. The DC motor will need some form of motor controller. It is hard to recommend one without knowing the voltage and current of your motor, but if it is small I have used this one with good results. https://www.sparkfun.com/products/9457 Driving a DC motor with a motor controller is just a couple of digital pins and a PWM speed.

If you explain the code you already have, and post a copy of it, people may be able to suggest how to extend it for the extra capabilities.

...R

i have a working project, couple of frens and i made this

hope you get sufficient info from the video. i want to extend my project by using a 9g servo motor for steering. the code is simple when forward button is pressed it goes forward and similary for the right, left and backward, we used virtualwire library to establish the communication between the remote and car. well i have used L293D motor driver for the motor controller and we control two 6v dc motor using this.

I don’t know how to help if you don’t show a copy of your code.

…R

If your controller just consists of four switches then perhaps you could change your transmitting unit so that it supports combinations of switch states rather than just one switch at a time. For example, four switch positions could be encoded using four bits of a one-byte value which is sent at regular intervals.

this is the receiver code

// receiver.pde

#include <VirtualWire.h>

const int led_pin = 13;
const int inp1=4;
const int inp2=5;
const int inp3=6;
const int inp4=7;

const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;

void setup()
{
    delay(1000);
    Serial.begin(9600);	// Debugging only
    Serial.println("setup");

    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    vw_set_ptt_pin(transmit_en_pin);
    vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);	 // Bits per sec

    vw_rx_start();       // Start the receiver PLL running

    pinMode(led_pin, OUTPUT);
    pinMode(inp1, OUTPUT);
    pinMode(inp2, OUTPUT);
    pinMode(inp3, OUTPUT);
    pinMode(inp4, OUTPUT);
}

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

    if (vw_get_message(buf, &buflen)) // Non-blocking
    {
//	int i;

        digitalWrite(led_pin, HIGH); // Flash a light to show received good message
        if(((char)buf[0])=='f'){
          digitalWrite(inp2,HIGH);
          digitalWrite(inp1,LOW);
          digitalWrite(inp4,HIGH);
          digitalWrite(inp3,LOW);
        }else if(((char)buf[0])=='b'){
          digitalWrite(inp1,HIGH);
          digitalWrite(inp2,LOW);
          digitalWrite(inp3,HIGH);
          digitalWrite(inp4,LOW);
        }else if(((char)buf[0])=='l'){
          digitalWrite(inp1,HIGH);
          digitalWrite(inp2,LOW);
          digitalWrite(inp4,HIGH);
          digitalWrite(inp3,LOW);
        }else if(((char)buf[0])=='r'){
          digitalWrite(inp2,HIGH);
          digitalWrite(inp1,LOW);
          digitalWrite(inp3,HIGH);
          digitalWrite(inp4,LOW);
        }else if(((char)buf[0])=='s'){
          digitalWrite(inp1,LOW);
          digitalWrite(inp2,LOW);
          digitalWrite(inp3,LOW);
          digitalWrite(inp4,LOW);
        }
	// Message with a good checksum received, dump it.
//	Serial.print("Got: ");
	
//	for (i = 0; i < buflen; i++)
//	{
//	    Serial.print(buf[i], HEX);
//	    Serial.print(' ');
//	}
//	Serial.println();
//        digitalWrite(led_pin, LOW);
    }
}

and this is the transmitter code

// transmitter.pde

#include <VirtualWire.h>

const int led_pin = 3;
const int transmit_pin = 12;
const int receive_pin = 2;
//const int transmit_en_pin = 3;

int fbutton = 6;
int bbutton = 5;
int lbutton = 7;
int rbutton = 4;


void setup()
{
    // Initialise the IO and ISR
    vw_set_tx_pin(transmit_pin);
    vw_set_rx_pin(receive_pin);
    //vw_set_ptt_pin(transmit_en_pin);
   vw_set_ptt_inverted(true); // Required for DR3100
    vw_setup(2000);       // Bits per sec
    
    
    pinMode(led_pin, OUTPUT);
    
    pinMode(fbutton,INPUT_PULLUP);
    pinMode(bbutton,INPUT_PULLUP);
    pinMode(lbutton,INPUT_PULLUP);
    pinMode(rbutton,INPUT_PULLUP);
    //digitalWrite(fbutton,HIGH);
    //digitalWrite(bbutton,HIGH);
    //digitalWrite(lbutton,HIGH);
    //digitalWrite(rbutton,HIGH);
    Serial.begin(9600);
}

byte count = 1;

void loop()
{
  digitalWrite(led_pin,LOW);
  int left = digitalRead(lbutton);
  int right = digitalRead(rbutton);
  int forward = digitalRead(fbutton);
  int backward = digitalRead(bbutton);
  
  if(forward == LOW){
    Serial.println("forward");
   // digitalWrite(led_pin,HIGH);
  //Forward
  char msgf[1] = {'f'};
  //msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msgf, 1);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  //delay(1000);
  }
  else if(backward == LOW){
    Serial.println("Backward");
    digitalWrite(led_pin,HIGH);
    //Backward
  char msgb[1] = {'b'};
  //msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msgb, 1);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  //delay(1000);*/
  }
  else if(right == LOW){
    Serial.println("Right");
    digitalWrite(led_pin,HIGH);
  //Right
  char msgr[1] = {'r'};
  //msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msgr, 1);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  //delay(1000);*/
  }
  else if(left == LOW){
    Serial.println("Left");
    digitalWrite(led_pin,HIGH);
  //Left
  char msgl[1] = {'l'};
  //msg[6] = count;
  digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msgl, 1);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  //delay(1000);*/
  }
  else
  {
  Serial.println("Stop");
  char msgl[1] = {'s'};
  //msg[6] = count;
  //digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
  vw_send((uint8_t *)msgl, 1);
  vw_wait_tx(); // Wait until the whole message is gone
  digitalWrite(led_pin, LOW);
  }
  
}

Peter can you explain more in detail about the states and bits

thanks

Currently your commands consist of single characters 'f', 'b', 'l', 'r'. This means you can only send one command at a time.

Instead of sending ascii characters like that, you could encode the four input states in a single binary byte - it would only need four bits so easily represented as a single byte.

You can use the bitWrite() function to help you set individual bits in your message byte, and bitRead() to find which bits are set in the received byte.

If I were you I'd put my switch input pin numbers in an array, and use a FOR loop to initialise the pin modes, also use a FOR loop to read the input state and set the corresponding bit in your message byte. Finally you can use another FOR loop in the receiver to extract each bit and test whether it is set.

Peter, can you please provide me a simple code about your idea or provide me a link to some tutorials. thank u