loading
Hi Guys/Gals

This project originally started to see if we could program out own remote controlled rover but turned into more then that,we ordered 3 Rover 5 units as they seems to have a very easy to use driver board form sparkfun. Below is the steps to make yours work with the use of VirtualWire library and Arduino. The code is very basic and could be done a very different way but as it is now almost anyone can understand it.

the current code allows the rover to be driver in 8 directions namely.

1) Forward
2) Reverse
3) Left
4) Right
5) Forward/Right ( drives to the right )
6) Forward/Left ( drives to the left )
7) Back/Right
8) Back/Left

See steps below to built your own !

Step 1: Step 1: Wire Up the Rover.

Attached is the manual for the driver board and description of the pin-outs and below is how to wire the Arduino Mega to the driver board.

1) Arduino Mega 2560
2) Sparkfun Rover 5 Driver board
3) Cheap 433Mhz data radio's

Mega Driver board
22 // Direction pin ch1 front right motor
28 // Direction pin ch2 front left motor
24 // Direction pin ch3 back right motor
26 // Direction pin ch4 back left motor

2 //Speed Ch1 PWM 1
3 //Speed Ch2 PWM 2
4 //Speed Ch3 PWM 3
5 //Speed Ch4 PWM 4

11 // Data Receive pin

The Rover 5 is available in 4WD or 2WD the code is written for a 4WD rover but wiring it up as below for the 2WD should still work the same.

Step 2: Step 2: Build Remote and Plug Into UNO

The Sparkfun joystick remote was an easy choice as it had n joystick and 4 buttons ( explained later )
Solder the pins onto the board. and plug it into a UNO.( presolder units is also available form them )

The data radio data pin must be connected to PIN 11 on the Uno! and POS to 5v and NEG to GND.
there are many online tutorials on the making of antenna's for the data radios but i found a 164.5mm lenght of solid copter wire gets a range of a around 42 meters.( code can be changed to use RC )

after you have done this you can find the "Rover_TX"pde attached copy ,past and upload to UNO.
NOTE( please remember you need to download and install "VirtualWire" library before the code will compile.
VirtualWire.rar

From the picture above you can see I have proceeded to make my remote smaller by using a Ariduino Pro Micro Board ( if anyone requires i will give pin layout and code but this is a very tricky and really unnecessary evil)

Step 3: Step 3: Load the Code

Attached is the two .pde's to be used drag and drop and upload if all is connected correctly you should have a working rover !!! Enjoy


Now coming back to the Buttons on the remote, our plan is to advance the code to include a pan tilt servo on the front with a IR laser acting as a "Canon" and on the other rovers have IR Receivers. this would be used with FPV gear to play real world "battle tank" . one of these function has already been implemented in the code. for example

if your rover is working. press and hold button D5 done then press the joystick down ( also a button) you should see your rover jump back ( mimic of the canon shot recoil) ;-)

this project was intended for short to medium range ( 10- 40 meters) as this is what you can expect from the cheap 433mhz data radios.

hope you guys enjoy!
<p>Hello, I am trying to do this project with nearly all the same equipment. However, I am getting a compile warning. I get a warning that says &quot;typedef was ignored in this declaration.&quot; The code compiles and uploads. With the serial monitor running on the remote, I can see the values displayed by the joystick and 'case' number, but not the buttons (although they do work when wired to an LED.)</p><p><br>However, with the serial monitor running on the Rover, it displays nothing and is not responsive to the remote. I assume it is not receiving properly from the remote, because of the typedef struct error, which packages the information to be send by virtualwire. <br><br>Any idea why this is happening and what steps I can do to get it working? The RF links do work when I use example code for virtualwire.</p>
<p>#include &lt;AFMotor.h&gt;</p><p>#include &lt;LiquidCrystal.h&gt;</p><p>//#include &lt;Servo.h&gt;</p><p>//Servo myservo;</p><p>LiquidCrystal lcd(32, 30, 28, 26, 24, 22);</p><p>AF_DCMotor motor1(1, MOTOR12_8KHZ);</p><p>AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm</p><p>AF_DCMotor motor3(3, MOTOR34_64KHZ);</p><p>AF_DCMotor motor4(4, MOTOR34_1KHZ);</p><p>int state = 0;</p><p>int ledLight = 52;</p><p>int ledRed = 48;</p><p>int ledGreen = 46;</p><p>int BodyLight = 53;</p><p>int LdrPin = A8; // Ldr Sensore pin</p><p>int LdrValue = 0; // Ldr Sensore pin Value</p><p>//int pos = 0;</p><p>int ch1; // RC input pins</p><p>int ch2;</p><p>int ch3;</p><p>//int ledPin = 13;</p><p>//const int D1RA = 2;</p><p>//const int PWMA = 3;</p><p>const int trigPin = A11; // Sonar Sensore pins</p><p>const int echoPin = A12;</p><p>const int buttonPin = 50;</p><p>int buttonPushCounter = 0; // counter for the number of button presses</p><p>int buttonState = 0; // current state of the button</p><p>int lastButtonState = 0; // previous state of the button</p><p>int sensorpin = A10; int temperature = 0;</p><p>void setup() {</p><p> pinMode(buttonPin, INPUT);</p><p> digitalWrite(buttonPin, HIGH);</p><p> // myservo.attach(9);</p><p> pinMode(46, OUTPUT); // Light Green</p><p> pinMode(48, OUTPUT); // Light Red</p><p> pinMode(52, OUTPUT); // Light Pin</p><p> pinMode(53, OUTPUT); // Light Pin</p><p> pinMode(50, INPUT); //LDR Sensor Pin</p><p> pinMode(34, INPUT); // RC input pins</p><p> pinMode(36, INPUT);</p><p> pinMode(38, INPUT);</p><p> pinMode(trigPin, OUTPUT); // Sonar Sensore pins</p><p> pinMode(echoPin, INPUT);</p><p> pinMode(sensorpin, INPUT);</p><p> Serial.begin(9600);</p><p> Serial3.begin(9600);</p><p> lcd.begin(16, 2);</p><p>}</p><p>void LCDdisplay() {</p><p> lcd.begin(16, 2);</p><p> lcd.setCursor(4, 0); lcd.print(&quot;WELLCOME&quot;);</p><p> delay(500);</p><p> lcd.setCursor(3, 0); lcd.print(&quot;=WELLCOME=&quot;);</p><p> delay(500);</p><p> lcd.setCursor(2, 0); lcd.print(&quot;-=WELLCOME=-&quot;);</p><p> delay(1000);</p><p> lcd.setCursor(3, 1); lcd.print(&quot;&lt;ROBOTANK&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(2, 1); lcd.print(&quot;&lt;&lt;ROBOTANK&gt;&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(1, 1); lcd.print(&quot;&lt;&lt;&lt;ROBOTANK&gt;&gt;&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(0, 1); lcd.print(&quot;&lt;&lt;&lt;&lt;ROBOTANK&gt;&gt;&gt;&gt;&quot;);</p><p> delay(3000);</p><p> lcd.clear();</p><p>}</p><p>void Button() {</p><p> buttonState = digitalRead(buttonPin);</p><p> if (buttonState != lastButtonState) {</p><p> if (buttonState == HIGH) {</p><p> buttonPushCounter++;</p><p> Serial.println(&quot;on&quot;);</p><p> Serial.print(&quot;number of button pushes: &quot;);</p><p> Serial.println(buttonPushCounter);</p><p> } else {</p><p> Serial.println(&quot;off&quot;);</p><p> }</p><p> delay(50);</p><p> }</p><p> lastButtonState = buttonState;</p><p> if (buttonPushCounter % 2 == 0) {</p><p> digitalWrite(ledGreen, HIGH);</p><p> digitalWrite(ledRed, LOW);</p><p> } else {</p><p> digitalWrite(ledRed, HIGH);</p><p> digitalWrite(ledGreen, LOW);</p><p> }</p><p>}</p><p>float search(void)</p><p>{</p><p> float duration = 0.00;</p><p> float CM = 0.00;</p><p> digitalWrite(trigPin, LOW); delayMicroseconds(2);</p><p> digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Delay for 10 us</p><p> digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH);</p><p> CM = (duration / 58.82); //Convert distance into CM.</p><p> lcd.setCursor(11, 1); lcd.print(CM);</p><p> float distance = 0.00; distance = search();</p><p> if ((distance &lt;= 10)) {</p><p> RobotLeft(); delay(400);</p><p> }</p><p> return CM;</p><p>}</p><p>void RightHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(250);</p><p> motor2.setSpeed(250);</p><p> motor3.setSpeed(100);</p><p> motor4.setSpeed(100);</p><p>}</p><p>void LeftHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(100);</p><p> motor2.setSpeed(100);</p><p> motor3.setSpeed(250);</p><p> motor4.setSpeed(250);</p><p>}</p><p>void RobotSpeedLow()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(150);</p><p> motor2.setSpeed(150);</p><p> motor3.setSpeed(150);</p><p> motor4.setSpeed(150);</p><p>}</p><p>void RobotSpeedHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sHi&quot;);</p><p> motor1.setSpeed(250);</p><p> motor2.setSpeed(250);</p><p> motor3.setSpeed(250);</p><p> motor4.setSpeed(250);</p><p>}</p><p>void RobotForward()</p><p>{ lcd.setCursor(0, 0); lcd.print(&quot;BK&quot;); motor1.run(FORWARD);</p><p> motor2.run(FORWARD); // turn it on going forward</p><p> motor3.run(FORWARD);</p><p> motor4.run(FORWARD);</p><p>}</p><p>void RobotBackward()</p><p>{ lcd.setCursor(0, 0); lcd.print(&quot;FT&quot;); motor1.run(BACKWARD);</p><p> motor2.run(BACKWARD); // the other way</p><p> motor3.run(BACKWARD);</p><p> motor4.run(BACKWARD);</p><p>}</p><p>void RobotLeft()</p><p>{ lcd.setCursor(0, 1); lcd.print(&quot;LF&quot;); motor1.run(BACKWARD);</p><p> motor2.run(BACKWARD);</p><p> motor3.run(FORWARD);</p><p> motor4.run(FORWARD);</p><p>}</p><p>void RobotRight()</p><p>{ lcd.setCursor(0, 1); lcd.print(&quot;RT&quot;); motor1.run(FORWARD);</p><p> motor2.run(FORWARD);</p><p> motor3.run(BACKWARD);</p><p> motor4.run(BACKWARD);</p><p>}</p><p>void RobotStop()</p><p>{ motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p>}</p><p>void LdrLight()</p><p>{ int LdrValue = analogRead(LdrPin);</p><p> if (LdrValue &lt;= 58) {</p><p> Serial.println(LdrValue);</p><p> lcd.setCursor(7, 0);</p><p> lcd.print(&quot;ON*&quot;);</p><p> digitalWrite(ledLight, HIGH);</p><p> }</p><p> else {</p><p> digitalWrite(ledLight, LOW);</p><p> lcd.setCursor(7, 0);</p><p> lcd.print(&quot;OFF&quot;);</p><p> }</p><p>}</p><p>void Voltage()</p><p>{ int VsensorValue = analogRead(A9); float voltage = VsensorValue / 10;</p><p> lcd.setCursor(11, 0); lcd.print(voltage); lcd.print(&quot;V&quot;);</p><p>}</p><p>void Temper()</p><p>{ temperature = analogRead(sensorpin); temperature = temperature * 0.48828125;</p><p> lcd.setCursor(3, 1); lcd.print(temperature); //Show the temperature in LCD</p><p> lcd.setCursor(5, 1); lcd.print(&quot;c&quot;); // C for Celecius</p><p>}</p><p>void Speed() {</p><p> if (ch3 &gt;= 1000) {</p><p> Serial.println(ch3);</p><p> RobotSpeedHigh();</p><p> }</p><p> else if (ch3 &lt;= 1000) {</p><p> Serial.println(ch3);</p><p> RobotSpeedLow();</p><p> }</p><p>}</p><p>void Blutooth()</p><p>{</p><p> if (Serial3.available() &gt; 0) {</p><p> state = Serial3.read();</p><p> if (state == 'F' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-F&quot;);</p><p> RobotSpeedHigh();</p><p> RobotBackward();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'B' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-B&quot;);</p><p> RobotSpeedHigh();</p><p> RobotForward();</p><p> delay(1000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'L' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-L&quot;);</p><p> RobotSpeedHigh();</p><p> RobotLeft();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'R' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-R&quot;);</p><p> RobotSpeedHigh();</p><p> RobotRight();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;BLT&quot;);</p><p> }</p><p> }</p><p>}</p><p>void OldRemote() {</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> //Serial.println(ch1); // each channel</p><p> // Serial.println(ch2);</p><p> // Serial.println(ch3);</p><p> if (ch2 &lt;= 1300) {</p><p> RobotForward(); Serial.println(ch2);</p><p> }</p><p> else if (ch2 &gt;= 1500) {</p><p> RobotBackward(); Serial.println(ch2);</p><p> }</p><p> else if (ch1 &lt;= 1300) {</p><p> Serial.println(ch1);</p><p> RobotLeft();</p><p> }</p><p> else if (ch1 &gt;= 1500) {</p><p> Serial.println(ch1);</p><p> RobotRight();</p><p> }</p><p> else if ((ch1 &gt;= 1300) &amp;&amp; (ch1 &lt;= 1500) &amp;&amp; (ch2 &gt;= 1300) &amp;&amp; (ch2 &lt;= 1500))</p><p> { RobotStop();</p><p> }</p><p> else {</p><p> RobotStop();</p><p> }</p><p>}</p><p>void NewRemote() {</p><p> int move; // Forward/Back speed</p><p> int back; // Turning Factor</p><p> int left;</p><p> int right;</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> move = map(ch2, 1000, 2000, -500, 500); //center over zero</p><p> move = constrain(move, -255, 255);</p><p> back = map(ch2, 1000, 2000, -500, 500);</p><p> back = constrain(back, -255, 255);</p><p> left = map(ch1, 1000, 2000, -500, 500);</p><p> left = constrain(left, -255, 255);</p><p> right = map(ch1, 1000, 2000, -500, 500);</p><p> right = constrain(right, -255, 255);</p><p> Serial.print(&quot;Channel 2:&quot;); // Print the value of</p><p> Serial.println(right); // each channel</p><p> //Backward============</p><p> if (move &gt;= 15) {</p><p> motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p> motor1.setSpeed(move); motor2.setSpeed(move); motor3.setSpeed(move); motor4.setSpeed(move);</p><p> }</p><p> //Forward=============</p><p> else if (move &lt;= -15) {</p><p> back = abs(move); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p> motor1.setSpeed(back); motor2.setSpeed(back); motor3.setSpeed(back); motor4.setSpeed(back);</p><p> }</p><p> //Strate Left =============</p><p> else if (left &gt;= 15) { //back=abs(move);</p><p> motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p> motor3.setSpeed(left); motor4.setSpeed(left);</p><p> motor1.run(FORWARD); motor2.run(FORWARD);</p><p> motor1.setSpeed(left); motor2.setSpeed(left);</p><p> }</p><p> //Strate Right =============</p><p> else if (left &lt;= -15) {</p><p> right = abs(right);</p><p> motor3.run(FORWARD); motor4.run(FORWARD);</p><p> motor3.setSpeed(right); motor4.setSpeed(right);</p><p> motor1.run(BACKWARD); motor2.run(BACKWARD);</p><p> motor1.setSpeed(right); motor2.setSpeed(right);</p><p> }</p><p> else {</p><p> motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p> }</p><p>}</p><p>void NewTurn () {</p><p> int move; // Forward/Back speed</p><p> int back; // Turning Factor</p><p> int left;</p><p> int right;</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> move = map(ch2, 1000, 2000, -500, 500); //center over zero</p><p> move = constrain(move, -255, 255);</p><p> back = map(ch2, 1000, 2000, -500, 500);</p><p> back = constrain(back, -255, 255);</p><p> left = map(ch1, 1000, 2000, -500, 500);</p><p> left = constrain(left, -255, 255);</p><p> right = map(ch1, 1000, 2000, -500, 500);</p><p> right = constrain(right, -255, 255);</p><p> Serial.print(&quot;Channel 2:&quot;); // Print the value of</p><p> Serial.println(left); // each channel</p><p>if ((move&lt;= -40) &amp;&amp; (left &lt;= -40))// Back Left High</p><p>{</p><p> LeftHigh(); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p>}</p><p>else if ((move&lt;= -40) &amp;&amp; (left &gt;= 40))// Back Right High</p><p>{</p><p> RightHigh(); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p>}</p><p>else if ((move&gt;= 40) &amp;&amp; (left &gt;= 40))// Front Left High mean Right Turn</p><p>{</p><p> LeftHigh(); motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p>}</p><p>else if ((move&gt;= 40) &amp;&amp; (left &lt;= -40))// Front Rihgt High mean Left Turn</p><p>{</p><p> RightHigh(); motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p>}</p><p> else {</p><p> motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p> }</p><p>}</p><p>void Run()</p><p>{ Temper();</p><p> Voltage();</p><p> LdrLight();</p><p> Blutooth();</p><p> Speed();</p><p> Button();</p><p>}</p><p>void loop() {</p><p>NewRemote();</p><p> //digitalWrite(53, HIGH);</p><p>//NewTurn ();</p><p>}</p>
<p>how to wire the Arduino Pro Micro to the button &amp; joystick?? please help me...</p><p>thank you very much...</p><p>veri.andrianta@gmail.com</p>
Mmm. not sure what your question is? do you want to know how to map the pins so you can use a pro micro ?
<p>yes, i want to know how to map the pins arduino pro micro? I 've tried but, the button 1,2,3,4 not function.. thanks</p>
<p>Is your hardware setup the same as mine ? you must make sure that the pins on your Pro micro match my pins as some Pro micros are different due to different manufacturing houses </p>
<p>my rover 5 tank can drive 4 direction only,,</p><p>1.forward, 2.reverse, 3.left, 4.right.</p><p>how to drive FWD/RIGHT, FWD/LEFT, REV/RIGHT, REV/LEFT??</p>
<p>//PLz Follow New Turn</p><p>#include &lt;AFMotor.h&gt;</p><p>#include &lt;LiquidCrystal.h&gt;</p><p>//#include &lt;Servo.h&gt;</p><p>//Servo myservo;</p><p>LiquidCrystal lcd(32, 30, 28, 26, 24, 22);</p><p>AF_DCMotor motor1(1, MOTOR12_8KHZ);</p><p>AF_DCMotor motor2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm</p><p>AF_DCMotor motor3(3, MOTOR34_64KHZ);</p><p>AF_DCMotor motor4(4, MOTOR34_1KHZ);</p><p>int state = 0;</p><p>int ledLight = 52;</p><p>int ledRed = 48;</p><p>int ledGreen = 46;</p><p>int BodyLight = 53;</p><p>int LdrPin = A8; // Ldr Sensore pin</p><p>int LdrValue = 0; // Ldr Sensore pin Value</p><p>//int pos = 0;</p><p>int ch1; // RC input pins</p><p>int ch2;</p><p>int ch3;</p><p>//int ledPin = 13;</p><p>//const int D1RA = 2;</p><p>//const int PWMA = 3;</p><p>const int trigPin = A11; // Sonar Sensore pins</p><p>const int echoPin = A12;</p><p>const int buttonPin = 50;</p><p>int buttonPushCounter = 0; // counter for the number of button presses</p><p>int buttonState = 0; // current state of the button</p><p>int lastButtonState = 0; // previous state of the button</p><p>int sensorpin = A10; int temperature = 0;</p><p>void setup() {</p><p> pinMode(buttonPin, INPUT);</p><p> digitalWrite(buttonPin, HIGH);</p><p> // myservo.attach(9);</p><p> pinMode(46, OUTPUT); // Light Green</p><p> pinMode(48, OUTPUT); // Light Red</p><p> pinMode(52, OUTPUT); // Light Pin</p><p> pinMode(53, OUTPUT); // Light Pin</p><p> pinMode(50, INPUT); //LDR Sensor Pin</p><p> pinMode(34, INPUT); // RC input pins</p><p> pinMode(36, INPUT);</p><p> pinMode(38, INPUT);</p><p> pinMode(trigPin, OUTPUT); // Sonar Sensore pins</p><p> pinMode(echoPin, INPUT);</p><p> pinMode(sensorpin, INPUT);</p><p> Serial.begin(9600);</p><p> Serial3.begin(9600);</p><p> lcd.begin(16, 2);</p><p>}</p><p>void LCDdisplay() {</p><p> lcd.begin(16, 2);</p><p> lcd.setCursor(4, 0); lcd.print(&quot;WELLCOME&quot;);</p><p> delay(500);</p><p> lcd.setCursor(3, 0); lcd.print(&quot;=WELLCOME=&quot;);</p><p> delay(500);</p><p> lcd.setCursor(2, 0); lcd.print(&quot;-=WELLCOME=-&quot;);</p><p> delay(1000);</p><p> lcd.setCursor(3, 1); lcd.print(&quot;&lt;ROBOTANK&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(2, 1); lcd.print(&quot;&lt;&lt;ROBOTANK&gt;&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(1, 1); lcd.print(&quot;&lt;&lt;&lt;ROBOTANK&gt;&gt;&gt;&quot;);</p><p> delay(500);</p><p> lcd.setCursor(0, 1); lcd.print(&quot;&lt;&lt;&lt;&lt;ROBOTANK&gt;&gt;&gt;&gt;&quot;);</p><p> delay(3000);</p><p> lcd.clear();</p><p>}</p><p>void Button() {</p><p> buttonState = digitalRead(buttonPin);</p><p> if (buttonState != lastButtonState) {</p><p> if (buttonState == HIGH) {</p><p> buttonPushCounter++;</p><p> Serial.println(&quot;on&quot;);</p><p> Serial.print(&quot;number of button pushes: &quot;);</p><p> Serial.println(buttonPushCounter);</p><p> } else {</p><p> Serial.println(&quot;off&quot;);</p><p> }</p><p> delay(50);</p><p> }</p><p> lastButtonState = buttonState;</p><p> if (buttonPushCounter % 2 == 0) {</p><p> digitalWrite(ledGreen, HIGH);</p><p> digitalWrite(ledRed, LOW);</p><p> } else {</p><p> digitalWrite(ledRed, HIGH);</p><p> digitalWrite(ledGreen, LOW);</p><p> }</p><p>}</p><p>float search(void)</p><p>{</p><p> float duration = 0.00;</p><p> float CM = 0.00;</p><p> digitalWrite(trigPin, LOW); delayMicroseconds(2);</p><p> digitalWrite(trigPin, HIGH); delayMicroseconds(10); // Delay for 10 us</p><p> digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH);</p><p> CM = (duration / 58.82); //Convert distance into CM.</p><p> lcd.setCursor(11, 1); lcd.print(CM);</p><p> float distance = 0.00; distance = search();</p><p> if ((distance &lt;= 10)) {</p><p> RobotLeft(); delay(400);</p><p> }</p><p> return CM;</p><p>}</p><p>void RightHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(250);</p><p> motor2.setSpeed(250);</p><p> motor3.setSpeed(100);</p><p> motor4.setSpeed(100);</p><p>}</p><p>void LeftHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(100);</p><p> motor2.setSpeed(100);</p><p> motor3.setSpeed(250);</p><p> motor4.setSpeed(250);</p><p>}</p><p>void RobotSpeedLow()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sLO&quot;);</p><p> motor1.setSpeed(150);</p><p> motor2.setSpeed(150);</p><p> motor3.setSpeed(150);</p><p> motor4.setSpeed(150);</p><p>}</p><p>void RobotSpeedHigh()</p><p>{</p><p> lcd.setCursor(3, 0);</p><p> lcd.print(&quot;sHi&quot;);</p><p> motor1.setSpeed(250);</p><p> motor2.setSpeed(250);</p><p> motor3.setSpeed(250);</p><p> motor4.setSpeed(250);</p><p>}</p><p>void RobotForward()</p><p>{ lcd.setCursor(0, 0); lcd.print(&quot;BK&quot;); motor1.run(FORWARD);</p><p> motor2.run(FORWARD); // turn it on going forward</p><p> motor3.run(FORWARD);</p><p> motor4.run(FORWARD);</p><p>}</p><p>void RobotBackward()</p><p>{ lcd.setCursor(0, 0); lcd.print(&quot;FT&quot;); motor1.run(BACKWARD);</p><p> motor2.run(BACKWARD); // the other way</p><p> motor3.run(BACKWARD);</p><p> motor4.run(BACKWARD);</p><p>}</p><p>void RobotLeft()</p><p>{ lcd.setCursor(0, 1); lcd.print(&quot;LF&quot;); motor1.run(BACKWARD);</p><p> motor2.run(BACKWARD);</p><p> motor3.run(FORWARD);</p><p> motor4.run(FORWARD);</p><p>}</p><p>void RobotRight()</p><p>{ lcd.setCursor(0, 1); lcd.print(&quot;RT&quot;); motor1.run(FORWARD);</p><p> motor2.run(FORWARD);</p><p> motor3.run(BACKWARD);</p><p> motor4.run(BACKWARD);</p><p>}</p><p>void RobotStop()</p><p>{ motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p>}</p><p>void LdrLight()</p><p>{ int LdrValue = analogRead(LdrPin);</p><p> if (LdrValue &lt;= 58) {</p><p> Serial.println(LdrValue);</p><p> lcd.setCursor(7, 0);</p><p> lcd.print(&quot;ON*&quot;);</p><p> digitalWrite(ledLight, HIGH);</p><p> }</p><p> else {</p><p> digitalWrite(ledLight, LOW);</p><p> lcd.setCursor(7, 0);</p><p> lcd.print(&quot;OFF&quot;);</p><p> }</p><p>}</p><p>void Voltage()</p><p>{ int VsensorValue = analogRead(A9); float voltage = VsensorValue / 10;</p><p> lcd.setCursor(11, 0); lcd.print(voltage); lcd.print(&quot;V&quot;);</p><p>}</p><p>void Temper()</p><p>{ temperature = analogRead(sensorpin); temperature = temperature * 0.48828125;</p><p> lcd.setCursor(3, 1); lcd.print(temperature); //Show the temperature in LCD</p><p> lcd.setCursor(5, 1); lcd.print(&quot;c&quot;); // C for Celecius</p><p>}</p><p>void Speed() {</p><p> if (ch3 &gt;= 1000) {</p><p> Serial.println(ch3);</p><p> RobotSpeedHigh();</p><p> }</p><p> else if (ch3 &lt;= 1000) {</p><p> Serial.println(ch3);</p><p> RobotSpeedLow();</p><p> }</p><p>}</p><p>void Blutooth()</p><p>{</p><p> if (Serial3.available() &gt; 0) {</p><p> state = Serial3.read();</p><p> if (state == 'F' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-F&quot;);</p><p> RobotSpeedHigh();</p><p> RobotBackward();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'B' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-B&quot;);</p><p> RobotSpeedHigh();</p><p> RobotForward();</p><p> delay(1000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'L' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-L&quot;);</p><p> RobotSpeedHigh();</p><p> RobotLeft();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else if (state == 'R' ) {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;B-R&quot;);</p><p> RobotSpeedHigh();</p><p> RobotRight();</p><p> delay(2000);</p><p> RobotStop();</p><p> }</p><p> else {</p><p> lcd.setCursor(7, 1);</p><p> lcd.print(&quot;BLT&quot;);</p><p> }</p><p> }</p><p>}</p><p>void OldRemote() {</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> //Serial.println(ch1); // each channel</p><p> // Serial.println(ch2);</p><p> // Serial.println(ch3);</p><p> if (ch2 &lt;= 1300) {</p><p> RobotForward(); Serial.println(ch2);</p><p> }</p><p> else if (ch2 &gt;= 1500) {</p><p> RobotBackward(); Serial.println(ch2);</p><p> }</p><p> else if (ch1 &lt;= 1300) {</p><p> Serial.println(ch1);</p><p> RobotLeft();</p><p> }</p><p> else if (ch1 &gt;= 1500) {</p><p> Serial.println(ch1);</p><p> RobotRight();</p><p> }</p><p> else if ((ch1 &gt;= 1300) &amp;&amp; (ch1 &lt;= 1500) &amp;&amp; (ch2 &gt;= 1300) &amp;&amp; (ch2 &lt;= 1500))</p><p> { RobotStop();</p><p> }</p><p> else {</p><p> RobotStop();</p><p> }</p><p>}</p><p>void NewRemote() {</p><p> int move; // Forward/Back speed</p><p> int back; // Turning Factor</p><p> int left;</p><p> int right;</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> move = map(ch2, 1000, 2000, -500, 500); //center over zero</p><p> move = constrain(move, -255, 255);</p><p> back = map(ch2, 1000, 2000, -500, 500);</p><p> back = constrain(back, -255, 255);</p><p> left = map(ch1, 1000, 2000, -500, 500);</p><p> left = constrain(left, -255, 255);</p><p> right = map(ch1, 1000, 2000, -500, 500);</p><p> right = constrain(right, -255, 255);</p><p> Serial.print(&quot;Channel 2:&quot;); // Print the value of</p><p> Serial.println(right); // each channel</p><p> //Backward============</p><p> if (move &gt;= 15) {</p><p> motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p> motor1.setSpeed(move); motor2.setSpeed(move); motor3.setSpeed(move); motor4.setSpeed(move);</p><p> }</p><p> //Forward=============</p><p> else if (move &lt;= -15) {</p><p> back = abs(move); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p> motor1.setSpeed(back); motor2.setSpeed(back); motor3.setSpeed(back); motor4.setSpeed(back);</p><p> }</p><p> //Strate Left =============</p><p> else if (left &gt;= 15) { //back=abs(move);</p><p> motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p> motor3.setSpeed(left); motor4.setSpeed(left);</p><p> motor1.run(FORWARD); motor2.run(FORWARD);</p><p> motor1.setSpeed(left); motor2.setSpeed(left);</p><p> }</p><p> //Strate Right =============</p><p> else if (left &lt;= -15) {</p><p> right = abs(right);</p><p> motor3.run(FORWARD); motor4.run(FORWARD);</p><p> motor3.setSpeed(right); motor4.setSpeed(right);</p><p> motor1.run(BACKWARD); motor2.run(BACKWARD);</p><p> motor1.setSpeed(right); motor2.setSpeed(right);</p><p> }</p><p> else {</p><p> motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p> }</p><p>}</p><p>void NewTurn () {</p><p> int move; // Forward/Back speed</p><p> int back; // Turning Factor</p><p> int left;</p><p> int right;</p><p> ch1 = pulseIn(34, HIGH, 25000); // Read the pulse width of</p><p> ch2 = pulseIn(36, HIGH, 25000); // each channel</p><p> ch3 = pulseIn(38, HIGH, 25000);</p><p> move = map(ch2, 1000, 2000, -500, 500); //center over zero</p><p> move = constrain(move, -255, 255);</p><p> back = map(ch2, 1000, 2000, -500, 500);</p><p> back = constrain(back, -255, 255);</p><p> left = map(ch1, 1000, 2000, -500, 500);</p><p> left = constrain(left, -255, 255);</p><p> right = map(ch1, 1000, 2000, -500, 500);</p><p> right = constrain(right, -255, 255);</p><p> Serial.print(&quot;Channel 2:&quot;); // Print the value of</p><p> Serial.println(left); // each channel</p><p>if ((move&lt;= -40) &amp;&amp; (left &lt;= -40))// Back Left High</p><p>{</p><p> LeftHigh(); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p>}</p><p>else if ((move&lt;= -40) &amp;&amp; (left &gt;= 40))// Back Right High</p><p>{</p><p> RightHigh(); motor1.run(FORWARD); motor2.run(FORWARD); motor3.run(FORWARD); motor4.run(FORWARD);</p><p>}</p><p>else if ((move&gt;= 40) &amp;&amp; (left &gt;= 40))// Front Left High mean Right Turn</p><p>{</p><p> LeftHigh(); motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p>}</p><p>else if ((move&gt;= 40) &amp;&amp; (left &lt;= -40))// Front Rihgt High mean Left Turn</p><p>{</p><p> RightHigh(); motor1.run(BACKWARD); motor2.run(BACKWARD); motor3.run(BACKWARD); motor4.run(BACKWARD);</p><p>}</p><p> else {</p><p> motor1.run(RELEASE);</p><p> motor2.run(RELEASE);</p><p> motor3.run(RELEASE);</p><p> motor4.run(RELEASE);</p><p> }</p><p>}</p><p>void Run()</p><p>{ Temper();</p><p> Voltage();</p><p> LdrLight();</p><p> Blutooth();</p><p> Speed();</p><p> Button();</p><p>}</p><p>void loop() {</p><p>NewTurn ();</p><p>}</p>
<p>yes, my hardware setup the same as you.</p><p>1. arduino mega 2500</p><p>2. arduino pro micro 32u4</p><p>3. driver rover 5 tank</p><p>4. cheep data radio 433MHz</p>
<p>Easiest way to test is to see what your default analog values are from the joystick. load the code on the remote control device and open the serial monitor while it is running the joystick will give you values of around 512 or close if these values are out you will not get all 8 directions only 4. as for the buttons, you can see the buttons in the serial monitor aswell, if they work and you press the button the string will show &quot;1&quot; in the 3, 4 and 5 position.</p>
<p>thank you very much for your help</p>
<p>Is it like this way of connecting the push button??</p>
<p>Hi awesome project, just a quick question.</p><p>Can you show me how to wire the Transmitter to the Joystick board with the Uno plugged in. Thank you.</p>
<p>Hi,great project! I would like the pin out for the Pro?</p><p>Thanks</p>

About This Instructable

10,341views

39favorites

License:

More by Rustie0125:LED Head Arduino TED  Arduino Integer transmission simplified  Arduino low Power Project. 
Add instructable to: