Components and supplies
Jumper wires (generic)
Arduino Nano R3
Dual H-Bridge motor drivers L293D
Apps and platforms
Arduino IDE
Project description
Code
Program
c_cpp
1#include "IRremote.h" 2 3int receiver = 11; 4int velocity1 = 100; 5int velocity2 = 100; 6 7int x; 8int Power__ON = 0; 9 10const int M1P1 = 7; 11const int M1N1 = 8; 12 13const int M2P2 = 9; 14const int M2N2 = 10; 15 16const int M1__Speed = 6; 17const int M2__Speed = 5; 18 19IRrecv irrecv(receiver); 20decode_results results; 21 22void setup() 23{ 24 Serial.begin(9600); 25 irrecv.enableIRIn(); 26 pinMode(M1P1, OUTPUT); 27 pinMode(M1N1, OUTPUT); 28 pinMode(M2P2, OUTPUT); 29 pinMode(M2N2, OUTPUT); 30 pinMode(M1__Speed, OUTPUT); 31 pinMode(M2__Speed, OUTPUT); 32} 33void loop() 34{ 35 if (irrecv.decode(&results)) 36 { 37 x = results.value & 0x0000ff; 38 Serial.println(results.value, HEX); 39 processIR(); 40 irrecv.resume(); 41 } 42 43} 44void processIR() 45{ 46 if (x == 0x1f) //previous 47 { 48 Serial.println("Motor 1 rotates forward"); 49 digitalWrite(M1P1, HIGH); 50 digitalWrite(M1N1, LOW); 51 analogWrite(M1__Speed, velocity1); 52 } 53 else if (x == 0x57) //next 54 { 55 Serial.println("Motor 2 rotates forward"); 56 digitalWrite(M2P2, LOW); 57 digitalWrite(M2N2, HIGH); 58 analogWrite(M2__Speed, velocity2); 59 } 60 else if (x == 0x5d) //turn on 61 { 62 Power__ON = Power__ON + 1; 63 int x = Power__ON % 2; 64 Serial.println(x); 65 if (x == 0) 66 { 67 Serial.println("Both Motor goes OFF"); 68 digitalWrite(M1P1, LOW); 69 digitalWrite(M1N1, LOW); 70 digitalWrite(M1P1, LOW); 71 digitalWrite(M1N1, LOW); 72 analogWrite(M1__Speed, 0); 73 analogWrite(M2__Speed, 0); 74 75 } 76 else 77 { 78 Serial.println("Both Motor ready to run"); 79 digitalWrite(M1P1, HIGH); 80 digitalWrite(M1N1, LOW); 81 digitalWrite(M1P1, HIGH); 82 digitalWrite(M1N1, LOW); 83 } 84 } 85 else if (x == 0x67) // vol+ 86 { 87 velocity1 = velocity1 + 10; 88 analogWrite(M1__Speed, velocity1); 89 Serial.println(velocity1); 90 } 91 else if (x == 0x97) // vol- 92 { 93 velocity1 = velocity1 - 10; 94 analogWrite(M1__Speed, velocity1); 95 Serial.println(velocity1); 96 } 97 else if (x == 0xdd) //mode 98 { 99 velocity2 = velocity2 + 10; 100 analogWrite(M2__Speed, velocity2); 101 Serial.println(velocity2); 102 } 103 else if (x == 0x3d) //equ 104 { 105 velocity2 = velocity2 - 10; 106 analogWrite(M2__Speed, velocity2); 107 Serial.println(velocity2); 108 } 109 else 110 { 111 112 } 113 delay(500); 114} 115
Program
c_cpp
1#include "IRremote.h" 2 3int receiver = 11; 4int velocity1 = 100; 5int velocity2 = 100; 6 7int x; 8int Power__ON = 0; 9 10const int M1P1 = 7; 11const int M1N1 = 8; 12 13const int M2P2 = 9; 14const int M2N2 = 10; 15 16const int M1__Speed = 6; 17const int M2__Speed = 5; 18 19IRrecv irrecv(receiver); 20decode_results results; 21 22void setup() 23{ 24 Serial.begin(9600); 25 irrecv.enableIRIn(); 26 pinMode(M1P1, OUTPUT); 27 pinMode(M1N1, OUTPUT); 28 pinMode(M2P2, OUTPUT); 29 pinMode(M2N2, OUTPUT); 30 pinMode(M1__Speed, OUTPUT); 31 pinMode(M2__Speed, OUTPUT); 32} 33void loop() 34{ 35 if (irrecv.decode(&results)) 36 { 37 x = results.value & 0x0000ff; 38 Serial.println(results.value, HEX); 39 processIR(); 40 irrecv.resume(); 41 } 42 43} 44void processIR() 45{ 46 if (x == 0x1f) //previous 47 { 48 Serial.println("Motor 1 rotates forward"); 49 digitalWrite(M1P1, HIGH); 50 digitalWrite(M1N1, LOW); 51 analogWrite(M1__Speed, velocity1); 52 } 53 else if (x == 0x57) //next 54 { 55 Serial.println("Motor 2 rotates forward"); 56 digitalWrite(M2P2, LOW); 57 digitalWrite(M2N2, HIGH); 58 analogWrite(M2__Speed, velocity2); 59 } 60 else if (x == 0x5d) //turn on 61 { 62 Power__ON = Power__ON + 1; 63 int x = Power__ON % 2; 64 Serial.println(x); 65 if (x == 0) 66 { 67 Serial.println("Both Motor goes OFF"); 68 digitalWrite(M1P1, LOW); 69 digitalWrite(M1N1, LOW); 70 digitalWrite(M1P1, LOW); 71 digitalWrite(M1N1, LOW); 72 analogWrite(M1__Speed, 0); 73 analogWrite(M2__Speed, 0); 74 75 } 76 else 77 { 78 Serial.println("Both Motor ready to run"); 79 digitalWrite(M1P1, HIGH); 80 digitalWrite(M1N1, LOW); 81 digitalWrite(M1P1, HIGH); 82 digitalWrite(M1N1, LOW); 83 } 84 } 85 else if (x == 0x67) // vol+ 86 { 87 velocity1 = velocity1 + 10; 88 analogWrite(M1__Speed, velocity1); 89 Serial.println(velocity1); 90 } 91 else if (x == 0x97) // vol- 92 { 93 velocity1 = velocity1 - 10; 94 analogWrite(M1__Speed, velocity1); 95 Serial.println(velocity1); 96 } 97 else if (x == 0xdd) //mode 98 { 99 velocity2 = velocity2 + 10; 100 analogWrite(M2__Speed, velocity2); 101 Serial.println(velocity2); 102 } 103 else if (x == 0x3d) //equ 104 { 105 velocity2 = velocity2 - 10; 106 analogWrite(M2__Speed, velocity2); 107 Serial.println(velocity2); 108 } 109 else 110 { 111 112 } 113 delay(500); 114} 115
Downloadable files
Circuit Diagram
Circuit Diagram
Comments
Only logged in users can leave comments
boaz
0 Followers
•0 Projects
Table of contents
Intro
4
0