arduino - Read Mutiple Channels of 9 Channel Transmitter Receiver -


i have 9 channel rf rx/tx,i want connect 3 motors it.i able connect channel 1 motor1 unable connect channel2 motor2 simultaneously ardunio.pls take @ code. cant able rotate motors different channels

    int motor1left = 7;// defines pin 5 connected motor int motor1right= 9;// defines pin 6 connected motor int motor2left = 22;// defines pin 7 connected motor int motor2right = 26;// defines pin 8 connected motor int enable = 5; int enable2 = 10; int channel1 = 2; // defines channels connected int channel2 = 3;// pins 9 , 10 of arduino respectively  int channel1 ; // used later  int channel2 ; // store values  void  setup () {    pinmode (motor1left, output);// initialises motor pins    pinmode (motor1right, output);    pinmode (motor2left, output);    pinmode (motor2right, output);// outputs    pinmode (channel1, input);// initialises channels    pinmode (channel2, input);// inputs   //pinmode (enable, output);       serial.begin (9600); // sets baud rate 9600 bps   }  void  loop () {   channel1 = (pulsein (channel1, high)); // checks value of channel1    serial.println (channel1); //prints channels value on serial monitor   delay(1000);    channel2 = (pulsein (channel2, high)); // checks value of channel1   serial.println (channel2); //prints channels value value on serial monitor   delay(1000);    if (channel1 > 1470 && channel1 < 1500) /*if these conditions true, following. these values got transmitter, may customize according transmitter values */   {     digitalwrite (motor1left, low); // sets both     digitalwrite (motor1right, low);// motors low    analogwrite(enable, 100);   }    if (channel1 < 1460) // checks if channel1 lesser 1300   {     digitalwrite (motor1left, high);// turns left     digitalwrite (motor1right, low); // motor forward     analogwrite(enable, 100);     //delay(500);      //delay(500);     //digitalwrite(motor1left, low);     //delay(1); }    if (channel1 > 1510) // checks if channel1 greater 1500   {     digitalwrite (motor1left, low);// turns right      digitalwrite (motor1right, high);// motor forward      analogwrite(enable, 70);      //delay(500);     //digitalwrite (motor1right, low);    // delay(50);     //digitalwrite (motor1right, high);   }    if (channel2 > 1480 && channel1 < 1500 ) // if these conditions true, following   {     digitalwrite (motor2left, low);// sets both     digitalwrite (motor2right, low);// motors low     analogwrite (enable2, 100); }    if (channel2 < 1300) // checks if channel2 lesser 1300   {     digitalwrite (motor2left, low);// turns left     digitalwrite (motor2right, high);// motor backward     analogwrite (enable2, 100);   }   if (channel2 > 1500) // checks if channel2 greater 1500   {     digitalwrite (motor2left, high);// turns right     digitalwrite (motor2right, low);// motor backward     analogwrite (enable2, 100);   } } 

i see couple of problems:

  • you mention 3 motors, there appear 2.
  • you print out th value read, don't have identify one. consider adding "serial.print("ch1 = ");" before first println differentiate.
  • about line 72, have mixed channel2 , channel1.
  • in both channels, have dead zones readings. example, channel 1, happen if channel1 1465? or 1460 or 1470? in cases none of "if" statements fire. in channel2 lower dead zone bigger, , upper dead zone still there (what if channel2 1500?).

lastly, still seems motor should have done something. maybe because channel 1 less 1500. if still doesn't work, check wiring.

also, style note: use channel1 input pin read. use channel1 value read that. these extremely similar looking. if had mistyped one, impossible spot. should consider naming these in way makes easier spot mistake, , more obvious. example, channel1 become pinch1, , channel1 become inpch1. others might suggest more descriptive names, possibly first letter indicating data type. e.g., int ichannel1_pinnumber; int ichannel1_inputvalue;


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -