//simple Tx on pin D12 //.................................. #include // this library makes it very easy to send a character wich allows the motors to be active. // First we give all the inputs or outputs a name. int en1 = 5; int en2 = 6; int in1 = 9; int in2 = 10; int in3 = 7; int in4 = 8; int light1=3; int light2=4; int motorPin[] = {3,4, 5, 6, 7, 8, 9, 10};//array for storing pin nos void setup() { Serial.begin(9600); // Debugging only Serial.println("setup"); vw_set_ptt_inverted(true); // Required for DR3100 vw_set_rx_pin(12); vw_setup(4000); // Bits per sec pinMode(13, OUTPUT); vw_rx_start(); // Start the receiver PLL running for (int i = 0; i < 3; i++) { pinMode(motorPin[i], OUTPUT); pinMode(in1, OUTPUT); pinMode(in2,OUTPUT); }} void loop(){ // this is the recieving code. this controls how many int you can send. 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(13, true); // Flash a light to show received good message // Message with a good checksum received, dump it. for (i = 0; i < buflen; i++) { if(buf[0]=='2')//when the number 2 is recieved it will turn motor1 on and it should go forward. { forward();//go forward Serial.println(" = forward"); } if(buf[i] == '1')//when the number 1 is recieved it will turn motor1 on and it should go backward. { backward();//go backward Serial.println(" = backward"); } if(buf[i] == '4')//when the number 4 is recieved it will turn motor2 on and it should go left. { left();//go left Serial.println(" = left"); } if(buf[i] == '3')//when the number 3 is recieved it will turn motor2 on and it should go right. { right();//go right Serial.println(" = right"); } if(buf[i] == '5')//when the number 5 is recieved it should turn everything off { stopMotor();//stop/brake Serial.println(" = stopped"); } if(buf[i] == 'b')//when the letter b is recieved it will turn motor1 off { stopforward();//stop/brake } if(buf[i] == 'a')//when the letter a is recieved it will turn motor1 off { stopbackward();//stop/brake } if(buf[i] == 'd')//when the letter d is recieved it will turn motor2 off { stopleft();//stop/brake } if(buf[i] == 'c')//when the letter c is recieved it will turn motor2 off { stopright();//stop/brake } if(buf[i] == '8') //when the number 8 is recieved it will turn on the sirens {Sirens(); Serial.println(" = SIRENS"); } if(buf[i] == 'f') {stopSirens();}//when the letter F is recieved it will turn off the sirens } digitalWrite(13, false); } } //from here we define which outputs will be high or low. void forward() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in1,HIGH); digitalWrite(in2, LOW); } void stopforward() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in1,LOW); } void backward() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in1,LOW); digitalWrite(in2,HIGH); } void stopbackward() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in2,LOW); } void left() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in3,LOW); digitalWrite(in4,HIGH); } void stopleft() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in4,LOW); } void right() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in3,HIGH); digitalWrite(in4,LOW); } void stopright() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in3,LOW); } void stopMotor() { digitalWrite(en1,HIGH); digitalWrite(en2,HIGH); digitalWrite(in1,LOW); digitalWrite(in2,LOW); digitalWrite(in3,LOW); digitalWrite(in4,LOW); } void Sirens(){ digitalWrite(light1,HIGH); digitalWrite(light2,LOW); delay(100); digitalWrite(light1,LOW); digitalWrite(light2,HIGH); delay(100); } void stopSirens(){ digitalWrite(light1,LOW); digitalWrite(light2,LOW); } //End Of Code