int incomingByte = 0; // variable pour lecture de l'octet entrant
void setup() {
Serial.begin(9600); // ouvre le port série et fixe le débit à 9600 bauds
}
void loop() {
// envoie une donnée sur le port série seulement quand reçoit une donnée
if (Serial.available() > 0) { // si données disponibles sur le port série
// lit l'octet entrant
incomingByte = Serial.read();
// renvoie l'octet reçu
Serial.print("Octet reçu: ");
Serial.println(incomingByte, DEC);
}
}
/* Example program for from IRLib – an Arduino library for infrared encoding and decoding
* Version 1.3 January 2014
* Copyright 2014 by Chris Young http://cyborg5.com
* Based on original example sketch for IRremote library
* Version 0.11 September, 2009
* Copyright 2009 Ken Shirriff
* http://www.righto.com/
*/
#include <IRLib.h>
IRsend My_Sender;
//Create a receiver object to listen on pin 11
IRrecv My_Receiver(11);
IRdecode My_Decoder;
int incomingByte = 0;
void setup()
{
Serial.begin(9600);
My_Receiver.enableIRIn(); // Start the receiver
}
void loop() {
// Serial.println(Serial.read());
if (Serial.read() != -1) {
//send a code every time a character is received from the serial port
//Sony DVD power A8BCA
// My_Sender.send(SONY,0xa8bca, 20);
My_Sender.send(SONY,0xA8B5F, 20);
Serial.print("send");
delay(10000);
}
if (My_Receiver.GetResults(&My_Decoder)) {
My_Decoder.decode(); //Decode the data
My_Decoder.DumpResults(); //Show the results on serial monitor
My_Receiver.resume(); //Restart the receiver
}
}
If this works on the serial monitor, and doesn't work when you attempt to serial read form your IR, then the problem is not in the reading code but in the setup of the IR.
The behaviour that you are getting is that the Serial object never contains any bytes for you to read. One possible thing - for instance - that can cause this behaviour is if your IR transmitter doesn't have any batteries in it.