You are on page 1of 6

Contenido

ARDUINO. ...................................................................................................................................... 1
Salidas digitales. ........................................................................................................................ 1
Esquema. ............................................................................................................................... 1
Cdigo.................................................................................................................................... 2
Entradas digitales. ..................................................................................................................... 3
Esquema. ............................................................................................................................... 3
Cdigo.................................................................................................................................... 3
Entradas analgicas. .................................................................................................................. 4
Esquema. ............................................................................................................................... 4
Cdigo.................................................................................................................................... 4
Salida analgica. ........................................................................................................................ 4
Esquema ................................................................................................................................ 5
Cdigo.................................................................................................................................... 5
Enlaces. ...................................................................................................................................... 6


ARDUINO.
Salidas digitales.
Utilizaremos la salida digital 13. Esta viene de fbrica con un led en la placa y una resistencia.
Esta resistencia nos ayuda a conectar un led de forma directa.
Esquema.

La patilla positiva de led ira a la salida 13 y la
negativa la conectaremos a GND.
Cdigo.
/*
Este es un bloque de comentarios, su contenido
ser ignorado por el compilador.
Su funcin es almacenar informacin que nos
haga ms sencilla la compresin del cdigo o
recordar su funcionamiento tiempo despus, as
que cuanto ms descriptivos seamos mejor.
BLINK
Enciende un LED durante un segundo, lo apaga durante otro segundo, repetidamente. Este
ejemplo de cdigo es de dominio pblico.
*/

// Pin 13 tiene un pin conectado.
// le damos un nombre al pin.
int led = 13;

// esta oarte del cdigo, setup, corre slo una vez cada vez que pulsamos el reset.
void setup() {
// inicializamos el pin 13, llamado led, como salida.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // pone la salida digital, led, a nivel alto.
delay(1000); // espera 1000 mseg.
digitalWrite(led, LOW); // pone la salida digital, led, a nivel bajo.
delay(1000); // espera 1000 mseg.
}
Entradas digitales.
Esquema.

Utilizaremos el pin 2 configurado como entrada. Utilizaremos una resistencia de pull-down.
Esto quiere decir, que mientras no pulsemos el interruptor existir un cero lgico LOW en la
entrada 2. Al pulsar el interruptor llevamos la entrada 2 a nivel alto HIGH.
Cdigo.
/*
A travs del pin2 configurado como entrada, vigilaremos si es pulsado el interruptor
conectado a ese pin. Al ser pulsado encenderemos el led de la placa conectado al pin13.

The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground


// asignamos nombres a los pines
// set pin numbers:
const int pulsador = 2; // the number of the pushbutton pin
const int led= 13; // the number of the LED pin

// variables will change:
int estadopulsador = 0; // variable donde guardaremos estado del pulsador. 0 sino esta
pulsado.
void setup() {
// inicializamos pin:
pinMode(led, OUTPUT);
pinMode(pulsador, INPUT);
}

void loop(){
// lee el estado del pulsador y pone su valor en la variable estadopulsador:
estadopulsador = digitalRead(pulsador);

// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (estadopulsador == HIGH) {
// turn LED on:
digitalWrite(led, HIGH);
}
else {
// turn LED off:
digitalWrite(led, LOW);
}
}

Entradas analgicas.
Lee el valor de un potencimetro en una entrada analgica, y muestra su valor en pantalla.
Esquema.


Cdigo.
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

This example code is in the public domain.
*/

// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second, paa poder ver lo valores en
pantalla:
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);
// print out the value you read, muestra por pantalla el valor:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
}

Salida analgica.
Lee el valor de un potencimetro, entrada analgica, y segn su valor da un valor de salida
analgico, proporcional a la entrada a travs del comando map.
Muestra todos los valores en la pantalla.

Esquema




Cdigo.
/*
Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground

created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe

This example code is in the public domain.

*/

// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPin = 9; // Analog output pin that the LED is attached to

int sensorValue = 0; // value read from the pot
int outputValue = 0; // value output to the PWM (analog out)

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin, outputValue);

// print the results to the serial monitor: println imprime y salto de lnea
Serial.print("sensor = " );
Serial.print(sensorValue);
Serial.print("\t output = ");
Serial.println(outputValue);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
Enlaces.
http://arduino.cc/es/Tutorial/HomePage
http://www.trastejant.es/circuitos/cardu.php
http://www.ardumania.es/

You might also like