Robot car |
This could be the future of technology someday. We can take it to the next level. Here we are going to explain the process of making this robot. Before the creation process, we will find out what is needed to make this. (You can watch the completed project from here)
Apparatus
- Arduino Uno board
Arduino Uno board |
- L293D Motor shield
L293D Motor shield |
- Servo motors (two motors needed)
Servo motors |
- Relay Module
Relay Module |
- DC Gear Motor with wheels
DC Gear Motor |
- Flame sensor
Flame sensor |
- 3.7V Rechargeable battery
Rechargeable battery |
- Spray bottle
- Mini water pump
Connection diagram
ARDUINO CODE
#include <AFMotor.h>
#include <Servo.h>
AF_DCMotor TopLeft(1);
AF_DCMotor TopRight(2);
AF_DCMotor BottomLeft(4);
AF_DCMotor BottomRight(3);
Servo Name1;
Servo Name2;
char value;
void setup() {
Serial.begin(9600);
Name1.attach(9);
Name2.attach(10);
pinMode(A5, INPUT); //flame sensor
pinMode(A4, OUTPUT); //relay(spray bottel)
pinMode(A3, OUTPUT); //relay(water pump)
digitalWrite(A4, HIGH);
digitalWrite(A3, HIGH);
Name1.write(90);
Name2.write(90);
delay(500);
}
void loop() {
if (digitalRead(A5) == LOW ) {
digitalWrite(A4, LOW);
digitalWrite(A3, LOW);
for (int j = 150; j >= 60; j -= 10) {
Name1.write(j);
delay(40);
for (int i = 0; i <= 120; i += 10) {
Name2.write(i);
if (Serial.available()) {
value = Serial.read();
Serial.print("value");
Serial.println(value);
if (value == '1') {
//forward
mpower(1, 200, 1);
mpower(2, 200, -1);
//right side motor
mpower(3, 200, 1);
mpower(4, 200, 1);
delay(100);
}
if (value == '2') {
//backward
mpower(1, 200, -1);
mpower(2, 200, 1);
//right side motor
mpower(3, 200, -1);
mpower(4, 200, -1);
delay(100);
}
if (value == '3') {
//turn righ
mpower(1, 200, 1);
mpower(2, 200, -1);
//right side motor
mpower(3, 200, -1);
mpower(4, 200, -1);
delay(100);
}
if (value == '4') {
//turn left
mpower(1, 255, -1);
mpower(2, 255, 1);
//right side motor
mpower(3, 255, 1);
mpower(4, 255, 1);
delay(100);
}
if (value == '0') {
//stop
mpower(1, 0, 1);
mpower(2, 0, -1);
//right side motor
mpower(3, 0, 1);
mpower(4, 0, 1);
delay(100);
}
}
delay(40);
}
}
}
else {
digitalWrite(A4, HIGH);
digitalWrite(A3, HIGH);
Name1.write(0);
Name2.write(90);
delay(500);
if (Serial.available()) {
value = Serial.read();
Serial.print("value");
Serial.println(value);
if (value == '1') {
//forward
mpower(1, 200, 1);
mpower(2, 200, -1);
//right side motor
mpower(3, 200, 1);
mpower(4, 200, 1);
delay(100);
}
if (value == '2') {
//backward
mpower(1, 200, -1);
mpower(2, 200, 1);
//right side motor
mpower(3, 200, -1);
mpower(4, 200, -1);
delay(100);
}
if (value == '3') {
//turn righ
mpower(1, 200, 1);
mpower(2, 200, -1);
//right side motor
mpower(3, 200, -1);
mpower(4, 200, -1);
delay(100);
}
if (value == '4') {
//turn left
mpower(1, 200, -1);
mpower(2, 200, 1);
//right side motor
mpower(3, 200, 1);
mpower(4, 200, 1);
delay(100);
}
if (value == '0') {
//stop
mpower(1, 0, 1);
mpower(2, 0, -1);
//right side motor
mpower(3, 0, 1);
mpower(4, 0, 1);
delay(100);
}
}
}
}
void mpower(int motor, int mspeed, int rdirection) {
if (motor == 1) {
TopLeft.setSpeed(mspeed);
if (rdirection == 1) {
TopLeft.run(FORWARD);
}
else if (rdirection == -1) {
TopLeft.run(BACKWARD);
}
}
else if (motor == 2) {
TopRight.setSpeed(mspeed);
if (rdirection == 1) {
TopRight.run(FORWARD);
}
else if (rdirection == -1) {
TopRight.run(BACKWARD);
}
}
else if (motor == 3) {
BottomRight.setSpeed(mspeed);
if (rdirection == 1) {
BottomRight.run(FORWARD);
}
else if (rdirection == -1) {
BottomRight.run(BACKWARD);
}
}
else if (motor == 4) {
BottomLeft.setSpeed(mspeed);
if (rdirection == 1) {
BottomLeft.run(FORWARD);
}
else if (rdirection == -1) {
BottomLeft.run(BACKWARD);
}
}
else {
return;
}
}
0 Comments