You are on page 1of 23

ARDUINO

Qu es Arduino
Arduino es una herramienta para hacer que los ordenadores puedan sentir y
controlar el mundo fsico a travs de tu ordenador personal. Es una
plataforma de desarrollo de computacin fsica (physical computing) de
cdigo abierto, basada en una placa con un sencillo microcontrolador y un
entorno de desarrollo para crear software (programas) para la placa. Puedes
usar Arduino para crear objetos interactivos, leyendo datos de una gran
variedad de interruptores y sensores y controlar multitud de tipos de luces,
motores y otros actuadores fsicos. Los proyectos con Arduino pueden ser
autnomos o comunicarse con un programa (software) que se ejecute en tu
ordenador. La placa puedes montarla t mismo o comprarla ya lista para
usar, y el software de desarrollo es abierto y lo puedes descargar gratis desde
la pgina www.arduino.cc/en/
Alimentacin ( power)
Entradas/salidas digitales (inputs/outputs)
Entradas anlogas (analog inputs)
Primeros pasos con arduino
Funciones bsicas
Funciones bsicas
Funciones bsicas
Encender y apagar un led
/ the setup function runs once when you press reset or power
the board
void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage
level)
delay(1000); // wait for a second
digitalWrite(13, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}
Lectura digital monitor serial
This example code is in the public domain.
*/
// digital pin 2 has a pushbutton attached to it. Give it a
name:
int pushButton = 2;
// the setup routine runs once when you press reset:

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

// make the pushbutton's pin an input:


pinMode(pushButton, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState = digitalRead(pushButton);
// print out the state of the button:
Serial.println(buttonState);
delay(1); // delay in between reads for stability
}
Encendido de un LED con tiempo
const int ledPin = 13;

int ledState = LOW;


const long interval = 1000;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}
Utilizando Pulsador
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed.


// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
Ejercicio practico #1
Encienda cinco led, en los puertos 2,3,4,5,6 con tres diferentes
secuencias.
Ejercicio para la casa
Armar y programar el circuito que se muestra en el link.
http://www.geekfactory.mx/tutoriales/tutoriales-arduino/tutorial-arduino-con-fotoresistencia-ldr/
SEMANA #2
UTILIZANDO ENTRADAS DIGITALES
UTILIZANDO ENTRADAS DIGITALES
http://www.arduino.cc/en/Tutorial/ButtonSt
ateChange
buttonState = digitalRead(buttonPin);
*/

// this constant won't change: if (buttonState != lastButtonState) {

const int buttonPin = 2; if (buttonState == HIGH) {

const int ledPin = 13;


buttonPushCounter++;
Serial.println("on");
int buttonPushCounter = 0; Serial.print("number of button pushes: ");
Serial.println(buttonPushCounter);
int buttonState = 0; } else {

int lastButtonState = 0; Serial.println("off");


}
void setup() {
delay(50);
pinMode(buttonPin, INPUT); }
pinMode(ledPin, OUTPUT); lastButtonState = buttonState;
Serial.begin(9600);
} if (buttonPushCounter % 4 == 0) {
digitalWrite(ledPin, HIGH);
} else {
void loop() { digitalWrite(ledPin, LOW);
}

}
UTILIZANDO ENTRADAS ANALOGAS
http://www.arduino.cc/en/Tutorial/AnalogInput
*/
int sensorPin = A0; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
void setup() {
// declare the ledPin as an OUTPUT:
pinMode(ledPin, OUTPUT);
}
void loop() {
// read the value from the sensor:
sensorValue = analogRead(sensorPin);
// turn the ledPin on
digitalWrite(ledPin, HIGH);
// stop the program for <sensorValue> milliseconds:
delay(sensorValue);
// turn the ledPin off:
digitalWrite(ledPin, LOW);
// stop the program for for <sensorValue> milliseconds:
delay(sensorValue);
}

You might also like