CINCO

Práctica con Arduino:

Código:

int medio = 13;
int ia = 12;
int a = 11;
int da = 10;
int iab = 9;
int ab = 8;
int dab = 7;


void setup() {

  pinMode(medio, OUTPUT);
  pinMode(ia, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(da, OUTPUT);
  pinMode(iab, OUTPUT);
  pinMode(ab, OUTPUT);
  pinMode(dab, OUTPUT);
}

void loop() {
  digitalWrite(medio, HIGH);   //0
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);

 digitalWrite(medio, HIGH);   //1
  digitalWrite(ia, HIGH);
  digitalWrite(a, HIGH);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);

   digitalWrite(medio, LOW);   //2
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, HIGH);
  delay(1000);

   digitalWrite(medio, LOW);   //3
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);

   digitalWrite(medio, LOW);   //4
  digitalWrite(ia, LOW);
  digitalWrite(a, HIGH);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);

  digitalWrite(medio, LOW);   //5
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, HIGH);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);


   digitalWrite(medio, LOW);   //6
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, HIGH);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);


   digitalWrite(medio, HIGH);   //7
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);


   digitalWrite(medio, LOW);   //8
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);

   digitalWrite(medio, LOW);   //9
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
}

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


Código:

int medio = 13;
int ia = 12;
int a = 11;
int da = 10;
int iab = 9;
int ab = 8;
int dab = 7;


void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
   pinMode(medio, OUTPUT);
  pinMode(ia, OUTPUT);
  pinMode(a, OUTPUT);
  pinMode(da, OUTPUT);
  pinMode(iab, OUTPUT);
  pinMode(ab, OUTPUT);
  pinMode(dab, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);

  Serial.print(voltage);

  if(voltage<3.5) {
  digitalWrite(medio, HIGH);   //0
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
  }

  if(voltage>3.5 && voltage<3.64) {
  digitalWrite(medio, HIGH);   //1
  digitalWrite(ia, HIGH);
  digitalWrite(a, HIGH);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);
  }

  if(voltage>3.64 && voltage<3.78){
  digitalWrite(medio, LOW);   //2
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, HIGH);
  delay(1000);
  }

  if(voltage>3.78 && voltage<3.92){
    digitalWrite(medio, LOW);   //3
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000); 
  }

  if(voltage>3.92 && voltage<4.06){
     digitalWrite(medio, LOW);   //4
  digitalWrite(ia, LOW);
  digitalWrite(a, HIGH);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);
  }

   if(voltage>4.06 && voltage<4.2){
    digitalWrite(medio, LOW);   //5
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, HIGH);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
  }

   if(voltage>4.2 && voltage<4.34){
     digitalWrite(medio, LOW);   //6
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, HIGH);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
  }

   if(voltage>4.34 && voltage<4.48){
   digitalWrite(medio, HIGH);   //7
  digitalWrite(ia, HIGH);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, HIGH);
  digitalWrite(dab, LOW);
  delay(1000);
  }

  if(voltage>4.48 && voltage<4.62){
    digitalWrite(medio, LOW);   //8
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, LOW);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
 }
 
if(voltage>4.62 && voltage<4.76){
  digitalWrite(medio, LOW);   //9
  digitalWrite(ia, LOW);
  digitalWrite(a, LOW);
  digitalWrite(da, LOW);
  digitalWrite(iab, HIGH);
  digitalWrite(ab, LOW);
  digitalWrite(dab, LOW);
  delay(1000);
}

}

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



Código:

void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}


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

Código:

int l1 = 13;
int l2 = 12;
int l3 = 11;
int l4 = 10;
int l5 = 9;
int l6 = 8;



void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  pinMode(l1, OUTPUT);
  pinMode(l2, OUTPUT);
  pinMode(l3, OUTPUT);
  pinMode(l4, OUTPUT);
  pinMode(l5, OUTPUT);
  pinMode(l6, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);

  if(voltage<.25){
   digitalWrite(l1, LOW);
   digitalWrite(l2, LOW);
   digitalWrite(l3, LOW);
   digitalWrite(l4, LOW);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

  if(voltage>.25 && voltage<.30){
    digitalWrite(l1, HIGH);
   digitalWrite(l2, LOW);
   digitalWrite(l3, LOW);
   digitalWrite(l4, LOW);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

  if(voltage>.30 && voltage<.35){
    digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, LOW);
   digitalWrite(l4, LOW);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

  if(voltage>.35 && voltage<.40){
    digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, LOW);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

  if(voltage>.40 && voltage<.45){
    digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, HIGH);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

   if(voltage>.45 && voltage<.50){
    digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, HIGH);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
  }

   if(voltage>.5 && voltage<.55){
   digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, HIGH);
   digitalWrite(l5, HIGH);
   digitalWrite(l6, LOW);
  }

   if(voltage>.55 && voltage<.6){
   digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, HIGH);
   digitalWrite(l5, HIGH);
   digitalWrite(l6, HIGH);
  }

  if(voltage>.6){
   digitalWrite(l1, HIGH);
   digitalWrite(l2, HIGH);
   digitalWrite(l3, HIGH);
   digitalWrite(l4, HIGH);
   digitalWrite(l5, HIGH);
   digitalWrite(l6, HIGH);
    delay(300);
   digitalWrite(l1, LOW);
   digitalWrite(l2, LOW);
   digitalWrite(l3, LOW);
   digitalWrite(l4, LOW);
   digitalWrite(l5, LOW);
   digitalWrite(l6, LOW);
    delay(300);
  }


}

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

Código:

#include <LiquidCrystal.h>

LiquidCrystal lcd (12,11,5,4,3,2);
const int inPin =0;

void setup() {
  lcd.begin(16,2);
  Serial.begin(9600);

}

void loop()
{
 int value = analogRead(inPin);
  lcd.setCursor(0,1);
  float voltage = value *5.0;
  voltage /=1024.0;

  float celsius = (voltage-0.5)* 100;
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(celsius,1);
  lcd.print("C TEMP");
  lcd.setCursor(0,1);
  lcd.print((celsius*9)/5 + 32,1);
  lcd.print("F Dr.COGLEZ");

  delay(1000);

  Serial.println(analogRead(0));
  delay(100);

}
--------------------------------------------------------------------


Código:

int m1a=13;
int m1b=12;

int m2a=11;
int m2b=10;

void setup()
{
  pinMode(m1a, OUTPUT);
  pinMode(m1b, OUTPUT);
  pinMode(m2a, OUTPUT);
  pinMode(m2b, OUTPUT);
}

void loop()
{
  //Motor A
  digitalWrite(m1a, HIGH);
  digitalWrite(m1b, LOW);
   digitalWrite(m2a, LOW);
  digitalWrite(m2b, LOW);

  delay(2000);

   digitalWrite(m1a, LOW);
  digitalWrite(m1b, LOW);
   digitalWrite(m2a, LOW);
  digitalWrite(m2b, LOW);

  delay(2000);

  digitalWrite(m1a, LOW);
  digitalWrite(m1b, HIGH);
   delay(2000);
  digitalWrite(m2a, LOW);
  digitalWrite(m2b, LOW);

  delay(2000);

  //Motor B

  digitalWrite(m2a, HIGH);
  digitalWrite(m2b, LOW);

  delay(2000);
  digitalWrite(m1a, LOW);
  digitalWrite(m1b, LOW);
 delay(2000);

 

  digitalWrite(m2a, LOW);
  digitalWrite(m2b, HIGH);

  delay(2000);

  digitalWrite(m1a, LOW);
  digitalWrite(m1b, LOW);
   delay(2000);
 
}

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



Código:

#include <Servo.h>

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);                  // sets the servo position according to the scaled value
  delay(15);                           // waits for the servo to get there
}

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

Código:

const int Trigger = 2;   //Pin digital 2 para el Trigger del sensor
const int Echo = 3;   //Pin digital 3 para el Echo del sensor

void setup() {
  Serial.begin(9600);//iniciailzamos la comunicación
  pinMode(Trigger, OUTPUT); //pin como salida
  pinMode(Echo, INPUT);  //pin como entrada
  digitalWrite(Trigger, LOW);//Inicializamos el pin con 0
}

void loop()
{

  long t; //timepo que demora en llegar el eco
  long d; //distancia en centimetros

  digitalWrite(Trigger, HIGH);
  delayMicroseconds(10);          //Enviamos un pulso de 10us
  digitalWrite(Trigger, LOW);

  t = pulseIn(Echo, HIGH); //obtenemos el ancho del pulso
  d = t/59;             //escalamos el tiempo a una distancia en cm

  Serial.print("Distancia: ");
  Serial.print(d);      //Enviamos serialmente el valor de la distancia
  Serial.print("cm");
  Serial.println();
  delay(100);          //Hacemos una pausa de 100ms
}


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



Arduino UNO _ (LCD + SERVO)

#include <LiquidCrystal.h>

// Pines que funcionarán como salida (DISPLAY)
LiquidCrystal lcd(13,12,11,10,9,8);

// Función para temperatura
float centigrados() {
  int dato = analogRead(A0);
  float c=(500.0*dato)/1023;

  return(c);
}

byte grado[8] =
 {
    0b00001100,     // Los definimos como binarios 0bxxxxxxx
    0b00010010,
    0b00010010,
    0b00001100,
    0b00000000,
    0b00000000,
    0b00000000,
    0b00000000
 };


void setup()
{
  Serial.begin(19200);
  lcd.begin(16,2);
  lcd.createChar(1, grado);
lcd.setCursor(0,0);
lcd.print("POS.= ");
lcd.setCursor(0,1);
lcd.print("Temp.=");
}

void loop()
{
  float Centigrados = centigrados();
lcd.setCursor(7,1);
lcd.print(Centigrados);
  lcd.write(1);
  delay(100);

  if (Serial.available()) {
    setup();
    char key = Serial.read();
    lcd.setCursor(8,0);
    lcd.print(key);

    if(key == '1'){
      lcd.setCursor(6,0);
      lcd.print("IZQUIERDA");
    }
      if(key == '2'){
      lcd.setCursor(6,0);
      lcd.print("MEDIO");
    }
    if(key == '3'){
      lcd.setCursor(6,0);
      lcd.print("DERECHA");
    }
  }
}
  

Arduino UNO _ (KEYPAD)

#include <Servo.h>
#include <Keypad.h>

Servo myservo;
int pos = 0;

// Número de renglones y columnas
const byte rows = 4;
const byte cols = 4;

// Pines que funcionarán como entrada (TECLADO 4X4)
byte rowPins[4] = {2, 3, 4, 5};
byte colPins[4] = {6, 7, 8, 9};

char keys[rows][cols] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, rows, cols );

void setup()
{
  myservo.attach(11);
  Serial.begin(19200);
}

void loop()
{
  //pos=pos+90;
  char key = keypad.getKey();
  if (key != NO_KEY){
      Serial.print(key);
    
     if(key == '1'){
            myservo.write(pos=0); 
            delay(10);                        
        
     }
    
     if(key == '2'){
myservo.write(pos=90); 
            delay(10);                        
        
     }
    
     if(key == '3'){
            myservo.write(pos=180);
            delay(10); 
        }
     } 
   }