quinta-feira, 10 de maio de 2018

Arduino Acendendo e Apagando Led com Controle Remoto

Acendendo e Apagando 3 Leds Com Controle Remoto da TV - Infra Vermelho

Indico que assistam a vídeo aula do link abaixo:

Arduino, Utilizando Controle Infra Vermelho

Circuito Montado Conforme Vídeo Aula do Link A Cima:






Código :



/*
 * IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */

#include <IRremote.h>

#define tecla1 0xE0E020DF
#define tecla2 0xE0E0A05F
#define tecla3 0xE0E0609F
#define tecla4 0xE0E010EF
#define tecla5 0xE0E0906F
#define tecla6 0xE0E050AF

#define led1 7
#define led2 6
#define led3 5

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    switch(results.value)
    {
      case tecla1: digitalWrite(led1, HIGH); break; //tecla 1 liga led 1
      case tecla2: digitalWrite(led2, HIGH); break; //tecla 2 liga led 2
      case tecla3: digitalWrite(led3, HIGH); break; //tecla 3 liga led 3
      case tecla4: digitalWrite(led1, LOW); break;  //tecla 4 apaga led 1
      case tecla5: digitalWrite(led2, LOW); break;  //tecla 5 apaga led 2
      case tecla6: digitalWrite(led3, LOW); break;  //tecla 6 apaga led 3
      }
   
    irrecv.resume(); // Receive the next value
  }
  delay(100);
}

TESTE DO CIRCUITO 







Lendo Controle Remorto (IR) Infra Vermelho Arduino Nano


Sugiro que assintam o Vídeo Abaixo

Arduino - Lendo o Controle Remoto (IR) da sua TV

Link Para Baixar Biblioteca Arduino - IRremote-master.zip

http://bit.ly/1Wm1cec

Circuito Montado Conforme o Vídeo sugerido a cima.






Código Para Carregar No Arduino


/*
 * IRremote: IRrecvDump - dump details of IR codes with IRrecv
 * An IR detector/demodulator must be connected to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 * JVC and Panasonic protocol added by Kristian Lauszus (Thanks to zenwheel and other people at the original blog post)
 * LG added by Darryl Smith (based on the JVC protocol)
 */

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

// Dumps out the decode_results structure.
// Call this after IRrecv::decode()
// void * to work around compiler issue
//void dump(void *v) {
//  decode_results *results = (decode_results *)v
void dump(decode_results *results) {
  int count = results->rawlen;
  if (results->decode_type == UNKNOWN) {
    Serial.print("Unknown encoding: ");
  }
  else if (results->decode_type == NEC) {
    Serial.print("Decoded NEC: ");
  }
  else if (results->decode_type == SONY) {
    Serial.print("Decoded SONY: ");
  }
  else if (results->decode_type == RC5) {
    Serial.print("Decoded RC5: ");
  }
  else if (results->decode_type == RC6) {
    Serial.print("Decoded RC6: ");
  }
  else if (results->decode_type == PANASONIC) {
    Serial.print("Decoded PANASONIC - Address: ");
    Serial.print(results->address,HEX);
    Serial.print(" Value: ");
  }
  else if (results->decode_type == LG) {
     Serial.print("Decoded LG: ");
  }
  else if (results->decode_type == JVC) {
     Serial.print("Decoded JVC: ");

  }
  else if (results->decode_type == AIWA_RC_T501) {
    Serial.print("Decoded AIWA RC T501: ");
  }
  else if (results->decode_type == WHYNTER) {
     Serial.print("Decoded Whynter: ");
  }
  Serial.print(results->value, HEX);
  Serial.print(" (");
  Serial.print(results->bits, DEC);
  Serial.println(" bits)");
  Serial.print("Raw (");
  Serial.print(count, DEC);
  Serial.print("): ");

  for (int i = 0; i < count; i++) {
    if ((i % 2) == 1) {
      Serial.print(results->rawbuf[i]*USECPERTICK, DEC);
    }
    else {
      Serial.print(-(int)results->rawbuf[i]*USECPERTICK, DEC);
    }
    Serial.print(" ");
  }
  Serial.println("");
}


void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    dump(&results);
    irrecv.resume(); // Receive the next value
  }
}


Foto Capturando os Códigos em Exadecimal do Controle Remoto Samsung






Anotando O Código Capturado para Uso Posterior.

Tecla 1 do Controle Remoto Samsung
E0E020DF (32 bits)

Tecla 2 do Controle Remoto Samsung
E0E0A05F (32 bits)


Tecla 3 do Controle Remoto Samsung
E0E0609F (32 bits)

Observação: Os códigos acima estão relacionados ao controle que utilizo como referência.


segunda-feira, 19 de março de 2018


Passo 1: Você vai precisar

Passo 2: Ligar os Componentes

Se você tem um Arduino Uno (que a maioria das pessoas tem), ligue os componentes, com a ajuda da imagem abaixo. Se você tem um Arduino Nano, procure a imagem em “Usando um Arduino Nano”.
Conecte o positivo do buzzer ao pino digital 3 , e o negativo em um resistor de 1k ohm . Conecte o outro lado do resistor de 1 k ohm ao pino terra(GND) do Arduino. Lembre-se de ligar o alarme da maneira correta, o buzzer tem pinos positivos e negativos!
Então, basicamente, o buzzer, 1 k ohm e Arduino deve ser ligados assim:
Pino Digital Arduino 3 -> Buzzer -> 1 k ohm resisotor -> Arduino terra (GND) pino.
Você pode fazer sem o resistor de 1 k ohm! Se você conectar sem o resistor, o sinal sonoro será muito mais alto, e a qualidade do som pode se degradar. Mas você também pode diminuir a resistência para obter o som um pouco mais alto, e manter a qualidade do som. Uma outra ideia é o uso de um potenciómetro, em vez de uma resistência para agir como um controlador de volume! Para este tutorial vamos estar usando um resistor de 1 k ohm.

Usando em um Arduino Uno

Abaixo está uma ilustração de como se conectar o buzzer e resistência a um Arduino Uno.




Passo 3: O Código


/*
  Arduino Mario Bros Tunes
  With Piezo Buzzer and PWM

  Connect the positive side of the Buzzer to pin 3,
  then the negative side to a 1k ohm resistor. Connect
  the other side of the 1 k ohm resistor to
  ground(GND) pin on the Arduino.

  by: Dipto Pratyaksa
  last updated: 31/3/13
*/

/*************************************************
 * Public Constants
 *************************************************/

#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 NOTE_GS2 104
#define NOTE_A2  110
#define NOTE_AS2 117
#define NOTE_B2  123
#define NOTE_C3  131
#define NOTE_CS3 139
#define NOTE_D3  147
#define NOTE_DS3 156
#define NOTE_E3  165
#define NOTE_F3  175
#define NOTE_FS3 185
#define NOTE_G3  196
#define NOTE_GS3 208
#define NOTE_A3  220
#define NOTE_AS3 233
#define NOTE_B3  247
#define NOTE_C4  262
#define NOTE_CS4 277
#define NOTE_D4  294
#define NOTE_DS4 311
#define NOTE_E4  330
#define NOTE_F4  349
#define NOTE_FS4 370
#define NOTE_G4  392
#define NOTE_GS4 415
#define NOTE_A4  440
#define NOTE_AS4 466
#define NOTE_B4  494
#define NOTE_C5  523
#define NOTE_CS5 554
#define NOTE_D5  587
#define NOTE_DS5 622
#define NOTE_E5  659
#define NOTE_F5  698
#define NOTE_FS5 740
#define NOTE_G5  784
#define NOTE_GS5 831
#define NOTE_A5  880
#define NOTE_AS5 932
#define NOTE_B5  988
#define NOTE_C6  1047
#define NOTE_CS6 1109
#define NOTE_D6  1175
#define NOTE_DS6 1245
#define NOTE_E6  1319
#define NOTE_F6  1397
#define NOTE_FS6 1480
#define NOTE_G6  1568
#define NOTE_GS6 1661
#define NOTE_A6  1760
#define NOTE_AS6 1865
#define NOTE_B6  1976
#define NOTE_C7  2093
#define NOTE_CS7 2217
#define NOTE_D7  2349
#define NOTE_DS7 2489
#define NOTE_E7  2637
#define NOTE_F7  2794
#define NOTE_FS7 2960
#define NOTE_G7  3136
#define NOTE_GS7 3322
#define NOTE_A7  3520
#define NOTE_AS7 3729
#define NOTE_B7  3951
#define NOTE_C8  4186
#define NOTE_CS8 4435
#define NOTE_D8  4699
#define NOTE_DS8 4978

#define melodyPin 3
//Mario main theme melody
int melody[] = {
  NOTE_E7, NOTE_E7, 0, NOTE_E7,
  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,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  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,

  NOTE_G6, NOTE_E7, NOTE_G7,
  NOTE_A7, 0, NOTE_F7, NOTE_G7,
  0, NOTE_E7, 0, NOTE_C7,
  NOTE_D7, NOTE_B6, 0, 0
};
//Mario main them tempo
int tempo[] = {
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,

  9, 9, 9,
  12, 12, 12, 12,
  12, 12, 12, 12,
  12, 12, 12, 12,
};
//Underworld melody
int underworld_melody[] = {
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_C4, NOTE_C5, NOTE_A3, NOTE_A4,
  NOTE_AS3, NOTE_AS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0,
  NOTE_F3, NOTE_F4, NOTE_D3, NOTE_D4,
  NOTE_DS3, NOTE_DS4, 0,
  0, NOTE_DS4, NOTE_CS4, NOTE_D4,
  NOTE_CS4, NOTE_DS4,
  NOTE_DS4, NOTE_GS3,
  NOTE_G3, NOTE_CS4,
  NOTE_C4, NOTE_FS4, NOTE_F4, NOTE_E3, NOTE_AS4, NOTE_A4,
  NOTE_GS4, NOTE_DS4, NOTE_B3,
  NOTE_AS3, NOTE_A3, NOTE_GS3,
  0, 0, 0
};
//Underwolrd tempo
int underworld_tempo[] = {
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  3,
  12, 12, 12, 12,
  12, 12, 6,
  6, 18, 18, 18,
  6, 6,
  6, 6,
  6, 6,
  18, 18, 18, 18, 18, 18,
  10, 10, 10,
  10, 10, 10,
  3, 3, 3
};

void setup(void)
{
  pinMode(3, OUTPUT);//buzzer
  pinMode(13, OUTPUT);//led indicator when singing a note

}
void loop()
{
  //sing the tunes
  sing(1);
  sing(1);
  sing(2);
}
int song = 0;

void sing(int s) {
  // iterate over the notes of the melody:
  song = s;
  if (song == 2) {
    Serial.println(" 'Underworld Theme'");
    int size = sizeof(underworld_melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / underworld_tempo[thisNote];

      buzz(melodyPin, underworld_melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }

  } else {

    Serial.println(" 'Mario Theme'");
    int size = sizeof(melody) / sizeof(int);
    for (int thisNote = 0; thisNote < size; thisNote++) {

      // to calculate the note duration, take one second
      // divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / tempo[thisNote];

      buzz(melodyPin, melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);

      // stop the tone playing:
      buzz(melodyPin, 0, noteDuration);

    }
  }
}

void buzz(int targetPin, long frequency, long length) {
  digitalWrite(13, HIGH);
  long delayValue = 1000000 / frequency / 2; // calculate the delay value between transitions
  //// 1 second's worth of microseconds, divided by the frequency, then split in half since
  //// there are two phases to each cycle
  long numCycles = frequency * length / 1000; // calculate the number of cycles for proper timing
  //// multiply frequency, which is really cycles per second, by the number of seconds to
  //// get the total number of cycles to produce
  for (long i = 0; i < numCycles; i++) { // for the calculated length of time...
    digitalWrite(targetPin, HIGH); // write the buzzer pin high to push out the diaphram
    delayMicroseconds(delayValue); // wait for the calculated delay value
    digitalWrite(targetPin, LOW); // write the buzzer pin low to pull back the diaphram
    delayMicroseconds(delayValue); // wait again or the calculated delay value
  }
  digitalWrite(13, LOW);

}

Projeto Original de Prince de Princetronics.com
Diversos são os sons que podemos produzir através de um Arduino, a única coisa que nos limita é o emissor de som que iremos utilizar e os modos de armazenamento e reprodução, esta é somente uma ideia do que pode ser feito, outras músicas podem ser tocadas desta maneira e se preferir pode adicionar um mini alto falante e aumentar o som de sua reprodução, tem mais alguma ideia do que podemos fazer? Deixe seu comentários, compartilhe suas ideias.




sexta-feira, 13 de março de 2015

Luz Noturna, Trabalhando com sensores



Circuito a ser montado




Partes do Circuito

Botão




O botão será usado para ligar ou desligar o circuito.
  • Ele deve ser conectado a porta 13 do Arduino.
  • Ao ser pressionado a primeira vez ele liga o circuito.
  • Ao ser pressionado novamente ele desliga o circuito.



Partes do Circuito

Buzzer


O Buzzer será usado para dar um retorno auditivo de diversas situações.
  • Ele deve ser ligado à porta 11 do Arduino
  • Toda vez que o botão for pressionado ele deve emitir um som.
  • Quando a intensidade de luz muda ele deve emitir um som.
  • Quando o circuito é desligado ele deve emitir um som.



Partes do Circuito

LDR
O LDR serve para ler a intensidade de luz disponível.
  • Ele deve ser ligado à porta A0 do Arduino
  • Quando o circuito está ligado ela deve ser lida, e conforme a intensidade de luz, ascender o led branco.


Partes do Circuito

LEDs


Os LEDs serão usados para indicação visual e iluminação

O LED vermelho deve estar aceso quando o sistema estiver em stand by (energizado e desligado).
O LED verde deve estar aceso quando o circuito estiver ligado.

O LED branco deve ficar aceso quando o circuito estiver ligado conforme a intensidade de luz do LDR (quanto menos luz disponível, mais aceso deve estar o LED).


LuzNoturna


  1. int ligado = LOW;
  2. int botao = 13;
  3. int ledverde = 10;
  4. int ledvermelho = 12;
  5. int ledbranco = 9;
  6. int buzzer = 11;
  7. int valoranteriorLDR = 0;
  8. int valoratualLDR = 0;

  9. boolean botaoPressionado();
  10. void som(int frquencia, int duracao);
  11. int leLDR();

  12. void setup()
  13. {
  14.   pinMode(botao, INPUT);
  15.   pinMode(ledverde, OUTPUT);
  16.   pinMode(ledvermelho, OUTPUT);
  17.   pinMode(ledbranco, OUTPUT);
  18.   pinMode(buzzer, OUTPUT);

  19. }

  20. void loop()
  21. {
  22.   if (botaoPressionado())
  23.   {
  24.     som(10, 100);
  25.     if (ligado == LOW)
  26.       ligado = HIGH;
  27.     else
  28.     ligado == LOW;
  29.   }
  30.   if (ligado == LOW)
  31.   {
  32.     digitalWrite(ledvermelho, HIGH);
  33.     digitalWrite(ledverde, LOW);
  34.     digitalWrite(ledbranco, LOW);
  35.   }
  36.   else
  37.   {
  38.     digitalWrite(ledvermelho, LOW);
  39.     digitalWrite(ledverde, HIGH);
  40.     valoratualLDR = leLDR();
  41.     if (valoranteriorLDR != valoratualLDR)
  42.     {
  43.       valoranteriorLDR = valoratualLDR;
  44.       analogWrite(ledbranco, valoratualLDR);
  45.       som(2000, 5);
  46.     }
  47.   }
  48. }

  49. boolean botaoPressionado()
  50. {
  51.   int foiPressionado = LOW;
  52.   foiPressionado = digitalRead(botao);
  53.   delay(200);
  54.   return (foiPressionado == HIGH);
  55. }
  56. void som(int frequencia, int duracao)
  57. {
  58.   analogWrite(buzzer, frequencia);
  59.   delay(duracao);
  60.   analogWrite(buzzer, 0);
  61. }

  62. int leLDR()
  63. {
  64.   int i;
  65.   int auxLDR;
  66.   auxLDR = 0;
  67.   for (i = 0; i < 10; i++)
  68.     auxLDR += analogRead(A0);
  69.   auxLDR /= 10;

  70.   auxLDR = map(auxLDR, 0, 500, 0, 200);
  71.   if (auxLDR < 20) auxLDR = 0;
  72.   if (auxLDR > 200) auxLDR = 255;
  73.   return auxLDR;
  74. }

Projeto Montado e Funcionando