Codigos Arduino
Codigos Arduino
int volumen;
void setup() {
pinMode(13, OUTPUT);
void loop() {
volumen = analogRead(A0);
estado = !estado;
delay(25);
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define melodyPin 3
int melody[] = {
0, NOTE_C7, NOTE_E7, 0,
NOTE_G7, 0, 0, 0,
NOTE_G6, 0, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0,
NOTE_C7, 0, 0, NOTE_G6,
0, 0, NOTE_E6, 0,
0, NOTE_A6, 0, NOTE_B6,
0, NOTE_AS6, NOTE_A6, 0,
0, NOTE_E7, 0, NOTE_C7,
NOTE_D7, NOTE_B6, 0, 0
};
int tempo[] = {
9, 9, 9,
9, 9, 9,
};
int underworld_melody[] = {
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_AS3, NOTE_AS4, 0,
0,
NOTE_DS3, NOTE_DS4, 0,
0,
NOTE_DS3, NOTE_DS4, 0,
NOTE_CS4, NOTE_DS4,
NOTE_DS4, NOTE_GS3,
NOTE_G3, NOTE_CS4,
0, 0, 0
};
int underworld_tempo[] = {
12, 12, 6,
3,
12, 12, 6,
3,
12, 12, 6,
3,
12, 12, 6,
6, 6,
6, 6,
6, 6,
18, 18, 18, 18, 18, 18,
3, 3, 3
};
void setup(void)
pinMode(13, OUTPUT);//buzzer
void loop()
sing(1);
sing(1);
sing(2);
int song = 0;
void sing(int s) {
song = s;
if (song == 2) {
buzz(melodyPin, 0, noteDuration);
} else {
delay(pauseBetweenNotes);
buzz(melodyPin, 0, noteDuration);
digitalWrite(13, HIGH);
digitalWrite(targetPin, HIGH);
delayMicroseconds(delayValue);
digitalWrite(targetPin, LOW);
delayMicroseconds(delayValue);
digitalWrite(13, LOW);
}
SENSOR DE MOVIMIENTO
#include <Ultrasonic.h>
int distance;
Ultrasonic ultrasonic(TRIG,ECHO);
void setup(){
Serial.begin(9600);
pinMode(BUZZER, OUTPUT);
void loop(){
distance=ultrasonic.read();
Serial.println(distance);
if(distance<= 20){
digitalWrite(BUZZER,HIGH);}
else{
digitalWrite(BUZZER, LOW);
delay(10);
}
Sensor de temperature
#include<DHT.h>
DHT dht(sensorDHT,DHT11);
void setup(){
Serial.begin(9600);
pinMode(caliente,OUTPUT);
dht.begin();
void loop(){
humedad= dht.readHumidity();
temp= dht.readTemperature();
Serial.print(temp);
Serial.println("ºC");
Serial.print("Humedad: ");
Serial.print(humedad);
Serial.print("%");
Serial.println(" ");
Serial.println(" ");
delay(2000);
while(temp>=28){
Serial.println("Temperatura MÁXIMA EXCEDIDA (28°C)");
digitalWrite(caliente,HIGH);
temp= dht.readTemperature();
Serial.print(temp);
Serial.println("ºC");
Serial.print("Humedad: ");
Serial.print(humedad);
Serial.print("%");
Serial.println(" ");
Serial.println(" ");
delay(2000);
digitalWrite(caliente,LOW);