jueves, 25 de febrero de 2016

TECLADO SONORO

En esta practica hemos utilizado una placa arduino, una placa board, 4 pulsadores, 2 resistencias de 10 kilo ohmios, una de 1 m ohmios y otra de 220 ohmios. También un altavoz y varios cables.
 Esta practica consiste en tocar los distintos pulsadores y cada vez que tocabas cada uno de los distintos pulsadores el sonido que producía el altavoz iba cambiando

El programa es el siguiente
/*
  Arduino Starter Kit example
 Project 7  - Keyboard

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

 Parts required:
 two 10 kilohm resistors
 1 Megohm resistor
 220 ohm resistor
 4 pushbuttons
 piezo

 Created 13 September 2012
 by Scott Fitzgerald

 http://arduino.cc/starterKit

 This example code is part of the public domain
*/

// create an array of notes
// the numbers below correspond to
// the frequencies of middle C, D, E, and F
int notes[] = {262, 294, 330, 349};

void setup() {
    //start serial communication
  Serial.begin(9600);
}

void loop() {
  // create a local variable to hold the input on pin A0
  int keyVal = analogRead(A0);
  // send the value from A0 to the Serial Monitor
  Serial.println(keyVal);

  // play the note corresponding to each value on A0
  if(keyVal == 1023){
    // play the first frequency in the array on pin 8
    tone(8, notes[0]);
  }
  else if(keyVal >= 990 && keyVal <= 1010){
    // play the second frequency in the array on pin 8
    tone(8, notes[1]);
  }
  else if(keyVal >= 505 && keyVal <= 515){
    // play the third frequency in the array on pin 8
    tone(8, notes[2]);
  }
  else if(keyVal >= 5 && keyVal <= 10){
    // play the fourth frequency in the array on pin 8
    tone(8, notes[3]);
  }
  else{
    // if the value is out of range, play no tone
    noTone(100);
  }
}




miércoles, 17 de febrero de 2016

LÁMPARA DE COLORES

En este proyecto hemos utilizado 3 LDR, 6 resistencias, tres de 220 ohmios y otras tres de 10k. Además hemos empleado un elemento nuevo, un led de 4 patas, y de varios colores.
Con esto hemos conseguido que al tapar las distinatas LDR, de forma aleatoria, el led cambiaba de color, como se ve en el siguiente vídeo:

PROGRAMA:

/*
  Arduino Starter Kit example
 Project 4  - Color Mixing Lamp

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

 Parts required:
 1 RGB LED
 three 10 kilohm resistors
 3 220 ohm resistors
 3 photoresistors
 red green and blue colored gels

 Created 13 September 2012
 Modified 14 November 2012
 by Scott Fitzgerald
 Thanks to Federico Vanzati for improvements

 http://arduino.cc/starterKit

 This example code is part of the public domain
 */

const int greenLEDPin = 9;    // LED connected to digital pin 9
const int redLEDPin = 10;     // LED connected to digital pin 10
const int blueLEDPin = 11;    // LED connected to digital pin 11

const int redSensorPin = A0;  // pin with the photoresistor with the red gel
const int greenSensorPin = A1;   // pin with the photoresistor with the green gel
const int blueSensorPin = A2;   // pin with the photoresistor with the blue gel

int redValue = 0; // value to write to the red LED
int greenValue = 0; // value to write to the green LED
int blueValue = 0; // value to write to the blue LED

int redSensorValue = 0; // variable to hold the value from the red sensor
int greenSensorValue = 0; // variable to hold the value from the green sensor
int blueSensorValue = 0; // variable to hold the value from the blue sensor

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

  // set the digital pins as outputs
  pinMode(greenLEDPin,OUTPUT);
  pinMode(redLEDPin,OUTPUT);
  pinMode(blueLEDPin,OUTPUT);
}

void loop() {
  // Read the sensors first:

  // read the value from the red-filtered photoresistor:
  redSensorValue = analogRead(redSensorPin);
  // give the ADC a moment to settle
  delay(5);
  // read the value from the green-filtered photoresistor:
  greenSensorValue = analogRead(greenSensorPin);
  // give the ADC a moment to settle
  delay(5);
  // read the value from the blue-filtered photoresistor:
  blueSensorValue = analogRead(blueSensorPin);

  // print out the values to the serial monitor
  Serial.print("raw sensor Values \t red: ");
  Serial.print(redSensorValue);
  Serial.print("\t green: ");
  Serial.print(greenSensorValue);
  Serial.print("\t Blue: ");
  Serial.println(blueSensorValue);

  /*
  In order to use the values from the sensor for the LED,
  you need to do some math. The ADC provides a 10-bit number,
  but analogWrite() uses 8 bits. You'll want to divide your
  sensor readings by 4 to keep them in range of the output.
  */
  redValue = redSensorValue/4;
  greenValue = greenSensorValue/4;
  blueValue = blueSensorValue/4;

  //  print out the mapped values
  Serial.print("Mapped sensor Values \t red: ");
  Serial.print(redValue);
  Serial.print("\t green: ");
  Serial.print(greenValue);
  Serial.print("\t Blue: ");
  Serial.println(blueValue);

  /*
  Now that you have a usable value, it's time to PWM the LED.
  */
  analogWrite(redLEDPin, redValue);
  analogWrite(greenLEDPin, greenValue);
  analogWrite(blueLEDPin, blueValue);
}

Vídeo y fotos








miércoles, 10 de febrero de 2016

LOVE O METER

En este proyecto hemos utilizado 3 resistencias de 220 ohmnios cada una, 3 diodos led, varios cables, placa arduino y placa board, y por último un elemento nuevo que no habíamos utilizado antes, un sensor que detecta la temperatura, en concreto los cambios de la misma. Con todo ello hemos conseguido que poner el dedo en el sensor, este detecta el calor humano y a medida que la temperatura va aumentando, se van encendiendo los diferentes led (en función a los valores que hemos fijado). A medida que la temperatura aumentaba, también lo hacía el número de leds encendidos, como se muestra  en el siguiente vídeo.



/*
  Arduino Starter Kit example
 Project 3  - Love-O-Meter

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

 Parts required:
 1 TMP36 temperature sensor or LM35DZ
 3 red LEDs
 3 220 ohm resistors

 Created 13 September 2012
 by Scott Fitzgerald

 http://arduino.cc/starterKit

 This example code is part of the public domain 
 */

// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;

void setup(){
  // open a serial connection to display values
  Serial.begin(9600);
  // set the LED pins as outputs
  // the for() loop saves some extra coding
  for(int pinNumber = 2; pinNumber<5; pinNumber++){
    pinMode(pinNumber,OUTPUT);
    digitalWrite(pinNumber, LOW);
  }
}

void loop(){
  // read the value on AnalogIn pin 0 
  // and store it in a variable
  int sensorVal = analogRead(sensorPin);

  // send the 10-bit sensor value out the serial port
  Serial.print("sensor Value: ");
  Serial.print(sensorVal); 

  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;

  // Send the voltage level out the Serial port
  Serial.print(", Volts: ");
  Serial.print(voltage);

  // convert the voltage to temperature in degrees C
  // the sensor changes 10 mV per degree
  // the datasheet says there's a 500 mV offset
  // ((volatge - 500mV) times 100) for tmp36
  // ((volatge) times 100) for LM35DZ
  Serial.print(", degrees C: "); 
  float temperature = (voltage) * 100;
  Serial.println(temperature);

  // if the current temperature is lower than the baseline
  // turn off all LEDs
  if(temperature < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 2-4 degrees, turn an LED on 
  else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 4-6 degrees, turn a second LED on  
  else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  } // if the temperature rises more than 6 degrees, turn all LEDs on
  else if(temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
  }
  delay(1);
}




jueves, 4 de febrero de 2016

THEREMIN DE LUZ 2

En esta práctica hemos investigado en el programa y cambiando la función delay, que se encuentra al final, hemos conseguido que cambie la tonalidad del altavoz. De tal forma que si lo ponemos a 1 el sonido es muy grave y seguido, y cuando lo pusimos a 1000 el tono era más agudo y más intermitente.

VÍDEO delay 1








VÍDEO delay 1000






THEREMIN DE LUZ

En esta práctica hemos utilizado además de los materiales habituales como cables o placa arduino y placa board, hemos usado un altavoz, una LDR, y una resistencia de 10 kOhmios.
Con ello hemos conseguido que al poner la mano encima de la LDR, esta detecta sombra y cambia el sonido como se muestra en el siguiente video.

El programa es el siguiente:

/* Arduino Starter Kit example Project 6 - Light Theremin This sketch is written to accompany Project 6 in the Arduino Starter Kit Parts required: photoresistor 10 kilohm resistor piezo Created 13 September 2012 by Scott Fitzgerald http://arduino.cc/starterKit This example code is part of the public domain */ // variable to hold sensor value int sensorValue; // variable to calibrate low value int sensorLow = 1023; // variable to calibrate high value int sensorHigh = 0; // LED pin const int ledPin = 13; void setup() { // Make the LED pin an output and turn it on pinMode(ledPin, OUTPUT); digitalWrite(ledPin, HIGH); // calibrate for the first five seconds after program runs while (millis() < 5000) { // record the maximum sensor value sensorValue = analogRead(A0); if (sensorValue > sensorHigh) { sensorHigh = sensorValue; } // record the minimum sensor value if (sensorValue < sensorLow) { sensorLow = sensorValue; } } // turn the LED off, signaling the end of the calibration period digitalWrite(ledPin, LOW); } void loop() { //read the input from A0 and store it in a variable sensorValue = analogRead(A0); // map the sensor values to a wide range of pitches int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000); // play the tone for 20 ms on pin 8 tone(8, pitch, 20); // wait for a moment delay(10); }

VÍDEO Y FOTOS: