Practica con arduino

Páginas: 6 (1436 palabras) Publicado: 8 de noviembre de 2010
1. Arrancamos el motor, esperamos un tiempo, después apagamos el motor.
int motorPin = 9;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
int onTime = 2500;
int offTime = 1000;
digitalWrite(motorPin, HIGH);
delay (onTime);
digitalWrite(motorPin, LOW);
delay (offTime);


2. Al igual que antes cambiabamos la iluminación del led, ahora podemos controlar lavelocidad del motor con la función analogWrite(pin, valor).
int motorPin = 9;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
int onSpeed = 200;
int onTime = 2500;
int offSpeed = 50; // a number between 0 (stopped) and 255 (full speed)
int offTime = 1000; //the number of milliseconds for the motor to turn off for
analogWrite(motorPin, onSpeed); // turns the motor Ondelay(onTime); // waits for onTime milliseconds
analogWrite(motorPin, offSpeed); // turns the motor Off
delay(offTime); // waits for offTime milliseconds
}

3. Aceleramos y desaceleramos el motor, ahora usamos un bucle para acelerar y frenar el motor, usando del mismo modo la función analogWrite(), que en el caso anterior.
int motorPin = 9;
void setup()
{
pinMode(motorPin, OUTPUT);
}
voidloop()
{
int delayTime = 50;
  tor
for(int i = 0; i < 256; i++){ //aceleramos
analogWrite(motorPin, i);
delay(delayTime);
}
for(int i = 255; i >= 0; i--){ //frenamos
analogWrite(motorPin, i);
delay(delayTime);
}
}
 

4. Usamos ahora un potenciómetro para variar la velocidad del motor. El potenciómetreo se conecta de la siguiente forma, extremos a v+ y gnd y el pin de controlal pin 0 de las entradas análogicas de Arduino.
Arduino dispone de 6 entradas analógicas, que tienen un voltaje de 0 a 5voltios que convertidas a señales digitales tendríamos de 0 a 1024, esto es 10 bits de resolución. ¿Por qué dividimos por 4 analogRead()?, pues porque esta función devuelve un valor comprendido entre 0 y 1024 (10 bits) y la función analogWrite () toma valores comprendidosentre 0 y 255 (8 bits).
int motorPin = 9;
int potPin=0;
int potValue;
void setup()
{
pinMode(motorPin, OUTPUT);
}
void loop()
{
potValue = analogRead(potPin) / 4;
analogWrite(motorPin, potValue);
}

5. Control de un servomotor
 #include <Servo.h>
Servo myservo; // creamos un objeto servo para controlar nuestro servo
int pos = 0; // variable para almacenar la posición delservo
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // avanza de 0 a 180 grados
{ // en saltos de un grado
myservo.write(pos); // mueve a la posición de la variable 'pos'
delay(15); // espera 15ms
}
for(pos = 180; pos>=1; pos-=1) // va de 180 a 0 grados
{
myservo.write(pos);delay(15);
}
}

step 1Basic implementation
This is the most basic implementation of the chip.

As you can see, a 5V Voltage Regulator is between the battery and pins 1, 9, 16.

Pin 8 gets power before the VReg, if your motor needs for example 6V you should put 6V directly in this pin, all the other pins should not get more than 5V.

This will work with no problem at all, but if you wantto do the right implementation take a look at the next example:

step 2Advanced implementation
This is the correct Implementation (with the capacitors), and note that pin 8 is feeded by unregulated voltage. This means that if your motors need more than 5V, you should power this pin with that amount of voltage, and the rest of the circuit with 5V.

// Use this code to test your motor with theArduino board:

// if you need PWM, just use the PWM outputs on the Arduino
// and instead of digitalWrite, you should use the analogWrite command

// --------------------------------------------------------------------------- Motors
int motor_left[] = {2, 3};
int motor_right[] = {7, 8};

// --------------------------------------------------------------------------- Setup
void setup()...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • practica de arduino
  • Practicas Arduino
  • Practica de Arduino
  • practicas con arduino
  • PRACTICAS ARDUINO
  • Arduino Practicas
  • practicas basicas de arduino labview
  • Practica de Servomotores aplicado a camaras con arduino

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS