0% found this document useful (0 votes)
2 views5 pages

Carro Bluetoth Funcionando

The document describes an Arduino project for controlling a robot car via a Bluetooth app. It includes code for motor control and commands for movement directions such as forward, backward, left, and right. The project allows for electronic braking and is licensed for remixing but not for commercial use.

Uploaded by

reop90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views5 pages

Carro Bluetoth Funcionando

The document describes an Arduino project for controlling a robot car via a Bluetooth app. It includes code for motor control and commands for movement directions such as forward, backward, left, and right. The project allows for electronic braking and is licensed for remixing but not for commercial use.

Uploaded by

reop90
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

/*

Code Name: Arduino Bluetooth Control Car

Code URI: https://circuitbest.com/category/arduino-projects/

Author: Make DIY

Author URI: https://circuitbest.com/author/admin/

Description: This program is used to control a robot using a app

that communicates with Arduino through a bluetooth module.

App URI: https://bit.ly/2BlMAea

Version: 1.0

License: Remixing or Changing this Thing is allowed. Commercial use is not allowed.

*/

#define in1 5 //L298n Motor Driver pins.

#define in2 6

#define in3 10

#define in4 11

#define LED 13

int command; // Int to store app command state.

int buttonState = 0;

int lastButtonState = 0;

int brakeTime = 45;

int brkonoff = 1; // 1 for the electronic braking system, 0 for normal.

void setup() {

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

pinMode(LED, OUTPUT); // Set the LED pin.

Serial.begin(9600); // Set the baud rate to your Bluetooth module.

}
void loop() {

if (Serial.available() > 0) {

command = Serial.read();

// Exibe o comando recebido no monitor serial

Serial.print("Comando recebido: ");

Serial.println((char)command);

Stop(); // Initialize with motors stopped.

switch (command) {

case 'F':

forward();

break;

case 'B':

back();

break;

case 'L':

left();

break;

case 'R':

right();

break;

case 'G':

forwardleft();

break;

case 'I':

forwardright();

break;

case 'H':
backleft();

break;

case 'J':

backright();

break;

if (brkonoff == 1) {

brakeOn();

} else {

brakeOff();

void forward() {

analogWrite(in1, 255); // Velocidade máxima

analogWrite(in3, 255); // Velocidade máxima

void back() {

analogWrite(in2, 255); // Velocidade máxima

analogWrite(in4, 255); // Velocidade máxima

void left() {

analogWrite(in3, 255); // Velocidade máxima

analogWrite(in2, 255); // Velocidade máxima

void right() {
analogWrite(in4, 255); // Velocidade máxima

analogWrite(in1, 255); // Velocidade máxima

void forwardleft() {

analogWrite(in1, 255); // Velocidade máxima

analogWrite(in3, 255); // Velocidade máxima

void forwardright() {

analogWrite(in1, 255); // Velocidade máxima

analogWrite(in3, 255); // Velocidade máxima

void backright() {

analogWrite(in2, 255); // Velocidade máxima

analogWrite(in4, 255); // Velocidade máxima

void backleft() {

analogWrite(in2, 255); // Velocidade máxima

analogWrite(in4, 255); // Velocidade máxima

void Stop() {

analogWrite(in1, 0);

analogWrite(in2, 0);

analogWrite(in3, 0);

analogWrite(in4, 0);

}
void brakeOn() {

// Here's the future use: an electronic braking system!

// Read the pushbutton input pin:

buttonState = command;

// Compare the buttonState to its previous state

if (buttonState != lastButtonState) {

// If the state has changed, increment the counter

if (buttonState == 'S') {

if (lastButtonState != buttonState) {

digitalWrite(in1, HIGH);

digitalWrite(in2, HIGH);

digitalWrite(in3, HIGH);

digitalWrite(in4, HIGH);

delay(brakeTime);

Stop();

// Save the current state as the last state,

// for next time through the loop

lastButtonState = buttonState;

void brakeOff() {

// Placeholder for brake off function (if necessary)

You might also like