1#include <IRremote.h>
2
3
4int IRsensorPin = 12;
5
6
7IRrecv irrecv(IRsensorPin);
8decode_results results;
9
10
11int RightMotorForward = 2;
12int RightMotorBackward = 3;
13int LeftMotorForward = 4;
14int LeftMotorBackward = 5;
15int LeftLED = 6;
16int RightLED = 7;
17
18void setup(){
19
20
21 pinMode(LeftMotorForward,OUTPUT);
22 pinMode(RightMotorForward,OUTPUT);
23 pinMode(LeftMotorBackward,OUTPUT);
24 pinMode(RightMotorBackward,OUTPUT);
25 pinMode(LeftLED,OUTPUT);
26 pinMode(RightLED,OUTPUT);
27
28
29 Serial.begin(9600);
30 irrecv.enableIRIn();
31}
32
33void loop(){
34
35
36 if (irrecv.decode(&results)){
37
38
39 Serial.println(results.value);
40 delay(5);
41
42
43 irrecv.resume();
44 }
45
46 if(results.value == 752) MotorForward();
47 if(results.value == 2800) MotorBackward();
48 if(results.value == 3280) TurnRight();
49 if(results.value == 720) TurnLeft();
50 if(results.value == 2672) MotorStop();
51
52}
53
54
55void MotorForward(){
56 digitalWrite(LeftLED,LOW);
57 digitalWrite(RightLED,LOW);
58 digitalWrite(LeftMotorForward,HIGH);
59 digitalWrite(RightMotorForward,HIGH);
60 digitalWrite(LeftMotorBackward,LOW);
61 digitalWrite(RightMotorBackward,LOW);
62}
63
64
65void MotorBackward(){
66 digitalWrite(LeftLED,LOW);
67 digitalWrite(RightLED,LOW);
68 digitalWrite(LeftMotorBackward,HIGH);
69 digitalWrite(RightMotorBackward,HIGH);
70 digitalWrite(LeftMotorForward,LOW);
71 digitalWrite(RightMotorForward,LOW);
72}
73
74
75void TurnRight(){
76 digitalWrite(LeftLED,LOW);
77 digitalWrite(LeftMotorForward,HIGH);
78 digitalWrite(RightMotorForward,LOW);
79 digitalWrite(LeftMotorBackward,LOW);
80 digitalWrite(RightMotorBackward,HIGH);
81 digitalWrite(RightLED,HIGH);
82}
83
84
85void TurnLeft(){
86 digitalWrite(RightLED,LOW);
87 digitalWrite(RightMotorForward,HIGH);
88 digitalWrite(LeftMotorForward,LOW);
89 digitalWrite(LeftMotorBackward,HIGH);
90 digitalWrite(RightMotorBackward,LOW);
91 digitalWrite(LeftLED,HIGH);
92}
93
94
95void MotorStop(){
96 digitalWrite(LeftLED,LOW);
97 digitalWrite(RightLED,LOW);
98 digitalWrite(LeftMotorBackward,LOW);
99 digitalWrite(RightMotorBackward,LOW);
100 digitalWrite(LeftMotorForward,LOW);
101 digitalWrite(RightMotorForward,LOW);
102}
Anonymous user
4 years ago
THANK YOU VERY MUCH IT WORK'S VERY WELL I AM LOVE IT