top of page

Welcome to my code page. On this page, you will find my coding and how I was able to do all that I have done with this project.

//***********************************************************
//  MJRoBot - AutoBot (Bluetooth CMD) V1
//   
// ==>  BT remote control manual operation via Android app (MJRobot BT Remote Control)
//
// Marcelo José Rovai
// 7 May 16
//************************************************************


#include "robotDefines.h"

// BT Module
#include <SoftwareSerial.h>
SoftwareSerial BT1(10, 11); // El pin 10 es Rx y el pin 11 es Tx

//******************************************************************************//  
void setup() {

  Serial.begin(9600);
  BT1.begin(9600);
  
  // Motor Drives

  pinMode(rearMtEne, OUTPUT);
  pinMode(rearMtFw, OUTPUT);
  pinMode(rearMtBw, OUTPUT);
  pinMode(frontMtEne, OUTPUT);
  pinMode(frontMtLeft, OUTPUT);
  pinMode(frontMtRight, OUTPUT);
 
  //Buzzer
  pinMode(outBuz, OUTPUT);
 
  //*********Initial Settings

  //motor off
  moveStop(); 

  BT1.print("MJRoBot AutoBot BT Remote Control");
  BT1.println('\n');

}


//******************************************************************************//  
void loop() 
{
  checkBTcmd();  // verify if a comand is received from BT remote control
  receiveCmd ();
  
  if (turnOn) manualCmd ();
   else stopRobot ();
}

//******************************************************************************//  

void receiveCmd ()
{
  
  switch (command)
  {
    case 'p': 
      Serial.println("command ==> p"); 
      turnOn = !turnOn;
      command = 0;
      analogWrite(ledStatus, turnOn*128); // Robot ON - Led ON
      beep(outBuz, 1000, 100);
      BT1.print(" COMMAND ON/OFF");
      BT1.println('\n');
      delay(200); //Delay to call attention to mode change
      break;
      
   case 'm': //not used here
      break;
  }   
}

void moveSop() {
  
  }

First Page of Code.

void moveStop() //turn off rear motor

  analogWrite(rearMtEne, LOW);
  digitalWrite(rearMtFw, LOW);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

//******************************************************************************//  

void moveForward() // rear motor FW

  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, HIGH);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

//******************************************************************************//  

void moveBackward() // rear motor BW

  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, LOW);
  digitalWrite(rearMtBw, HIGH);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, HIGH);
  delay(5);
}

//******************************************************************************//  

void moveLeft() // front motor left

  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, HIGH);
  digitalWrite(frontMtRight, LOW);
  digitalWrite(ledRed, LOW);
  delay(10);
}

//******************************************************************************//  

void moveRight() // front motor right

  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, LOW);
  digitalWrite(frontMtRight, HIGH);
  digitalWrite(ledRed, LOW);
  delay(10);
}

//******************************************************************************//  

void stopRobot ()
{
  digitalWrite(ledBlue, LOW);
  digitalWrite(ledRed, LOW);
  
  state = 0;
  moveStop(); //turn off both motors
}

First Page of Code.

2nd Page of Code.

void moveStop() //turn off rear motor

  analogWrite(rearMtEne, LOW);
  digitalWrite(rearMtFw, LOW);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

//******************************************************************************//  

void moveForward() // rear motor FW

  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, HIGH);
  digitalWrite(rearMtBw, LOW);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, LOW);
  delay(5);
}

//******************************************************************************//  

void moveBackward() // rear motor BW

  analogWrite(rearMtEne, motorSpeed);
  digitalWrite(rearMtFw, LOW);
  digitalWrite(rearMtBw, HIGH);
  
  digitalWrite(frontMtEne, LOW);
  digitalWrite(ledRed, HIGH);
  delay(5);
}

//******************************************************************************//  

void moveLeft() // front motor left

  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, HIGH);
  digitalWrite(frontMtRight, LOW);
  digitalWrite(ledRed, LOW);
  delay(10);
}

//******************************************************************************//  

void moveRight() // front motor right

  digitalWrite(frontMtEne, HIGH);
  digitalWrite(frontMtLeft, LOW);
  digitalWrite(frontMtRight, HIGH);
  digitalWrite(ledRed, LOW);
  delay(10);
}

//******************************************************************************//  

void stopRobot ()
{
  digitalWrite(ledBlue, LOW);
  digitalWrite(ledRed, LOW);
  
  state = 0;
  moveStop(); //turn off both motors
}

bottom of page