Hello
So for short I can receive command from an IR LED receiver, address and raw data (HEX and DEC). But I can’t send anything and when i try it does nothing (i can see the Led flashing throughout my Phone).
I would like to clone my Samsung remote.
Can you help me please ? thanks
Hello @terosque
Add a drawing of your project showing part numbers (for reference) and wiring. Also, add your sketch, pasting it using the < CODE > tag button. This helps in understanding your configuration.
(for example, see how Adafruit adds pictures and code in their project.)
thanks ! i don't commonly ask on forum lol
Those are from LAOMAO :
this are the wiring with 220 resistor ( there was not the same IR receiver diode so I put what was closest) :
and then the code for sending (that I get from SimpleSender) :
#include <Arduino.h>
#define DECODE_SAMSUNG
#define DISABLE_CODE_FOR_RECEIVER .
//#define SEND_PWM_BY_TIMER
//#define USE_NO_SEND_PWM
/*
* This include defines the actual pin number for pins like IR_RECEIVE_PIN, IR_SEND_PIN for many different boards and architectures
*/
#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp> // include the library
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
Serial.print(F("Send IR signals at pin "));
Serial.println(IR_SEND_PIN);
/*
* The IR library setup. That's all!
*/
// IrSender.begin();
IrSender.begin(DISABLE_LED_FEEDBACK);
}
uint8_t sCommand = 0x2;
uint8_t sRepeats = 4;
void loop() {
/*
* Print current send values
*/
Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(sCommand, HEX);
Serial.print(F(", repeats="));
Serial.print(sRepeats);
Serial.println();
Serial.println(F("Send standard NEC with 8 bit address"));
Serial.flush();
// Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits)
IrSender.sendSamsung(0xFD020707, sCommand, sRepeats);
/*
* Increment send values
*/
sCommand += 0x11;
sRepeats++;
// clip repeats at 4
if (sRepeats > 4) {
sRepeats = 4;
}
delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
}
the info of my remote are those one :
Protocol=Samsung Address=0x707 Command=0x2 Raw-Data=0xFD020707 32 bits LSB first
hope i don't miss something.
Is the Serial Monitor showing any output?
Yes it s showing pin output if it s what you mean ? (Otherwise, what it is ?)
Yes, that is it. Would you copy/paste that here?
I do not see a button pin defined, or a button condition being tested, for example...
#define buttonPin 5
int buttonPress;
setup() {
pinMode( buttonPin, INPUT_PULLUP );
}
loop() {
buttonPress = digitalRead( buttonPin ); // oops... wrote "analogRead" - my mistake
// debounce routine for the button press
if ( buttonPress = 0 ) { // LOW for buttonPress
// do irsend things
}
}
my mistake, i just upload the wrong code lol. this is the correct one :
Using library version 4.2.0
Send IR signals at pin 3
Also post the code you are using that shows contains the button press to initiate the irsend().
sure but it's a receive and send :
#include <Arduino.h>
#include "PinDefinitionsAndMore.h"
//#define DECODE_DENON // Includes Sharp
//#define DECODE_JVC
//#define DECODE_KASEIKYO
//#define DECODE_PANASONIC // alias for DECODE_KASEIKYO
//#define DECODE_LG
#define DECODE_NEC // Includes Apple and Onkyo
#define DECODE_SAMSUNG
//#define DECODE_SONY
//#define DECODE_RC5
//#define DECODE_RC6
//#define DECODE_BOSEWAVE
//#define DECODE_LEGO_PF
//#define DECODE_MAGIQUEST
//#define DECODE_WHYNTER
//#define DECODE_FAST
//
#if !defined(RAW_BUFFER_LENGTH)
# if RAMEND <= 0x4FF || RAMSIZE < 0x4FF
#define RAW_BUFFER_LENGTH 120
# elif RAMEND <= 0xAFF || RAMSIZE < 0xAFF // 0xAFF for LEONARDO
#define RAW_BUFFER_LENGTH 400 // 600 is too much here, because we have additional uint8_t rawCode[RAW_BUFFER_LENGTH];
# else
#define RAW_BUFFER_LENGTH 750
# endif
#endif
//#define EXCLUDE_UNIVERSAL_PROTOCOLS // Saves up to 1000 bytes program memory.
//#define EXCLUDE_EXOTIC_PROTOCOLS // saves around 650 bytes program memory if all other protocols are active
//#define NO_LED_FEEDBACK_CODE // saves 92 bytes program memory
//#define RECORD_GAP_MICROS 12000 // Default is 5000. Activate it for some LG air conditioner protocols
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
// MARK_EXCESS_MICROS is subtracted from all marks and added to all spaces before decoding,
// to compensate for the signal forming of different IR receiver modules. See also IRremote.hpp line 142.
#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules.
//#define DEBUG // Activate this for lots of lovely debug output from the decoders.
#include <IRremote.hpp>
int SEND_BUTTON_PIN = APPLICATION_PIN;
int DELAY_BETWEEN_REPEAT = 50;
// Storage for the recorded code
struct storedIRDataStruct {
IRData receivedIRData;
// extensions for sendRaw
uint8_t rawCode[RAW_BUFFER_LENGTH]; // The durations if raw
uint8_t rawCodeLength; // The length of the code
} sStoredIRData;
bool sSendButtonWasActive;
void storeCode();
void sendCode(storedIRDataStruct *aIRDataToSend);
void setup() {
pinMode(SEND_BUTTON_PIN, INPUT_PULLUP);
Serial.begin(115200);
#if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/|| defined(USBCON) /*STM32_stm32*/|| defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
delay(4000); // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
#endif
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
Serial.print(F("Ready to receive IR signals of protocols: "));
printActiveIRProtocols(&Serial);
Serial.println(F("at pin " STR(IR_RECEIVE_PIN)));
IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
Serial.print(F("Ready to send IR signals at pin " STR(IR_SEND_PIN) " on press of button at pin "));
Serial.println(SEND_BUTTON_PIN);
}
void loop() {
// If button pressed, send the code.
bool tSendButtonIsActive = (digitalRead(SEND_BUTTON_PIN) == LOW); // Button pin is active LOW
/*
* Check for current button state
*/
if (tSendButtonIsActive) {
if (!sSendButtonWasActive) {
Serial.println(F("Stop receiving"));
IrReceiver.stop();
}
/*
* Button pressed -> send stored data
*/
Serial.print(F("Button pressed, now sending "));
if (sSendButtonWasActive == tSendButtonIsActive) {
Serial.print(F("repeat "));
sStoredIRData.receivedIRData.flags = IRDATA_FLAGS_IS_REPEAT;
} else {
sStoredIRData.receivedIRData.flags = IRDATA_FLAGS_EMPTY;
}
Serial.flush(); // To avoid disturbing the software PWM generation by serial output interrupts
sendCode(&sStoredIRData);
delay(DELAY_BETWEEN_REPEAT); // Wait a bit between retransmissions
} else if (sSendButtonWasActive) {
/*
* Button is just released -> activate receiving
*/
// Restart receiver
Serial.println(F("Button released -> start receiving"));
IrReceiver.start();
} else if (IrReceiver.decode()) {
/*
* Button is not pressed and data available -> store received data and resume
*/
storeCode();
IrReceiver.resume(); // resume receiver
}
sSendButtonWasActive = tSendButtonIsActive;
delay(100);
}
// Stores the code for later playback in sStoredIRData
// Most of this code is just logging
void storeCode() {
if (IrReceiver.decodedIRData.rawDataPtr->rawlen < 4) {
Serial.print(F("Ignore data with rawlen="));
Serial.println(IrReceiver.decodedIRData.rawDataPtr->rawlen);
return;
}
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_REPEAT) {
Serial.println(F("Ignore repeat"));
return;
}
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_IS_AUTO_REPEAT) {
Serial.println(F("Ignore autorepeat"));
return;
}
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_PARITY_FAILED) {
Serial.println(F("Ignore parity error"));
return;
}
/*
* Copy decoded data
*/
sStoredIRData.receivedIRData = IrReceiver.decodedIRData;
if (sStoredIRData.receivedIRData.protocol == UNKNOWN) {
Serial.print(F("Received unknown code and store "));
Serial.print(IrReceiver.decodedIRData.rawDataPtr->rawlen - 1);
Serial.println(F(" timing entries as raw "));
IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format
sStoredIRData.rawCodeLength = IrReceiver.decodedIRData.rawDataPtr->rawlen - 1;
/*
* Store the current raw data in a dedicated array for later usage
*/
IrReceiver.compensateAndStoreIRResultInArray(sStoredIRData.rawCode);
} else {
IrReceiver.printIRResultShort(&Serial);
IrReceiver.printIRSendUsage(&Serial);
sStoredIRData.receivedIRData.flags = 0; // clear flags -esp. repeat- for later sending
Serial.println();
}
}
void sendCode(storedIRDataStruct *aIRDataToSend) {
if (aIRDataToSend->receivedIRData.protocol == UNKNOWN /* i.e. raw */) {
// Assume 38 KHz
IrSender.sendRaw(aIRDataToSend->rawCode, aIRDataToSend->rawCodeLength, 38);
Serial.print(F("raw "));
Serial.print(aIRDataToSend->rawCodeLength);
Serial.println(F(" marks or spaces"));
} else {
/*
* Use the write function, which does the switch for different protocols
*/
IrSender.write(&aIRDataToSend->receivedIRData);
printIRResultShort(&Serial, &aIRDataToSend->receivedIRData, false);
}
}
If you did not see any of the following Serial.print() lines in the Serial Monitor, then I suspect the button wiring.
the button is correct because he send something like when i pushed the button in the Monitor there is :
Ignore data with rawlen=2
Stop receiving
Button pressed, now sending raw 3 marks or spaces
Button released -> start receiving
Received unknown code and store 5 timing entries as raw
rawData[6]:
-2356600
+ 100,-1100
+ 200,-2250 + 300
Sum: 3950
Ignore data with rawlen=2
Ignore data with rawlen=2
Ignore data with rawlen=2
Ignore data with rawlen=2
Received unknown code and store 31 timing entries as raw
rawData[32]:
-141750
+ 250,-4250
+ 650,- 450 + 150,-1300 + 200,- 100 + 200,- 150
+ 150,-1350 + 150,-1450 + 150,-3950 + 150,-4000
+ 250,-1200 + 150,-4500 + 250,- 850 + 150,- 600
+ 150,-2700 + 200,-1050 + 150
Sum: 31250
Received unknown code and store 7 timing entries as raw
rawData[8]:
-15000
+ 300,-1100
+ 100,- 950 + 200,- 150 + 150
Sum: 2950
Ignore data with rawlen=2
Ignore data with rawlen=2
Ignore data with rawlen=2
Ignore data with rawlen=2
Stop receiving
Button pressed, now sending raw 7 marks or spaces
Button pressed, now sending repeat raw 7 marks or spaces
Button released -> start receiving
Stop receiving
Button pressed, now sending raw 7 marks or spaces
Button released -> start receiving
Stop receiving
i think sometime it receive and sometime not
I see, the button works. It looks like the code sends and receives (its own send?). Is the problem bad data?
I can't say if it comes from bad data, I think it's correct. but by data what do you mean? hexadecimal, raw-data? and it receives a data and send this same data for your question
This answers my question.
also did you try to test the code with wiring and led IR ? for a better resolve of the potential issue ?
I thought this was the problem, but it seems you receive what you send, or are you using a another device to send?
I can send something but it don t do anything, like i say i can see the light of the ir led with the phone working. Maybe the data who is send is incorrect ?
A resistance of 220 ohms seems high to me. I suggest you try with a much lower resistance, and since the pin of the microcontroller cannot provide a large current, you will have to add a transistor - for example SI2300.
https://www.mouser.com/datasheet/2/143/EAILP05RDDB1-708504.pdf
The typical operating current of such LEDs is 100mA.
Thanks and so which resistance are you suggesting me ? 10 or 100 ? And also the transistors i have are :
NPN S8050 and NPN PN2222 which you would provide me ?