Components and supplies
Arduino UNO
9V battery (generic)
Ultrasonic Sensor - HC-SR04 (Generic)
Dual H-Bridge motor drivers L298
HC-05 Bluetooth Module
Jumper wires (generic)
Project description
Code
Noderover2 - Arduino Code
arduino
1// This Code is for Accident avoidance rover 2 3const int en1 = 9; 4const int en2 = 3; 5const int inp1 = 2; 6const int inp2 = 4; 7const int inp3 = 7; 8const int inp4 = 8; 9char charRead; 10String inputString = ""; 11 12//For ultrasonic sensor 13int trigPin = 10; 14int echoPin = 11; 15 16void setup() { 17 Serial.begin(9600); 18 19 pinMode(led, OUTPUT); 20 pinMode(trigPin, OUTPUT); 21 pinMode(echoPin, INPUT); 22 23 pinMode(en1, OUTPUT); 24 pinMode(en2, OUTPUT); 25 pinMode(inp1, OUTPUT); 26 pinMode(inp2, OUTPUT); 27 pinMode(inp3, OUTPUT); 28 pinMode(inp4, OUTPUT); 29} 30 31void loop() { 32 // put your main code here, to run repeatedly: 33 34 // Calculating distance of obstacle from rover 35 long duration, distance; 36 digitalWrite(trigPin, HIGH); 37 delay(1); 38 digitalWrite(trigPin, LOW); 39 duration = pulseIn(echoPin, HIGH); 40 distance = (duration / 2) / 29.1; 41 Serial.print(distance); 42 Serial.println("CM"); 43 delay(10); 44 45 if ((distance <= 17)) 46 { 47 // To Stop 48 digitalWrite(inp1, LOW); 49 digitalWrite(inp2, LOW); 50 digitalWrite(inp3, LOW); 51 digitalWrite(inp4, LOW); 52 if (Serial.available()) { 53 charRead = Serial.read(); 54 if (charRead != 'T') { 55 inputString += charRead; 56 } else { 57 if (inputString == "backward") { 58 // To move backward 59 digitalWrite(inp1, LOW); 60 digitalWrite(inp2, HIGH); 61 digitalWrite(inp3, LOW); 62 digitalWrite(inp4, HIGH); 63 delay(1500); 64 } 65 inputString = ""; 66 } 67 } 68 } 69 else { 70 if (Serial.available()) { 71 charRead = Serial.read(); 72 if (charRead != 'T') { 73 inputString += charRead; 74 } else { 75 if (inputString == "forward") { 76 // To move Forward 77 digitalWrite(inp1, HIGH); 78 digitalWrite(inp2, LOW); 79 digitalWrite(inp3, HIGH); 80 digitalWrite(inp4, LOW); 81 } 82 else if (inputString == "backward") { 83 // To move backward 84 digitalWrite(inp1, LOW); 85 digitalWrite(inp2, HIGH); 86 digitalWrite(inp3, LOW); 87 digitalWrite(inp4, HIGH); 88 } 89 else if (inputString == "fleft") { 90 // To move left 91 digitalWrite(inp1, HIGH); 92 digitalWrite(inp2, LOW); 93 digitalWrite(inp3, LOW); 94 digitalWrite(inp4, LOW); 95 } else if (inputString == "fright") { 96 // To move right 97 digitalWrite(inp1, LOW); 98 digitalWrite(inp2, LOW); 99 digitalWrite(inp3, HIGH); 100 digitalWrite(inp4, LOW); 101 } 102 else if (inputString == "bleft") { 103 // To move back left 104 digitalWrite(inp1, LOW); 105 digitalWrite(inp2, LOW); 106 digitalWrite(inp3, LOW); 107 digitalWrite(inp4, HIGH); 108 } 109 else if (inputString == "bright") { 110 // To move back right 111 digitalWrite(inp1, LOW); 112 digitalWrite(inp2, HIGH); 113 digitalWrite(inp3, LOW); 114 digitalWrite(inp4, LOW); 115 } 116 else if (inputString == "break") { 117 // To Stop 118 analogWrite(en1, 50); 119 analogWrite(en2, 50); 120 delay(550); 121 digitalWrite(inp1, LOW); 122 digitalWrite(inp2, LOW); 123 digitalWrite(inp3, LOW); 124 digitalWrite(inp4, LOW); 125 analogWrite(en1, 150); 126 analogWrite(en2, 150); 127 } 128 else if (inputString == "maxspeed") { 129 // Max speed 130 analogWrite(en1, 250); 131 analogWrite(en2, 250); 132 } 133 else if (inputString == "medspeed") { 134 // Medium Speed 135 analogWrite(en1, 180); 136 analogWrite(en2, 180); 137 } 138 else if (inputString == "lowspeed") { 139 // Low speed 140 analogWrite(en1, 90); 141 analogWrite(en2, 90); 142 } 143 else { 144 // Stop 145 digitalWrite(inp1, LOW); 146 digitalWrite(inp2, LOW); 147 digitalWrite(inp3, LOW); 148 digitalWrite(inp4, LOW); 149 } 150 inputString = ""; 151 } 152 } 153 } 154}
Noderover2 - Arduino Code
arduino
1// This Code is for Accident avoidance rover 2 3const int en1 = 9; 4const int en2 = 3; 5const int inp1 = 2; 6const int inp2 = 4; 7const int inp3 = 7; 8const int inp4 = 8; 9char charRead; 10String inputString = ""; 11 12//For ultrasonic sensor 13int trigPin = 10; 14int echoPin = 11; 15 16void setup() { 17 Serial.begin(9600); 18 19 pinMode(led, OUTPUT); 20 pinMode(trigPin, OUTPUT); 21 pinMode(echoPin, INPUT); 22 23 pinMode(en1, OUTPUT); 24 pinMode(en2, OUTPUT); 25 pinMode(inp1, OUTPUT); 26 pinMode(inp2, OUTPUT); 27 pinMode(inp3, OUTPUT); 28 pinMode(inp4, OUTPUT); 29} 30 31void loop() { 32 // put your main code here, to run repeatedly: 33 34 // Calculating distance of obstacle from rover 35 long duration, distance; 36 digitalWrite(trigPin, HIGH); 37 delay(1); 38 digitalWrite(trigPin, LOW); 39 duration = pulseIn(echoPin, HIGH); 40 distance = (duration / 2) / 29.1; 41 Serial.print(distance); 42 Serial.println("CM"); 43 delay(10); 44 45 if ((distance <= 17)) 46 { 47 // To Stop 48 digitalWrite(inp1, LOW); 49 digitalWrite(inp2, LOW); 50 digitalWrite(inp3, LOW); 51 digitalWrite(inp4, LOW); 52 if (Serial.available()) { 53 charRead = Serial.read(); 54 if (charRead != 'T') { 55 inputString += charRead; 56 } else { 57 if (inputString == "backward") { 58 // To move backward 59 digitalWrite(inp1, LOW); 60 digitalWrite(inp2, HIGH); 61 digitalWrite(inp3, LOW); 62 digitalWrite(inp4, HIGH); 63 delay(1500); 64 } 65 inputString = ""; 66 } 67 } 68 } 69 else { 70 if (Serial.available()) { 71 charRead = Serial.read(); 72 if (charRead != 'T') { 73 inputString += charRead; 74 } else { 75 if (inputString == "forward") { 76 // To move Forward 77 digitalWrite(inp1, HIGH); 78 digitalWrite(inp2, LOW); 79 digitalWrite(inp3, HIGH); 80 digitalWrite(inp4, LOW); 81 } 82 else if (inputString == "backward") { 83 // To move backward 84 digitalWrite(inp1, LOW); 85 digitalWrite(inp2, HIGH); 86 digitalWrite(inp3, LOW); 87 digitalWrite(inp4, HIGH); 88 } 89 else if (inputString == "fleft") { 90 // To move left 91 digitalWrite(inp1, HIGH); 92 digitalWrite(inp2, LOW); 93 digitalWrite(inp3, LOW); 94 digitalWrite(inp4, LOW); 95 } else if (inputString == "fright") { 96 // To move right 97 digitalWrite(inp1, LOW); 98 digitalWrite(inp2, LOW); 99 digitalWrite(inp3, HIGH); 100 digitalWrite(inp4, LOW); 101 } 102 else if (inputString == "bleft") { 103 // To move back left 104 digitalWrite(inp1, LOW); 105 digitalWrite(inp2, LOW); 106 digitalWrite(inp3, LOW); 107 digitalWrite(inp4, HIGH); 108 } 109 else if (inputString == "bright") { 110 // To move back right 111 digitalWrite(inp1, LOW); 112 digitalWrite(inp2, HIGH); 113 digitalWrite(inp3, LOW); 114 digitalWrite(inp4, LOW); 115 } 116 else if (inputString == "break") { 117 // To Stop 118 analogWrite(en1, 50); 119 analogWrite(en2, 50); 120 delay(550); 121 digitalWrite(inp1, LOW); 122 digitalWrite(inp2, LOW); 123 digitalWrite(inp3, LOW); 124 digitalWrite(inp4, LOW); 125 analogWrite(en1, 150); 126 analogWrite(en2, 150); 127 } 128 else if (inputString == "maxspeed") { 129 // Max speed 130 analogWrite(en1, 250); 131 analogWrite(en2, 250); 132 } 133 else if (inputString == "medspeed") { 134 // Medium Speed 135 analogWrite(en1, 180); 136 analogWrite(en2, 180); 137 } 138 else if (inputString == "lowspeed") { 139 // Low speed 140 analogWrite(en1, 90); 141 analogWrite(en2, 90); 142 } 143 else { 144 // Stop 145 digitalWrite(inp1, LOW); 146 digitalWrite(inp2, LOW); 147 digitalWrite(inp3, LOW); 148 digitalWrite(inp4, LOW); 149 } 150 inputString = ""; 151 } 152 } 153 } 154}
Downloadable files
Data Transmission
Data Transmission
Circuit Diagram
Circuit Diagram
Data Transmission
Data Transmission
Comments
Only logged in users can leave comments
adityahazarika08
0 Followers
•2 Projects
2
0