1#include <SPI.h>
2#include <nRF24L01.h>
3#include <RF24.h>
4int motor1r = 2;
5int motor1l = 3;
6int motor2r = 4;
7int motor2l = 5;
8
9RF24 radio(7, 8);
10
11const byte address[6] = "00001";
12
13void setup() {
14
15 Serial.begin(9600);
16 pinMode(motor1r, OUTPUT);
17 pinMode(motor1l, OUTPUT);
18 pinMode(motor2r, OUTPUT);
19 pinMode(motor2l, OUTPUT);
20
21 radio.begin();
22 radio.openReadingPipe(0, address);
23 radio.setPALevel(RF24_PA_MIN);
24 radio.startListening();
25}
26
27void loop() {
28
29 if (radio.available()) {
30 char text[32] = "";
31 radio.read(&text, sizeof(text));
32 Serial.println(text);
33
34 if(strcmp(text,"right") == 0){
35 digitalWrite(motor1r, LOW);
36 digitalWrite(motor1l, HIGH);
37 digitalWrite(motor2r, HIGH);
38 digitalWrite(motor2l, LOW);
39 delay(70);
40 digitalWrite(motor1r, LOW);
41 digitalWrite(motor1l, LOW);
42 digitalWrite(motor2r, LOW);
43 digitalWrite(motor2l, LOW);
44 Serial.println("CAr turning right");
45 }
46 else if(strcmp(text,"left") == 0){
47 digitalWrite(motor1r, HIGH);
48 digitalWrite(motor1l, LOW);
49 digitalWrite(motor2r, LOW);
50 digitalWrite(motor2l, HIGH);
51 delay(70);
52 digitalWrite(motor1r, LOW);
53 digitalWrite(motor1l, LOW);
54 digitalWrite(motor2r, LOW);
55 digitalWrite(motor2l, LOW);
56 Serial.println("CAr turning left");
57 }
58 else if(strcmp(text,"forward") == 0){
59 digitalWrite(motor1r, HIGH);
60 digitalWrite(motor1l, LOW);
61 digitalWrite(motor2r, HIGH);
62 digitalWrite(motor2l, LOW);
63 delay(70);
64 digitalWrite(motor1r, LOW);
65 digitalWrite(motor1l, LOW);
66 digitalWrite(motor2r, LOW);
67 digitalWrite(motor2l, LOW);
68
69
70 Serial.println("CAr going forward");
71 }
72 else if(strcmp(text,"backward") == 0){
73 digitalWrite(motor1r, LOW);
74 digitalWrite(motor1l, HIGH);
75 digitalWrite(motor2r, LOW);
76 digitalWrite(motor2l, HIGH);
77 delay(70);
78 digitalWrite(motor1r, LOW);
79 digitalWrite(motor1l, LOW);
80 digitalWrite(motor2r, LOW);
81 digitalWrite(motor2l, LOW);
82 Serial.println("CAr going backward");
83 }
84 }
85
86
87}