Devices & Components
Arduino Uno Rev3
5v dc motors
L298n - driver for stepper motor
18650 battery cell
Wheels for the motors
Remote Control
IR Sensors
Jumper wires (generic)
Hardware & Tools
drill, screwdriver, soldering iron
Software & Tools
Arduino IDE
Project description
Code
IR sensor Set Up
js
1#include<IRremote.h> 2const int RemotePin=8; 3IRrecv irrecv(RemotePin); 4decode_results results; 5void setup() { 6 // put your setup code here, to run once: 7 Serial.begin(9600); 8 irrecv.enableIRIn(); 9} 10 11void loop() { 12 // put your main code here, to run repeatedly: 13 if(irrecv.decode(&results)) 14 { 15 Serial.println(results.value, HEX); 16 delay(200); 17 irrecv.resume(); 18 } 19}
Code for Control Motors
js
1#include<IRremote.h> 2const int RemotePin=8; 3IRrecv irrecv(RemotePin); 4decode_results results; 5int in1=3; 6int in2=5; 7int in3=6; 8int in4=9; 9 10void setup() { 11 Serial.begin(9600); 12 irrecv.enableIRIn(); 13 pinMode(in1, OUTPUT); 14 pinMode(in2, OUTPUT); 15 pinMode(in3, OUTPUT); 16 pinMode(in4, OUTPUT); 17 18} 19 20void loop() { 21 22 if(irrecv.decode(&results)) 23 { 24 if (results.value==0xFF629D)//Press UP Button 25 { 26 Forward(); 27 } 28 else if (results.value==0xFFA857)//Press Down Button 29 { 30 Backward(); 31 } 32 else if (results.value==0xFF22DD)//Press Left Button 33 { 34 Left(); 35 } 36 else if (results.value==0xFFC23D)//Press Right Button 37 { 38 Right(); 39 } 40 else if (results.value==0xFF02FD)//Stop 41 { 42 Stop(); 43 } 44 irrecv.resume(); 45 } 46 } 47 48 49void Backward() 50 { 51 digitalWrite(in1,HIGH); 52 digitalWrite(in2,LOW); 53 digitalWrite(in3,HIGH); 54 digitalWrite(in4,LOW); 55 } 56 void Forward() 57 { 58 digitalWrite(in1,LOW); 59 digitalWrite(in2,HIGH); 60 digitalWrite(in3,LOW); 61 digitalWrite(in4,HIGH); 62 } 63 void Stop() 64 { 65 digitalWrite(in1,LOW); 66 digitalWrite(in2,LOW); 67 digitalWrite(in3,LOW); 68 digitalWrite(in4,LOW); 69 } 70 int Left() 71 { 72 digitalWrite(in1,LOW); 73 digitalWrite(in2,LOW); 74 digitalWrite(in3,LOW); 75 digitalWrite(in4,HIGH); 76 } 77 int Right() 78 { 79 digitalWrite(in1,LOW); 80 digitalWrite(in2,HIGH); 81 digitalWrite(in3,LOW); 82 digitalWrite(in4,LOW); 83 }
Downloadable files
3D Printed chassis
Chassis.stl
Comments
Only logged in users can leave comments