[go: up one dir, main page]

0% found this document useful (0 votes)
12 views3 pages

Programacion

This document contains an Arduino sketch for controlling motors via Bluetooth using a SoftwareSerial library. It defines pin configurations for an H-bridge motor driver and includes functions to set motor directions based on received Bluetooth commands. The loop continuously checks for Bluetooth input to execute motor control commands for moving forward, backward, left, right, or stopping.

Uploaded by

randalyashiro123
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)
12 views3 pages

Programacion

This document contains an Arduino sketch for controlling motors via Bluetooth using a SoftwareSerial library. It defines pin configurations for an H-bridge motor driver and includes functions to set motor directions based on received Bluetooth commands. The loop continuously checks for Bluetooth input to execute motor control commands for moving forward, backward, left, right, or stopping.

Uploaded by

randalyashiro123
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/ 3

#include <SoftwareSerial.

h>

SoftwareSerial Bluetooth(0, 1); // RX, TX

// Pines del puente H

const int in1 = 2;

const int in2 = 3;

const int in3 = 4;

const int in4 = 5;

void setup() {

// Configurar pines como salidas

pinMode(in1, OUTPUT);

pinMode(in2, OUTPUT);

pinMode(in3, OUTPUT);

pinMode(in4, OUTPUT);

// Iniciar la comunicación serie

Serial.begin(9600);

Bluetooth.begin(9600);

void loop() {

if (Bluetooth.available()) {

char command = Bluetooth.read();

controlMotors(command);

}
void controlMotors(char cmd) {

switch (cmd) {

case '2': // Adelante

digitalWrite(in1, HIGH);

digitalWrite(in2, LOW);

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW);

break;

case '3': // Atrás

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

break;

case '4': // Izquierda

digitalWrite(in1, LOW);

digitalWrite(in2, HIGH);

digitalWrite(in3, HIGH);

digitalWrite(in4, LOW);

break;

case '5': // Derecha

digitalWrite(in1, HIGH);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, HIGH);

break;

case '6': // Detener

digitalWrite(in1, LOW);

digitalWrite(in2, LOW);

digitalWrite(in3, LOW);

digitalWrite(in4, LOW);
break;

default:

break;

You might also like