Exploring Mars on a Budget
Abstract:
Mars exploration has always captivated the human imagination, but sending a rover to the red planet involves significant costs and advanced technology. However, with creativity and a bit of ingenuity, you can embark on your own budget-friendly Mars exploration project right here on Earth. In this article, we'll guide you through building a Mars rover prototype using Arduino, Bluetooth control, obstacle avoidance sensors, and an IP camera.
Table of Contents:
- Needed Material
- Circuit Connections
- Building the Hardware & Software
- Source Code
- Working Prototype
- Conclusion
Materials Needed:
- Arduino board (e.g., Arduino Uno or Arduino Nano)
- Motor driver module (e.g., L298N)
- DC motors and wheels
- Bluetooth module (e.g., HC-05)
- Ultrasonic sensors for obstacle avoidance
- Chassis or frame for the rover
- Power source (e.g., rechargeable batteries)
- IP camera (e.g., Mobile)
- Servo Motor
- Jumper wires and soldering kit
Building the Hardware:
VCC (Bluetooth) to Arduino Connect the VCC pin of the HC-05 to the 5V output on the Arduino Uno.GND (Bluetooth) to Arduino:Connect the GND pin of the HC-05 to one of the GND (ground) pins on the Arduino Uno.TXD (Bluetooth) to Arduino RX (Pin 3):Connect the TXD pin of the HC-05 to the RX (receive) pin (Pin 3) on the Arduino Uno. This is where the Bluetooth module sends data to the Arduino.RXD (Bluetooth) to Arduino TX (Pin 2):Connect the RXD pin of the HC-05 to the TX (transmit) pin (Pin 2) on the Arduino Uno. This is where the Bluetooth module receives data from the Arduino.
3. Motor Driver Module (L298N) Connections:
Enable Pins (ENA and ENB):Connect the ENA (Enable A) and ENB (Enable B) pins on the L298N to any two digital PWM pins on the Arduino (e.g., Pin 10 and Pin 5).
Motor Connections:
Connect the OUT1 and OUT2 pins on the L298N to one motor.Connect the OUT3 and OUT4 pins on the L298N to another motor.Connect the respective terminals of the motors to the positive and negative terminals on the L298N.
Power Supply Connections:
Connect the GND of the motor driver to the GND on the Arduino.Connect the +12V input of the motor driver to an external power source (e.g., the positive terminal of your battery).Connect the GND of the external power source to the GND on the Arduino.
Control Pins (IN1, IN2, IN3, IN4):Connect the IN1, IN2, IN3, and IN4 pins on the L298N to any four digital pins on the Arduino (e.g., Pin 9, Pin 8, Pin 7, and Pin 6).
4. Ultrasonic Sensor Connections:
Enable Pins (ENA and ENB):Connect the ENA (Enable A) and ENB (Enable B) pins on the L298N to any two digital PWM pins on the Arduino (e.g., Pin 10 and Pin 5).
Motor Connections:
Connect the OUT1 and OUT2 pins on the L298N to one motor.Connect the OUT3 and OUT4 pins on the L298N to another motor.Connect the respective terminals of the motors to the positive and negative terminals on the L298N.
Connect the OUT1 and OUT2 pins on the L298N to one motor.Connect the OUT3 and OUT4 pins on the L298N to another motor.Connect the respective terminals of the motors to the positive and negative terminals on the L298N.
Power Supply Connections:
Connect the GND of the motor driver to the GND on the Arduino.Connect the +12V input of the motor driver to an external power source (e.g., the positive terminal of your battery).Connect the GND of the external power source to the GND on the Arduino.
Connect the GND of the motor driver to the GND on the Arduino.Connect the +12V input of the motor driver to an external power source (e.g., the positive terminal of your battery).Connect the GND of the external power source to the GND on the Arduino.
Control Pins (IN1, IN2, IN3, IN4):Connect the IN1, IN2, IN3, and IN4 pins on the L298N to any four digital pins on the Arduino (e.g., Pin 9, Pin 8, Pin 7, and Pin 6).
4. Ultrasonic Sensor Connections:
VCC (Ultrasonic Sensor) to Arduino:Connect the VCC pin of the ultrasonic sensor to the 5V output on the Arduino Uno.GND (Ultrasonic Sensor) to Arduino:Connect the GND pin of the ultrasonic sensor to one of the GND (ground) pins on the Arduino Uno.Trigger Pin to Arduino:Connect the Trigger pin of the ultrasonic sensor to any digital pin on the Arduino (e.g., Pin A3).Echo Pin to Arduino:Connect the Echo pin of the ultrasonic sensor to any digital pin on the Arduino (e.g., Pin A2).
5. Servo Motor Connections:
VCC (Ultrasonic Sensor) to Arduino:
Connect the VCC pin of the ultrasonic sensor to the 5V output on the Arduino Uno.GND (Ultrasonic Sensor) to Arduino:Connect the GND pin of the ultrasonic sensor to one of the GND (ground) pins on the Arduino Uno.
Trigger Pin to Arduino:Connect the Trigger pin of the ultrasonic sensor to any digital pin on the Arduino (e.g., Pin A3).
Echo Pin to Arduino:Connect the Echo pin of the ultrasonic sensor to any digital pin on the Arduino (e.g., Pin A2).
5. Servo Motor Connections:
Power and Ground for Servo:Connect the power (usually red wire) from the servo motor to the 5V output on the Arduino Uno.Connect the ground (usually brown wire) from the servo motor to one of the GND (ground) pins on the Arduino Uno.Control (Signal) Wire for Servo:Connect the control (signal) wire from the servo motor (usually yellow or orange) to any digital PWM pin on the Arduino Uno (e.g., Pin A4).
Power and Ground for Servo:Connect the power (usually red wire) from the servo motor to the 5V output on the Arduino Uno.Connect the ground (usually brown wire) from the servo motor to one of the GND (ground) pins on the Arduino Uno.
Control (Signal) Wire for Servo:Connect the control (signal) wire from the servo motor (usually yellow or orange) to any digital PWM pin on the Arduino Uno (e.g., Pin A4).
Connecting Servo to the Rover:
Mounting Servo for Sensor Movement:
Mount the servo motor in a way that it can control the movement of the ultrasonic or any other component on the rover if u want.
Mounting Servo for Sensor Movement:
Mount the servo motor in a way that it can control the movement of the ultrasonic or any other component on the rover if u want.
6. Power Connection:
Power Source:Connect the positive (+) terminal of your power source (such as a battery) to the Arduino's VIN (Voltage In) pin if you're using an external power supply.If you're powering the Arduino through USB, make sure it's connected to a computer or a power source through a USB cable.Ground Connection:Connect the negative (-) terminal of your power source (or the ground, GND) to any of the GND (ground) pins on the Arduino.
Note:
The VIN pin on the Arduino is used to supply an external voltage (e.g., from a battery). It can accept a voltage range from 7V to 12V, depending on the Arduino model. Always check the specifications for your specific Arduino board.If you're using the same battery for both the motors and the Arduino, ensure that the voltage is within the acceptable range for the Arduino and any other components.When using a separate battery for the Arduino and motors, it's essential to connect the grounds of both power sources together. This creates a common ground reference for all the components in your circuit.
By properly connecting the power source to the Arduino, you ensure that the microcontroller has the necessary power to operate, allowing your Mars rover project to function as intended. Always refer to the Arduino board's documentation for specific details about voltage requirements and power connections.
7. Integrating the IP Camera:
To use the IP camera feature, first install an app called DroidCam from the Play Store. Then, copy the camera access link from the app and paste it into your Rover app. This will enable you to view your camera live.
By properly connecting the power source to the Arduino, you ensure that the microcontroller has the necessary power to operate, allowing your Mars rover project to function as intended. Always refer to the Arduino board's documentation for specific details about voltage requirements and power connections.
7. Integrating the IP Camera:
To use the IP camera feature, first install an app called DroidCam from the Play Store. Then, copy the camera access link from the app and paste it into your Rover app. This will enable you to view your camera live.
Follow the steps for More:
Follow the steps for More:
step 1 :
step 2 :
step 3 :
step 4 :
Programming the Arduino:
When developing code for a robot, it's important to create a harmonious blend of functionalities. Here's the code I wrote for our rover. If you want any customization, we can address it accordingly.
//*************************//Code By Sakshyam Bastakoti//**********************//
#include <SoftwareSerial.h>SoftwareSerial BT_Serial(2, 3); // RX, TX
#define enA 10//Enable1 L298 Pin enA #define in1 9 //Motor1 L298 Pin in1 #define in2 8 //Motor1 L298 Pin in1 #define in3 7 //Motor2 L298 Pin in1 #define in4 6 //Motor2 L298 Pin in1 #define enB 5 //Enable2 L298 Pin enB
#define servo A4
#define echo A2 //Echo pin#define trigger A3 //Trigger pin
int distance_L, distance_F = 30, distance_R;long distance;int set = 20;
int bt_data; // variable to receive data from the serial port and IRremoteint Speed = 130; int mode=0;
void setup(){ // put your setup code here, to run once
pinMode(echo, INPUT );// declare ultrasonic sensor Echo pin as inputpinMode(trigger, OUTPUT); // declare ultrasonic sensor Trigger pin as Output
pinMode(enA, OUTPUT); // declare as output for L298 Pin enA pinMode(in1, OUTPUT); // declare as output for L298 Pin in1 pinMode(in2, OUTPUT); // declare as output for L298 Pin in2 pinMode(in3, OUTPUT); // declare as output for L298 Pin in3 pinMode(in4, OUTPUT); // declare as output for L298 Pin in4 pinMode(enB, OUTPUT); // declare as output for L298 Pin enB
Serial.begin(9600); // start serial communication at 9600bpsBT_Serial.begin(9600);
pinMode(servo, OUTPUT);
for (int angle = 70; angle <= 140; angle += 5) { servoPulse(servo, angle); } for (int angle = 140; angle >= 0; angle -= 5) { servoPulse(servo, angle); }
for (int angle = 0; angle <= 70; angle += 5) { servoPulse(servo, angle); }delay(500);}
void loop(){
if(BT_Serial.available() > 0){ //if some date is sent, reads it and saves in state bt_data = BT_Serial.read(); Serial.println(bt_data); if(bt_data > 20){Speed = bt_data;} }
if(bt_data == 8){mode=0; Stop();} //Manual Android Application and IR Remote Control Command else if(bt_data ==10){mode=2; Speed=255;} //Auto Obstacle Avoiding Command
analogWrite(enA, Speed); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed analogWrite(enB, Speed); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed
if(mode==0){ //===============================================================================// Key Control Command//=============================================================================== if(bt_data == 1){forword(); } // if the bt_data is '1' the DC motor will go forwardelse if(bt_data == 2){backword();} // if the bt_data is '2' the motor will Reverseelse if(bt_data == 3){turnLeft();} // if the bt_data is '3' the motor will turn leftelse if(bt_data == 4){turnRight();} // if the bt_data is '4' the motor will turn rightelse if(bt_data == 5){Stop(); } // if the bt_data '5' the motor will Stop
//===============================================================================// Voice Control Command//=============================================================================== else if(bt_data == 6){turnLeft(); delay(400); bt_data = 5;}else if(bt_data == 7){turnRight(); delay(400); bt_data = 5;}}
if(mode==2){ //===============================================================================// Obstacle Avoiding Control//=============================================================================== distance_F = Ultrasonic_read(); Serial.print("S=");Serial.println(distance_F); if (distance_F > set){forword();} else{Check_side();}}
delay(10);}
void servoPulse (int pin, int angle){int pwm = (angle*11) + 500; // Convert angle to microseconds digitalWrite(pin, HIGH); delayMicroseconds(pwm); digitalWrite(pin, LOW); delay(50); // Refresh cycle of servo}
//**********************Ultrasonic_read****************************long Ultrasonic_read(){ digitalWrite(trigger, LOW); delayMicroseconds(2); digitalWrite(trigger, HIGH); delayMicroseconds(10); distance = pulseIn (echo, HIGH); return distance / 29 / 2;}
void compareDistance(){ if (distance_L > distance_R){ turnLeft(); delay(350); } else if (distance_R > distance_L){ turnRight(); delay(350); } else{ backword(); delay(300); turnRight(); delay(600); }}
void Check_side(){ Stop(); delay(100); for (int angle = 70; angle <= 140; angle += 5) { servoPulse(servo, angle); } delay(300); distance_L = Ultrasonic_read(); delay(100); for (int angle = 140; angle >= 0; angle -= 5) { servoPulse(servo, angle); } delay(500); distance_R = Ultrasonic_read(); delay(100); for (int angle = 0; angle <= 70; angle += 5) { servoPulse(servo, angle); } delay(300); compareDistance();}
void forword(){ //forworddigitalWrite(in1, HIGH); //Right Motor forword Pin digitalWrite(in2, LOW); //Right Motor backword Pin digitalWrite(in3, LOW); //Left Motor backword Pin digitalWrite(in4, HIGH); //Left Motor forword Pin }
void backword(){ //backworddigitalWrite(in1, LOW); //Right Motor forword Pin digitalWrite(in2, HIGH); //Right Motor backword Pin digitalWrite(in3, HIGH); //Left Motor backword Pin digitalWrite(in4, LOW); //Left Motor forword Pin }
void turnRight(){ //turnRightdigitalWrite(in1, LOW); //Right Motor forword Pin digitalWrite(in2, HIGH); //Right Motor backword Pin digitalWrite(in3, LOW); //Left Motor backword Pin digitalWrite(in4, HIGH); //Left Motor forword Pin }
void turnLeft(){ //turnLeftdigitalWrite(in1, HIGH); //Right Motor forword Pin digitalWrite(in2, LOW); //Right Motor backword Pin digitalWrite(in3, HIGH); //Left Motor backword Pin digitalWrite(in4, LOW); //Left Motor forword Pin }
void Stop(){ //stopdigitalWrite(in1, LOW); //Right Motor forword Pin digitalWrite(in2, LOW); //Right Motor backword Pin digitalWrite(in3, LOW); //Left Motor backword Pin digitalWrite(in4, LOW); //Left Motor forword Pin }
//*************************//Code By Sakshyam Bastakoti//**********************//
So, This is the Complete code of our Project. To download All files (App, circuit Diagram, Code ) : Click Here
App Interface
App Interface
Connect the Bluetooth Module:Power on your Arduino and ensure the HC-05 Bluetooth module is paired with your Android device.Upload Updated Arduino Code:Upload the modified Arduino code to your Arduino board.Launch the R.O.V.E.R application :Install the generated Android app on your device and allow permission for it.Connect to Bluetooth:Open the app, connect to the Bluetooth module, and start controlling your Mars rover
//*************************//Code By Sakshyam Bastakoti//**********************//
#include <SoftwareSerial.h>
SoftwareSerial BT_Serial(2, 3); // RX, TX
#define enA 10//Enable1 L298 Pin enA
#define in1 9 //Motor1 L298 Pin in1
#define in2 8 //Motor1 L298 Pin in1
#define in3 7 //Motor2 L298 Pin in1
#define in4 6 //Motor2 L298 Pin in1
#define enB 5 //Enable2 L298 Pin enB
#define servo A4
#define echo A2 //Echo pin
#define trigger A3 //Trigger pin
int distance_L, distance_F = 30, distance_R;
long distance;
int set = 20;
int bt_data; // variable to receive data from the serial port and IRremote
int Speed = 130;
int mode=0;
void setup(){ // put your setup code here, to run once
pinMode(echo, INPUT );// declare ultrasonic sensor Echo pin as input
pinMode(trigger, OUTPUT); // declare ultrasonic sensor Trigger pin as Output
pinMode(enA, OUTPUT); // declare as output for L298 Pin enA
pinMode(in1, OUTPUT); // declare as output for L298 Pin in1
pinMode(in2, OUTPUT); // declare as output for L298 Pin in2
pinMode(in3, OUTPUT); // declare as output for L298 Pin in3
pinMode(in4, OUTPUT); // declare as output for L298 Pin in4
pinMode(enB, OUTPUT); // declare as output for L298 Pin enB
Serial.begin(9600); // start serial communication at 9600bps
BT_Serial.begin(9600);
pinMode(servo, OUTPUT);
for (int angle = 70; angle <= 140; angle += 5) {
servoPulse(servo, angle); }
for (int angle = 140; angle >= 0; angle -= 5) {
servoPulse(servo, angle); }
for (int angle = 0; angle <= 70; angle += 5) {
servoPulse(servo, angle); }
delay(500);
}
void loop(){
if(BT_Serial.available() > 0){ //if some date is sent, reads it and saves in state
bt_data = BT_Serial.read();
Serial.println(bt_data);
if(bt_data > 20){Speed = bt_data;}
}
if(bt_data == 8){mode=0; Stop();} //Manual Android Application and IR Remote Control Command
else if(bt_data ==10){mode=2; Speed=255;} //Auto Obstacle Avoiding Command
analogWrite(enA, Speed); // Write The Duty Cycle 0 to 255 Enable Pin A for Motor1 Speed
analogWrite(enB, Speed); // Write The Duty Cycle 0 to 255 Enable Pin B for Motor2 Speed
if(mode==0){
//===============================================================================
// Key Control Command
//===============================================================================
if(bt_data == 1){forword(); } // if the bt_data is '1' the DC motor will go forward
else if(bt_data == 2){backword();} // if the bt_data is '2' the motor will Reverse
else if(bt_data == 3){turnLeft();} // if the bt_data is '3' the motor will turn left
else if(bt_data == 4){turnRight();} // if the bt_data is '4' the motor will turn right
else if(bt_data == 5){Stop(); } // if the bt_data '5' the motor will Stop
//===============================================================================
// Voice Control Command
//===============================================================================
else if(bt_data == 6){turnLeft(); delay(400); bt_data = 5;}
else if(bt_data == 7){turnRight(); delay(400); bt_data = 5;}
}
if(mode==2){
//===============================================================================
// Obstacle Avoiding Control
//===============================================================================
distance_F = Ultrasonic_read();
Serial.print("S=");Serial.println(distance_F);
if (distance_F > set){forword();}
else{Check_side();}
}
delay(10);
}
void servoPulse (int pin, int angle){
int pwm = (angle*11) + 500; // Convert angle to microseconds
digitalWrite(pin, HIGH);
delayMicroseconds(pwm);
digitalWrite(pin, LOW);
delay(50); // Refresh cycle of servo
}
//**********************Ultrasonic_read****************************
long Ultrasonic_read(){
digitalWrite(trigger, LOW);
delayMicroseconds(2);
digitalWrite(trigger, HIGH);
delayMicroseconds(10);
distance = pulseIn (echo, HIGH);
return distance / 29 / 2;
}
void compareDistance(){
if (distance_L > distance_R){
turnLeft();
delay(350);
}
else if (distance_R > distance_L){
turnRight();
delay(350);
}
else{
backword();
delay(300);
turnRight();
delay(600);
}
}
void Check_side(){
Stop();
delay(100);
for (int angle = 70; angle <= 140; angle += 5) {
servoPulse(servo, angle); }
delay(300);
distance_L = Ultrasonic_read();
delay(100);
for (int angle = 140; angle >= 0; angle -= 5) {
servoPulse(servo, angle); }
delay(500);
distance_R = Ultrasonic_read();
delay(100);
for (int angle = 0; angle <= 70; angle += 5) {
servoPulse(servo, angle); }
delay(300);
compareDistance();
}
void forword(){ //forword
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void backword(){ //backword
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, HIGH); //Right Motor backword Pin
digitalWrite(in3, HIGH); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
void turnRight(){ //turnRight
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, HIGH); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, HIGH); //Left Motor forword Pin
}
void turnLeft(){ //turnLeft
digitalWrite(in1, HIGH); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, HIGH); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
void Stop(){ //stop
digitalWrite(in1, LOW); //Right Motor forword Pin
digitalWrite(in2, LOW); //Right Motor backword Pin
digitalWrite(in3, LOW); //Left Motor backword Pin
digitalWrite(in4, LOW); //Left Motor forword Pin
}
//*************************//Code By Sakshyam Bastakoti//**********************//
So, This is the Complete code of our Project. To download All files (App, circuit Diagram, Code ) : Click Here
App Interface
App Interface |
Connect the Bluetooth Module:
Power on your Arduino and ensure the HC-05 Bluetooth module is paired with your Android device.
Upload Updated Arduino Code:
Upload the modified Arduino code to your Arduino board.
Launch the R.O.V.E.R application :
Install the generated Android app on your device and allow permission for it.
Connect to Bluetooth:
Open the app, connect to the Bluetooth module, and start controlling your Mars rover
Working Prototype
Here are Some of the images and videos of our Rover :
Rover
These are the complete steps to make your own rover. If you have any questions or confusion related to this project, please feel free to ask. Also, don't forget to leave a comment if you liked this project and have made your own rover.
Conclusion:Building a DIY Mars rover prototype is an exciting way to explore robotics and space exploration concepts. With Arduino, Bluetooth control, obstacle avoidance, servo motor control, and an IP camera, you can simulate the exploration of Mars right in your backyard. This project not only provides hands-on learning but also sparks the imagination about the possibilities of space exploration.
Here are Some of the images and videos of our Rover :
Rover |
These are the complete steps to make your own rover. If you have any questions or confusion related to this project, please feel free to ask. Also, don't forget to leave a comment if you liked this project and have made your own rover.
Conclusion:
Building a DIY Mars rover prototype is an exciting way to explore robotics and space exploration concepts. With Arduino, Bluetooth control, obstacle avoidance, servo motor control, and an IP camera, you can simulate the exploration of Mars right in your backyard. This project not only provides hands-on learning but also sparks the imagination about the possibilities of space exploration.