Ir al contenido principal

ESQUEMA DE CONEXION + CODIGO SEGUIDOR DE LINEA

 


#define IR_SENSOR_RIGHT 11
#define IR_SENSOR_LEFT 12
#define MOTOR_SPEED 180

//Right motor
int enableRightMotor=6;
int rightMotorPin1=7;
int rightMotorPin2=8;

//Left motor
int enableLeftMotor=5;
int leftMotorPin1=9;
int leftMotorPin2=10;

void setup()
{
  //The problem with TT gear motors is that, at very low pwm value it does not even rotate.
  //If we increase the PWM value then it rotates faster and our robot is not controlled in that speed and goes out of line.
  //For that we need to increase the frequency of analogWrite.
  //Below line is important to change the frequency of PWM signal on pin D5 and D6
  //Because of this, motor runs in controlled manner (lower speed) at high PWM value.
  //This sets frequecny as 7812.5 hz.
  TCCR0B = TCCR0B & B11111000 | B00000010 ;
  
  // put your setup code here, to run once:
  pinMode(enableRightMotor, OUTPUT);
  pinMode(rightMotorPin1, OUTPUT);
  pinMode(rightMotorPin2, OUTPUT);
  
  pinMode(enableLeftMotor, OUTPUT);
  pinMode(leftMotorPin1, OUTPUT);
  pinMode(leftMotorPin2, OUTPUT);

  pinMode(IR_SENSOR_RIGHT, INPUT);
  pinMode(IR_SENSOR_LEFT, INPUT);
  rotateMotor(0,0);   
}


void loop()
{

  int rightIRSensorValue = digitalRead(IR_SENSOR_RIGHT);
  int leftIRSensorValue = digitalRead(IR_SENSOR_LEFT);

  //If none of the sensors detects black line, then go straight
  if (rightIRSensorValue == LOW && leftIRSensorValue == LOW)
  {
    rotateMotor(MOTOR_SPEED, MOTOR_SPEED);
  }
  //If right sensor detects black line, then turn right
  else if (rightIRSensorValue == HIGH && leftIRSensorValue == LOW )
  {
      rotateMotor(-MOTOR_SPEED, MOTOR_SPEED); 
  }
  //If left sensor detects black line, then turn left  
  else if (rightIRSensorValue == LOW && leftIRSensorValue == HIGH )
  {
      rotateMotor(MOTOR_SPEED, -MOTOR_SPEED); 
  } 
  //If both the sensors detect black line, then stop 
  else 
  {
    rotateMotor(0, 0);
  }
}


void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
  
  if (rightMotorSpeed < 0)
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,HIGH);    
  }
  else if (rightMotorSpeed > 0)
  {
    digitalWrite(rightMotorPin1,HIGH);
    digitalWrite(rightMotorPin2,LOW);      
  }
  else
  {
    digitalWrite(rightMotorPin1,LOW);
    digitalWrite(rightMotorPin2,LOW);      
  }

  if (leftMotorSpeed < 0)
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,HIGH);    
  }
  else if (leftMotorSpeed > 0)
  {
    digitalWrite(leftMotorPin1,HIGH);
    digitalWrite(leftMotorPin2,LOW);      
  }
  else 
  {
    digitalWrite(leftMotorPin1,LOW);
    digitalWrite(leftMotorPin2,LOW);      
  }
  analogWrite(enableRightMotor, abs(rightMotorSpeed));
  analogWrite(enableLeftMotor, abs(leftMotorSpeed));    
}






🤖🤖🤖🤖🤖🤖🤖

#define IR_SENSOR_RIGHT 6
#define IR_SENSOR_LEFT 8
#define MOTOR_SPEED 80
//Right motor
int enableRightMotor=9;
int rightMotorPin1=2;
int rightMotorPin2=3;
//Left motor
int enableLeftMotor=10 ;
int leftMotorPin1=4;
int leftMotorPin2=5;
void setup()
{
//The problem with TT gear motors is that, at very low pwm value it does not even rotate.
//If we increase the PWM value then it rotates faster and our robot is not controlled in that speed and
goes out of line.
//For that we need to increase the frequency of analogWrite.
//Below line is important to change the frequency of PWM signal on pin D5 and D6
//Because of this, motor runs in controlled manner (lower speed) at high PWM value.
//This sets frequecny as 7812.5 hz.
TCCR0B = TCCR0B & B11111000 | B00000010 ;
// put your setup code here, to run once:
pinMode(enableRightMotor, OUTPUT);
pinMode(rightMotorPin1, OUTPUT);
pinMode(rightMotorPin2, OUTPUT);
pinMode(enableLeftMotor, OUTPUT);
pinMode(leftMotorPin1, OUTPUT);
pinMode(leftMotorPin2, OUTPUT);
pinMode(IR_SENSOR_RIGHT, INPUT);
pinMode(IR_SENSOR_LEFT, INPUT);
rotateMotor(0,0);
}
void loop()
{
int rightIRSensorValue = digitalRead(IR_SENSOR_RIGHT);
int leftIRSensorValue = digitalRead(IR_SENSOR_LEFT);
//If none of the sensors detects black line, then go straight
if (rightIRSensorValue == LOW && leftIRSensorValue == LOW)
{
rotateMotor(MOTOR_SPEED, MOTOR_SPEED);
}
//If right sensor detects black line, then turn right
else if (rightIRSensorValue == HIGH && leftIRSensorValue == LOW )
{
rotateMotor(-MOTOR_SPEED, MOTOR_SPEED);
}
//If left sensor detects black line, then turn left
else if (rightIRSensorValue == LOW && leftIRSensorValue == HIGH )
{
rotateMotor(MOTOR_SPEED, -MOTOR_SPEED);
}
//If both the sensors detect black line, then stop
else
{
rotateMotor(0, 0);
}
}
void rotateMotor(int rightMotorSpeed, int leftMotorSpeed)
{
if (rightMotorSpeed < 0)
{
digitalWrite(rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,HIGH);
}
else if (rightMotorSpeed > 0)
{
digitalWrite(rightMotorPin1,HIGH);
digitalWrite(rightMotorPin2,LOW);
}
else
{
digitalWrite(rightMotorPin1,LOW);
digitalWrite(rightMotorPin2,LOW);
}
if (leftMotorSpeed < 0)
{
digitalWrite(leftMotorPin1,LOW);
digitalWrite(leftMotorPin2,HIGH);
}
else if (leftMotorSpeed > 0)
{
digitalWrite(leftMotorPin1,HIGH);
digitalWrite(leftMotorPin2,LOW);
}
else
{
digitalWrite(leftMotorPin1,LOW);
digitalWrite(leftMotorPin2,LOW);
}
analogWrite(enableRightMotor, abs(rightMotorSpeed));
analogWrite(enableLeftMotor, abs(leftMotorSpeed));
}






Comentarios

Entradas populares de este blog

EXAMEN DE EXCEL 📚🧠📌

 Seguir las indicaciones para cumplir con la evaluación de Excel 💪📊📌📂📚🧠 Actividad 1: Una tienda de computadoras necesita adquirir nueva mercancía, para ello necesitan elaborar en Excel una tabla de gastos, para tener un presupuesto. Esta es la lista que tienen y el precio Computadora de escritorio - 10500 pesos 💻💻💻💻 Laptop Lenovo - 9800 pesos 💻🧍 Audifonos - 150 pesos 👂 💻 Mouse - 100 pesos 🐀 Teclado - 250 pesos 🎹 Licencia de antivirus - 1800 pesos 👾👾👾👿 Tapete para mouse - 250 pesos La tienda necesita  Computadora de escritorio - 8 piezas Laptop Lenovo - 25 piezas Audifonos - 50 piezas Mouse - 33 piezas Teclado - 33 piezas Licencia de antivirus - 7 piezas Tapete para mouse - 50 piezas Elaborar en Excel una hoja llamada "PRESUPUESTO" de color verde y en esa hoja una tabla donde se coloquen los precios por cada pieza y al final se coloque el total global de todo lo que se debe de gastar, favor de revisar bien las filas y columnas, ya que son importantes Agrega...

Examen Práctico de Microsoft Word

Las siguientes indicaciones forman parte del examen en Microsoft Word 📕📚🤓🤓 No olviden tomar en cuenta aspectos como tamaño, tipo de letra, color, etc. 1. Elaborar un documento en Word sobre  "¿Qué es la  Computación en la nube?"  😱🙀  mínimo  1 hoja de investigación , y en base a ello  complementar el documento con las siguientes instrucciones. ⛅💻 2. Crear un Gráfico SmartArt  de tipo "Jerarquía". Añade los siguientes modelos de implementación en el gráfico: 1.  "Nube Pública"  👾 2.  "Nube Privada" 💥 3.  "Nube Híbrida" 👀 Cambia los colores del Smart Art a uno que te guste. ✐🔵🔴🟢 3. Uso de Ilustraciones para explicar el Uso de la Nube 🌄🌄 Inserta 2 imágenes relacionadas con el uso de la nube. Da formato y posición a las imágenes, de manera que se vean agradables a la vista. 😀💬👀 😎😎👍GUARDAR EL ARCHIVO CON EL NOMBRE: Nombre_Apellidos_EXAMEN1_WORD.docx