arduinoetInfrarouge

image principale arduinoetInfrarouge

Difficulté:

Dans ce petit tuto on va apprendre a décoder un signal infrarouge de une télécomande .

Matériel :

Budget : Non défini

Etape 1 : Les étapes

étape 2 : La Lumière infrarouge

étape 3 : Le récepteur ir

étape 4 : le code /library

étape 5 : les protocoles 


Etape 2 : La lumière infrarouge

Le rayonnement infrarouge  est une lumière  de longueur d'onde supérieure à celle du du spectre                                                                                visible .

Elle n'est pas visible par l œil humain .Mais a l aide d une caméra on peut l'apperçevoire .(comme sur la photo).

On s en sert notamment dans les télécommandes pour commander les tv .


Etape 3 : Le récepteur ir

Le récepteurs possède 3 patte 2 pour l alimentation 5/3.3v et la dernière pour la réception des                                     donnée .On peut dire que ce composant est un circuit integrés car a l'interrieur de boitier on

retrouve un phototransistore et un transistors .Voir schéma  .

Etape 4 : recevoir un message ir

Pour le code on a juste besoin de installer la library IrRemote sur l IDE de ardunio . 

Une fois installer il suffit d'ouvrir l'exemple IRevDump2. Puis ouvrez le port Serie 




Soit copier coller ce code :


//------------------------------------------------------------------------------
// Include the IRremote library header
//
#include <IRremote.h>

//------------------------------------------------------------------------------
// Tell IRremote which Arduino pin is connected to the IR Receiver (TSOP4838)
//
int recvPin = 11;
IRrecv irrecv(recvPin);

//+=============================================================================
// Configure the Arduino
//
void  setup ( )
{
Serial.begin(9600);   // Status message will be sent to PC at 9600 baud
irrecv.enableIRIn();  // Start the receiver
}

//+=============================================================================
// Display IR code
//
void  ircode (decode_results *results)
{
// Panasonic has an Address
if (results->decode_type == PANASONIC) {
Serial.print(results->address, HEX);
Serial.print(":");
}

// Print Code
Serial.print(results->value, HEX);
}

//+=============================================================================
// Display encoding type
//
void  encoding (decode_results *results)
{
switch (results->decode_type) {
default:
case UNKNOWN:      Serial.print("UNKNOWN");       break ;
case NEC:          Serial.print("NEC");           break ;
case SONY:         Serial.print("SONY");          break ;
case RC5:          Serial.print("RC5");           break ;
case RC6:          Serial.print("RC6");           break ;
case DISH:         Serial.print("DISH");          break ;
case SHARP:        Serial.print("SHARP");         break ;
case JVC:          Serial.print("JVC");           break ;
case SANYO:        Serial.print("SANYO");         break ;
case MITSUBISHI:   Serial.print("MITSUBISHI");    break ;
case SAMSUNG:      Serial.print("SAMSUNG");       break ;
case LG:           Serial.print("LG");            break ;
case WHYNTER:      Serial.print("WHYNTER");       break ;
case AIWA_RC_T501: Serial.print("AIWA_RC_T501");  break ;
case PANASONIC:    Serial.print("PANASONIC");     break ;
case DENON:        Serial.print("Denon");         break ;
}
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpInfo (decode_results *results)
{
// Check if the buffer overflowed
if (results->overflow) {
Serial.println("IR code too long. Edit IRremoteInt.h and increase RAWBUF");
return;
}

// Show Encoding standard
Serial.print("Encoding  : ");
encoding(results);
Serial.println("");

// Show Code & length
Serial.print("Code      : ");
ircode(results);
Serial.print(" (");
Serial.print(results->bits, DEC);
Serial.println(" bits)");
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpRaw (decode_results *results)
{
// Print Raw data
Serial.print("Timing[");
Serial.print(results->rawlen-1, DEC);
Serial.println("]: ");

for (int i = 1;  i < results->rawlen;  i++) {
unsigned long  x = results->rawbuf[i] * USECPERTICK;
if (!(i & 1)) {  // even
Serial.print("-");
if (x < 1000)  Serial.print(" ") ;
if (x < 100)   Serial.print(" ") ;
Serial.print(x, DEC);
} else {  // odd
Serial.print("     ");
Serial.print("+");
if (x < 1000)  Serial.print(" ") ;
if (x < 100)   Serial.print(" ") ;
Serial.print(x, DEC);
if (i < results->rawlen-1) Serial.print(", "); //',' not needed for last one
}
if (!(i % 8))  Serial.println("");
}
Serial.println("");                    // Newline
}

//+=============================================================================
// Dump out the decode_results structure.
//
void  dumpCode (decode_results *results)
{
// Start declaration
Serial.print("unsigned int  ");          // variable type
Serial.print("rawData[");                // array name
Serial.print(results->rawlen - 1, DEC);  // array size
Serial.print("] = {");                   // Start declaration

// Dump data
for (int i = 1;  i < results->rawlen;  i++) {
Serial.print(results->rawbuf[i] * USECPERTICK, DEC);
if ( i < results->rawlen-1 ) Serial.print(","); // ',' not needed on last one
if (!(i & 1))  Serial.print(" ");
}

// End declaration
Serial.print("};");  //

// Comment
Serial.print("  // ");
encoding(results);
Serial.print(" ");
ircode(results);

// Newline
Serial.println("");

// Now dump "known" codes
if (results->decode_type != UNKNOWN) {

// Some protocols have an address
if (results->decode_type == PANASONIC) {
Serial.print("unsigned int  addr = 0x");
Serial.print(results->address, HEX);
Serial.println(";");
}

// All protocols have data
Serial.print("unsigned int  data = 0x");
Serial.print(results->value, HEX);
Serial.println(";");
}
}

//+=============================================================================
// The repeating section of the code
//
void  loop ( )
{
decode_results  results;        // Somewhere to store the results

if (irrecv.decode(&results)) {  // Grab an IR code
dumpInfo(&results);           // Output the results
dumpRaw(&results);            // Output the results in RAW format
dumpCode(&results);           // Output the results as source code
Serial.println("");           // Blank line between entries
irrecv.resume();              // Prepare for the next value
}
}

Etape 5 :

il faut savoir que les signale envoyé par vos télécommande sont soumis a un protocole 

il y en a plusieurs : 

le protocole NEC //utiliser par exemple dans les télécommande de box 

le protocole SONY //Utiliser dans tous les appareil Sony 

le protocole RC5  :) 

le protocole RC6

le protocole DISH

le protocole SHARP

le protocole JVC

le protocole SANYO

le protocole MITSUBISHI

le protocole SAMSUNG //utiliser dans les produit samsung

 et le protocole LG //Utilser dans les produit LG 

bonjour,

je suis novice dans la programmation voir ignorant. auriez vous un schémas de ce montage.

merci par avance

Guytou

Ces tutoriels devraient vous plaire

vignette Comment fabriquer son filament pour imprimante 3D
Comment fabriquer son filament pour imprimante 3D
vignette Connecter un  écran LCD en I2C
Connecter un écran LCD en I2C
vignette fabrication de circuits imprimés facile
fabrication de circuits imprimés facile

Découvrez tous les tutoriels partagés sur Oui Are Makers

Powered by Oui Are Makers