lunes, 30 de marzo de 2015

Arduino y la magia: Conceptos

MATERIALES:


Sin título (2).png       Sin título1 (2).png             Sin título (3).png
RESISTENCIAS                              LED                                          PLACA BOARD


Sin título1 (4).png                 


PLACA ARDUINO                         POTENCIOMETRO                  LDR
      


               
CABLES                                                                  POTENCIOMETRO
(CALIBRACIÓN)


LEYENDO EN ANALÓGICO (17/03/15)(8:30-9:25)
  1. Materiales:
Una placa arduino, led, una serie de cables, una placa board y un potenciómetro


  1. Código: para conseguir un montaje  en el que el led vaya cambiando su intensidad de brillo, en función de cómo pongas el potenciómetro hay que introducir el siguiente código:
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int val = analogRead(A5);
digitalWrite(ledPin, HIGH);
delay(val);
digitalWrite(ledPin, LOW);
delay(val);
}


3. Montaje: aquí tenemos algunos ejemplos:


IMG-20150329-WA0022.jpg     IMG-20150329-WA0027.jpg


(Como se puede observar en las fotos, en este montaje no se incluye ninguna resistencia protectora. Esto se debe a que el led está conectado al pin 13 y en este caso la placa ya lleva una incorporada. Si se conectase a otro lugar, necesitaríamos la resistencia)



ESCRIBIENDO EN ANALÓGICO (20/03/15) (9:25-10:20)
  1. Materiales:
Placa board, una serie de cables, led, una placa arduino y una resistencia de 220 Ohm (rojo, rojo, marrón)


  1. Para realizar el montaje que se muestra en el apartado 3 se tiene que introducir el siguiente código:
int ledPin = 10;
int fade = 0;
void setup() {
// nothing here
}
void loop() {
analogWrite(ledPin, fade);
delay(10);
fade = fade + 10;
if (fade > 255) fade = 0;
}


  1. Montaje:
Para realizar el montaje, se coge el led y la resistencia de 220 Ohm, se conecta el Pin largo del led a la resistencia y el otro Pin de la resistencia al pin digital 10. Para finalizar, se conecta el brazo corto del LED a GND.
Aquí se muestran algunos ejemplos:










 




  

 LDR (19/03/15) (10:35-11:20)
  1. Materiales:
Placa arduino, placa board, una serie de cables, dos resistencias de 220 y 10 Ohm, un led y un LDR


  1. Código: para poder conseguir un montaje en el que el led cambie su intensidad de brillo según la cantidad de luz que detecta el LDR, se debe introducir el siguiente código:
int ledPin=10;
int ldrPin=A1;void setup() {
//nothing here
}void loop() {
int ldrValue=analogRead(ldrPin);
int ledValue=map(ldrValue,0,1023,0,255);
analogWrite(ledPin, ledValue);
delay(10);
}


  1. Montaje:
Para conseguirlo debemos conectar el LED al Pin 10. Para que el LED cambie su secuencia de brillo se pone la mano encima del LDR tapandolo. Esto hace que no capte la luz y el led se encienda. Si quitamos la mano el LDR  capta la luz y el led se enciende. Aquí tenemos algunos ejemplos:


SC20150330-125422.png     SC20150330-125622.png



4. Montaje de calibración: el montaje es igual que el anterior únicamente se añade un potenciometro que se regula con un destornillador. Esto es necesario porque no en todos los lugares hay la misma cantidad de luz, y esto hace que se pueda adaptar al lugar para cuando el LDR se tapa o destapa, pueda apagarse y encender de la misma forma en todos los sitios.
Aquí tenemos algunos ejemplos:





Sin título.png


5. Código:



int ledPin=10;
int ldrPin=A1;
int potPin=A5;
void setup() {
 pinMode(ledPin,OUTPUT);
}
void loop() {
 int ldrValue=analogRead(ldrPin);
 int threshold=analogRead(potPin);
  if(ldrValue>threshold){
   digitalWrite(ledPin,LOW);
 }else{
   digitalWrite(ledPin,HIGH);
 }
 delay(10);
}

ENVIANDO AL ORDENADOR (24/03/15) (8:30-9:25)
  1. Materiales:
Placa arduino, ordenador


  1. Código: para conseguir que automáticamente el ordenador escriba una frase repetidamente se debe introducir el siguiente código:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hola Caracola");
delay(1000);
}
  1. Montaje: en este apartado, el montaje es muy sencillo únicamente se conecta la placa arduino con un cable al ordenador. En arduino ( el programa) se escribe el código, después, se le da a cargar y finalmente en herramientas, se le da a ‘Monitor Serial’ donde se abre la ventana que escribe la secuencia. Aquí se muestra el ejemplo:
Sin título.png




  1. Otro código: con este nuevo código se escribe una secuencia de números que van de 1 en 1:
void setup() {
Serial.begin(9600);
}void loop() {
int lecturaSensor = analogRead(A1);
Serial.println(lecturaSensor);
delay(1000);
}
(El montaje utilizado es el mismo que en el de ‘Hola Caracola’)


RECIBIENDO DEL ORDENADOR (27/03/15) (9:25-10:20)
  1. Materiales:
Una placa arduino, un led y el ordenador


  1. Código: para poder conseguir que el led se encienda y se apague dependiendo de lo que se escriba en ‘Monitor Serial’, se debe escribir el siguiente código:
int ledPin=13;
int incomingByte;
void setup() {
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop() {
if(Serial.available()>0){
incomingByte=Serial.read();
if(incomingByte=='E'){
digitalWrite(ledPin, HIGH);
}
if(incomingByte=='L'){
digitalWrite(ledPin,LOW);
}
}
}


  1. Montaje: La placa board se conecta al ordenador mediante un cable y en esta, se coloca el led. Aquí se muestra el ejemplo:
(Para que el led se encienda, introducimos en arduino el código. Seguidamente, le damos a cargar y luego en herramientas, a ‘Monitor Serial’. En la ventana, se pone una ‘E’ para que el led se encienda y una ‘L’ para que el led se apague)

sábado, 14 de marzo de 2015

SPACE INTERFACE (E/S DIGITALES)
  • Materiales: swith, led, resistencias de 220 ohm y 10 hohm , una placa arduino y una serie de cables que se muestran en las siguientes imagenes:


Sin título (2).png           Sin título1 (2).png             Sin título1 (3).png     


Sin título1 (4).pngSin título (3).png
(Los colores de las led deben ser rojo, rojo, marrón, plateado y la otra debe ser marrón, negro, naranja y plateado)


  • Con todos estos materiales, podemos construir el siguiente montaje  introduciendo en arduino (programa parecido a processing) el siguiente código:
/*
 Arduino Starter Kit example
Project 2  - Spaceship Interface

This sketch is written to accompany Project 2 in the
Arduino Starter Kit

Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors

Created 13 September 2012
by Scott Fitzgerald

http://arduino.cc/starterKit

This example code is part of the public domain
*/

// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;

void setup(){
 // declare the LED pins as outputs
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);

 // declare the switch pin as an input   
 pinMode(2,INPUT);
}

void loop(){

 // read the value of the switch
 // digitalRead() checks to see if there is voltage
 // on the pin or not  
 switchstate = digitalRead(2);

 // if the button is not pressed
 // turn on the green LED and off the red LEDs  
 if (switchstate == LOW) {
   digitalWrite(3, HIGH); // turn the green LED on pin 3 on
   digitalWrite(4, LOW);  // turn the red LED on pin 4 off
   digitalWrite(5, LOW);  // turn the red LED on pin 5 off
 }
 // this else is part of the above if() statement.
 // if the switch is not LOW (the button is pressed)
 // turn off the green LED and blink alternatively the red LEDs
 else {
   digitalWrite(3, LOW);  // turn the green LED on pin 3 off
   digitalWrite(4, LOW);  // turn the red LED on pin 4 off
   digitalWrite(5, HIGH); // turn the red LED on pin 5 on
   // wait for a quarter second before changing the light
   delay(250);
   digitalWrite(4, HIGH); // turn the red LED on pin 4 on
   digitalWrite(5, LOW);  // turn the red LED on pin 5 off
   // wait for a quarter second before changing the light
   delay(250);
 }
}
Así es como quedaría:
IMG-20150312-WA0007.jpg


Con este código lo que se hace es una secuencia en la que las bombillas se van encendiendo una después de otra rápidamente.
Seguimos experimentando.
  • Con el siguiente código lo que podemos conseguir es lo siguiente: (10/03/15) (De 8.30 a 9:25)
/*
 Arduino Starter Kit example
Project 2  - Spaceship Interface
Modificación: video grabado a las nueve y cuarto, dia 10
This sketch is written to accompany Project 2 in the
Arduino Starter Kit
Parts required:
1 green LED
2 red LEDs
pushbutton
10 kilohm resistor
3 220 ohm resistors
Created 13 September 2012
by Scott Fitzgerald
http://arduino.cc/starterKit


This example code is part of the public domain
*/


// Create a global variable to hold the
// state of the switch. This variable is persistent
// throughout the program. Whenever you refer to
// switchState, you’re talking about the number it holds
int switchstate = 0;


void setup(){
 // declare the LED pins as outputs
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);


 // declare the switch pin as an input   
 pinMode(2,INPUT);
}


void loop(){


 // read the value of the switch
 // digitalRead() checks to see if there is voltage
 // on the pin or not  
 switchstate = digitalRead(2);


 // if the button is not pressed
 // blink the red LEDs  
 if (switchstate == LOW) {
   digitalWrite(3, HIGH); // turn the green LED on pin 3 on
   digitalWrite(4, LOW);  // turn the red LED on pin 4 off
   digitalWrite(5, LOW);  // turn the red LED on pin 5 off
 }
 // this else is part of the above if() statement.
 // if the switch is not LOW (the button is pressed)
 // the code below will run  
 else {
   digitalWrite(4, LOW);  // turn the green LED on pin 3 off
   digitalWrite(3, LOW);  // turn the red LED on pin 4 off
   digitalWrite(4, HIGH); // turn the red LED on pin 5 on
   // wait for a quarter second before changing the light
   delay(250);
   digitalWrite(4, HIGH); // turn the red LED on pin 4 on
   digitalWrite(5, LOW);  // turn the red LED on pin 5 off
   // wait for a quarter second before changing the light
   delay(250);
 }
}
IMG-20150312-WA0004 (1).jpg      Sin título.png




 


(El trabajo1 solo consiste en que solo se enciendan 2 bombillas de las 3)
(El trabajo2 consiste en que se enciendas las 3 bombillas)


  • Por último se en esta foto hay varias idea de pequeños circuitos muy sencillos programados en arduino introduciendo el código blink (lo puedes encontrar enSin título (4).pngy ahí darle al apartado donde pone blink).


Aquí tenemos el ejemplo de como quedaría: (27/02/15) (De 9:25 a 10:20)


IMG-20150312-WA0008.jpg               IMG-20150312-WA0000.jpg





En esta última imagen se muestran algunos ejemplos sencillos que se pueden realizar:

IMG-20150312-WA0001.jpg