0% found this document useful (0 votes)
333 views

Codigo Carro Arduino Uno

This document contains code for controlling two DC motors connected to an Arduino Uno board. It defines the pin connections for the motors and includes functions to move the motors forward and backward at a given speed. It also includes code to interface with a Blynk app to control the motor speed remotely.

Uploaded by

Bryan Hernandez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
333 views

Codigo Carro Arduino Uno

This document contains code for controlling two DC motors connected to an Arduino Uno board. It defines the pin connections for the motors and includes functions to move the motors forward and backward at a given speed. It also includes code to interface with a Blynk app to control the motor speed remotely.

Uploaded by

Bryan Hernandez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Codigo carro Arduino uno

const int pinPWMA = 3;

const int pinAIN2 = 7;

const int pinAIN1 = 8;

const int pinSTBY = 12;

const int pinBIN1 = 9;

const int pinBIN2 = 10;

const int pinPWMB = 5;

int speed = 200; //velocidad de giro

const int pinMotorA[3] = { pinPWMA, pinAIN2, pinAIN1 };

const int pinMotorB[3] = { pinPWMB, pinBIN1, pinBIN2 };

void setup()

pinMode(pinAIN2, OUTPUT);

pinMode(pinAIN1, OUTPUT);

pinMode(pinPWMA, OUTPUT);

pinMode(pinBIN1, OUTPUT);

pinMode(pinBIN2, OUTPUT);

pinMode(pinPWMB, OUTPUT);

}
void loop()

digitalWrite(pinMotorA[1], HIGH);

digitalWrite(pinMotorA[2], LOW);

analogWrite(pinMotorA[0], speed);

digitalWrite(pinSTBY, HIGH);

-----------------------------------------------

BLYNK_WRITE(V2)

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

Serial.print("Motor 1 Forward: ");

Serial.println(pinValue);

if(pinValue == 1) {

moveMotorForward(pinMotorA, speed);

moveMotorForward(pinMotorB, speed);

if(pinValue == 0) {

moveMotorForward(pinMotorA, 0);

moveMotorForward(pinMotorB, 0);

terminal.println("You said: 'Marco'") ;

terminal.println("I said: 'Polo'") ;

terminal.flush();
}

void moveMotorForward(const int pinMotor[3], int speed)

digitalWrite(pinMotor[1], HIGH);

digitalWrite(pinMotor[2], LOW);

analogWrite(pinMotor[0], speed);

digitalWrite(pinSTBY, HIGH);

void moveMotorBackward(const int pinMotor[3], int speed)

digitalWrite(pinMotor[1], LOW);

digitalWrite(pinMotor[2], HIGH);

analogWrite(pinMotor[0], speed);

digitalWrite(pinSTBY, HIGH);

----------------------------------------

#define BLYNK_PRINT Serial

#include <SoftwareSerial.h>

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

#include <BlynkSimpleSerialBLE.h>

#include <SoftwareSerial.h>

char auth[] = "ca2720f8002e488fbce9a98e2b628e2f";

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

const int pinPWMA = 3;

const int pinAIN2 = 7;

const int pinAIN1 = 8;


const int pinSTBY = 12;

const int pinBIN1 = 9;

const int pinBIN2 = 10;

const int pinPWMB = 5;

int speed = 200; //velocidad de giro

const int pinMotorA[3] = { pinPWMA, pinAIN2, pinAIN1 };

const int pinMotorB[3] = { pinPWMB, pinBIN1, pinBIN2 };

void setup()

// Debug console

Serial.begin(9600);

SerialBLE.begin(9600);

Blynk.begin(SerialBLE, auth);

Serial.println("Waiting for connections...");

void loop()

Blynk.run();

BLYNK_WRITE(V3)

int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable

Serial.print("Motor 1 Forward: ");

Serial.println(pinValue);

if(pinValue == 1) {
digitalWrite(pinMotorA[1], HIGH);

digitalWrite(pinMotorA[2], LOW);

analogWrite(pinMotorA[0], speed);

digitalWrite(pinSTBY, HIGH);

if(pinValue == 0) {

digitalWrite(pinMotorA[1], HIGH);

digitalWrite(pinMotorA[2], LOW);

analogWrite(pinMotorA[0], 0);

digitalWrite(pinSTBY, HIGH);

You might also like