Remote Controlled Tank Robot
My project is a remote control robot that started as a base project with the basic robot with to moters connected to a H-Bridge,which controls the moters,and wired it to a audrino. It was coded to go in all directions autonomusly before I wired a reciver to the audrino and coded it to be controled through the remote control as well as turn on 4 LEDs through a switch on the controler.
Engineer | School | Area of Interest | Grade |
---|---|---|---|
Max G | Rambam | Aerospace Engineering | Junior |
Final Milestone
My final milestone is wiring and coding 4 LEDs into the robot to be turned on or off through a switch. This required me to read the values that are inputed through the switch but didn’t require me to change the values to a range of 0-255 like with the other controls because I wasn’t controling any moters. This made the coding a lot easier as I was able to find the code to light up the LEDs through the audrino coding platform and I didn’t have to create a compleatly new map statment for this control.
Second Milestone
My second milestone is making my robot controlable via a remote controller and connecting the reciever to the audrino. This was especally difficult since the controller sends values to the audrino through the reciever in a range of 1000-2000 while the moters are only able to take in values in a range of 0-255. Because of this I had to code my robot to read the values from the controller and then map the values into a range of 0-255. Then I had to code the robot to do certin controls depending on the values send by the controller for each of it’s inputs. This took a lot of work and troubleshooting both in the code and with the robot itself and is by far the most challenging part of my project.
First Milestone
My first milestone is the compleation of the of my base project,compleat with two moters and H-bridge wired to the audrino. The moters are connected to the H-bridge which sends a series of electric pulses to the moters to activate them depending on what it recives from the audrino.I also compleated some sample code that allowed me to see how my robot would operate and to give me a idea of what code to write for my modifications. One problem I faced was that while the moter on the right side ran according to the code, the left moter didn’t and instead continuously ran and didn’t stop at the designated time in my code. Another problem was that the moters ran in oppisite directions. After test running my code and troubleshooting I found out the problems were due to a falty wire and minor errors in my code.
Schematics
Code
#include <EnableInterrupt.h>
#define SERIAL_PORT_SPEED 9600
#define RC_NUM_CHANNELS 4
#define LED_pin 2
#define LED_pin1 3
#define LED_pin2 11
#define LED_pin3 12
const int A_1B=5;
const int A_1A=6;
const int B_1B=9;
const int B_1A=10;
#define RC_CH1 0
#define RC_CH2 1
#define RC_CH3 2
#define RC_CH5 3
#define RC_CH1_INPUT A0
#define RC_CH2_INPUT A1
#define RC_CH3_INPUT A2
#define RC_CH5_INPUT A3
uint16_t rc_values[RC_NUM_CHANNELS];
uint32_t rc_start[RC_NUM_CHANNELS];
volatile uint16_t rc_shared[RC_NUM_CHANNELS];
void rc_read_values() {
noInterrupts();
memcpy(rc_values, (const void *)rc_shared, sizeof(rc_shared));
interrupts();
}
void calc_input(uint8_t channel, uint8_t input_pin) {
if (digitalRead(input_pin) == HIGH) {
rc_start[channel] = micros();
} else {
uint16_t rc_compare = (uint16_t)(micros() - rc_start[channel]);
rc_shared[channel] = rc_compare;
}
}
void calc_ch1() { calc_input(RC_CH1, RC_CH1_INPUT); }
void calc_ch2() { calc_input(RC_CH2, RC_CH2_INPUT); }
void calc_ch3() { calc_input(RC_CH3, RC_CH3_INPUT); }
void calc_ch5() { calc_input(RC_CH5, RC_CH5_INPUT); }
void setup() {
Serial.begin(SERIAL_PORT_SPEED);
const int A_1B=5;
const int A_1A=6;
const int B_1B=9;
const int B_1A=10;
pinMode( LED_pin, OUTPUT);
pinMode( LED_pin1, OUTPUT);
pinMode( LED_pin2, OUTPUT);
pinMode( LED_pin3, OUTPUT);
pinMode(A_1B,OUTPUT);
pinMode(A_1A,OUTPUT);
pinMode(B_1B,OUTPUT);
pinMode(B_1A,OUTPUT);
pinMode(RC_CH1_INPUT, INPUT);
pinMode(RC_CH2_INPUT, INPUT);
pinMode(RC_CH3_INPUT, INPUT);
pinMode(RC_CH5_INPUT, INPUT);
enableInterrupt(RC_CH1_INPUT, calc_ch1, CHANGE);
enableInterrupt(RC_CH2_INPUT, calc_ch2, CHANGE);
enableInterrupt(RC_CH3_INPUT, calc_ch3, CHANGE);
enableInterrupt(RC_CH5_INPUT, calc_ch5, CHANGE);
}
void loop(){
rc_read_values();
Serial.print("CH2:"); Serial.print(rc_values[RC_CH2]); Serial.print("\t");
Serial.print("CH3:"); Serial.print(rc_values[RC_CH3]); Serial.print("\t");
Serial.print("CH5:"); Serial.println(rc_values[RC_CH5]);
int newCH2=map(rc_values[RC_CH2], 1000, 1984, 0, 254);
int newCH3=map(rc_values[RC_CH3], 1012, 1988, 0, 254);
Serial.print("CH2:"); Serial.print(newCH2); Serial.print("\t");
Serial.print("CH3:"); Serial.print(newCH3); Serial.print("\t");
if (newCH2 < 115 and newCH3 > 155) {
moveForward();
// Serial.print("moving foward right");
}
else if (newCH2 > 135 and newCH3 < 125) {
moveBackward();
// Serial.print("moving back right");
}
else if (newCH3 > 155 and newCH2 > 135) {
turnRight();
//Serial.print("moving foward left");
}
else if (newCH3 < 125 and newCH2 < 115) {
turnLeft();
// Serial.print("moving back left");
}
else {
stopMove();
//Serial.print("stop_left");
}
if (rc_values[RC_CH5] < 1600) {
digitalWrite(LED_pin, HIGH);
digitalWrite(LED_pin1, HIGH);
digitalWrite(LED_pin2, HIGH);
digitalWrite(LED_pin3, HIGH);
}
else if (rc_values[RC_CH5] > 1600) {
digitalWrite(LED_pin, LOW);
digitalWrite(LED_pin1, LOW);
digitalWrite(LED_pin2, LOW);
digitalWrite(LED_pin3, LOW);
}
}
void moveForward(){
digitalWrite(A_1B,LOW);
digitalWrite(A_1A,HIGH);
digitalWrite(B_1B,HIGH);
digitalWrite(B_1A,LOW);
}
void moveBackward(){
digitalWrite(A_1B,HIGH);
digitalWrite(A_1A,LOW);
digitalWrite(B_1B,LOW);
digitalWrite(B_1A,HIGH);
}
void turnRight(){
digitalWrite(A_1B,HIGH);
digitalWrite(A_1A,LOW);
digitalWrite(B_1B,HIGH);
digitalWrite(B_1A,LOW);
}
void turnLeft(){
digitalWrite(A_1B,LOW);
digitalWrite(A_1A,HIGH);
digitalWrite(B_1B,LOW);
digitalWrite(B_1A,HIGH);
}
void stopMove(){
digitalWrite(A_1B,LOW);
digitalWrite(A_1A,LOW);
digitalWrite(B_1B,LOW);
digitalWrite(B_1A,LOW);
}
Bill of Materials
Part | Note | Price | Link |
---|---|---|---|
Chasis | Used as the general frame of the robot. | $21.59 | Link |
Audrino Uno Clone | Accepts all the code for the robot and runs the actions for the robot accordingly. | $14.98 | Link |
Electronics Kit | Provides extra wires and components that can be used as needed. | $12.79 | Link |
Moters | Used to move the treads of the robot and allow it to move. | $11.98 | Link |
H Bridges | Receives the code for the moters from the Audrino and runs it for the moters. | $8.99 | Link |
DMM | Helps with debugging. | $11.00 | Link |
9V Barrel Jack | Allows for a 9 volt battery to be connected to the Audrino to power the robot | $5.99 | Link |
9V Batteries | Powers the robot. | $8.88 | Link |
Remote Control | Allows for compleate control of the robot’s movements. | $54.99 | Link |