Redefinition still suggests that you have another setup() function somewhere. However, I see a missing semi-colon at the end of the Serial.print line that I recommended. Don’t forget to terminate your lines/commands. For ease, you should try attaching your entire code sample or put it somewhere online like github/pastebin/dropbox, etc. for ease.
heres my whole sketch, i removed the void setup part because there was one function already at the top like you suggested and it works. the only thing is when opening the serial monitor im seeing test-108994 numbers scrolling continuously. I try to use the remote and see if it picks up the code for power but doesnt show
/*
* IRremoteESP8266: IRrecvDumpV2 - dump details of IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 Sept, 2015
* Based on Ken Shirriff's IrsendDemo Version 0.1 July, 2009, Copyright 2009 Ken Shirriff, http://arcfn.com
*/
#include <IRremoteESP8266.h>
int RECV_PIN = 2; //an IR detector/demodulator is connected to GPIO pin 2
IRrecv irrecv(RECV_PIN);
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->panasonicAddress, 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 ;
}
}
//+=============================================================================
// Dump out the decode_results structure.
//
void dumpInfo (decode_results *results)
{
// 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->panasonicAddress, 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 ( )
{
// AT THE TOP OF THE LOOP ADD YOUR DEBUG TRACES
Serial.print("test-"); Serial.println(millis())
;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
}
}
disregard i got it dumping code now, just commented out the Serial.print(“test-”); Serial.println(millis())… i will update this code to your sketch and see if it all works. thanks so far for all your help
Anyone know how I can successfully add volume up and volume down buttons on the device handler? as of now I have the sample that JZst created which has the on, off, tv input, previous, mute buttons.
Grab from GitHub again… check the changes using WinMerge or KDiff3 (or even the built-in diff highligher of GitHub) to see the code differences. If you want to see and learn that’s probably the best way. Took about 15 minutes to do due to the renaming and a bit of trial & error (forgot new command definitions at top of script).
@Raymond_Lopez download again if you want channel controls as well.
Are you able to tell Alexa to increase/decrease volume? If so, I might need to revisit my installation.
Yes, for a while… however, need to set up ANOTHER device handler that provide on GitHub just called TVvolume.groovy — and have same settings as the other TV device. Then you call it something like “TV Volume” then you can say “Alexa turn on the TV volume” and it will increase volume by one. I do it all the time — but it cannot be done on the same device handler considering that ON/OFF is reserved for TV on/off.
Alexa recognizes on/off and scale value like 0-100 and nothing else out of the box. So obviously all of this is a workaround but it works w/o issues for me.
I updated only the NodeMCU sketches to fix IR issues. New IRremoteESP8266 library seems to be broken and does not sendNEC so I had to switch to sendRaw.
I also added uptime to show how long device has been up because mine has lately been rebooting like crazy probably because I’m under-powering it with long extension cable. I also switched to D1 Mini clone from NodeMCU to see if the rebooting stops.
Lastly, I added OTA but it’s buggy as hell. I can’t seem to make it work. Has something to do with these three libraries being loaded at the same time: ESP8266WiFi, ESP8266WebServer & ESP8266HTTPUpdateServer. Whoever can figure it gets a gold star. I probably could have made it work if I re-wrote the project to be just like my relay/garage switch project but I’m not that in need of getting OTA working.
I have the NodeMCU code working and am able to issue commands through both the web interface and SmartThings. Only problem is that my TV is not responding (not a range issue since I have it right next to the IR receiver on the TV). None of the commands work on the TV. When I replace the TSAL6400s with LEDs, I do see them light up for all the default commands in the code.
I am assuming the IR codes in the .ino file are not correct for my TV (Samsung UN55C8000, 2010 model).
I want some confirmation of this suspiscion and some guidance on how to go ahead replacing the IR raw codes in the .ino file. Incidentally, http://irdb.tk/codes/ shows no raw codes for Samsung TVs.
New to IR codes, any help is appreciated. Thanks.
Edit: My problem described above is resolved, just needed the correct IR codes for my TV.
Samsung TV IR codes are available at: http://arduinostuff.blogspot.com/2011/06/samsung-remote-ir-codes.html and http://www.remotecentral.com/cgi-bin/codes/samsung/tv_functions/
The codes for my Monoprice HDMI switch (MD-415ARC) were available at: http://www.remotecentral.com/cgi-bin/mboard/rc-discrete/thread.cgi?7384
(I still DO NOT have the IR raw code for the ARC button on the remote though …)
A very useful tutorial for people with some signal processing knowledge (also shows how to convert HEX values to raw codes): http://cdn.alphak.net/dl/InfraredProtocolPrimer.pdf
IR codes for Roomba: https://gist.github.com/probonopd/5181021
Confirmed… it’s for an LG. BTW, there’s now a bug with the library and sendNEC — which is the IR standard that most remotes/devices use. You now have to sendRaw instead like the below. However, when I first did it with the original increments of like 550 600 1600 1650 1700 — it simply failed with one particular HDMI switch device. However, using the below, notice the endings, seemed to work great. Looks like the IR receive sample does the 50 unit increments but the below are the values you really should be using: Here’s how I figured that little piece out, just looking at examples.
unsigned int hdmi1[67] = {9024,4512, 564,564, 564,564, 564,564, 564,564, 564,564, 564,564, 564,564, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564,564, 564,564, 564,1692, 564,564, 564,564, 564,564, 564,564, 564,564, 564,564, 564,1692, 564,564, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564,1692, 564}; // NEC 1FE40BF
irsend.sendRaw(hdmi1, 67, 38);
@JZst Can the 5V power supply be taken from the NodeMCU’s Vin (NodeMCU itself powered by microUSB)?
I got this to work but wondering if there are issues with the 5V voltage regulation.
5V pin of NodeMCU should be directly connected (with a diode) to 5V of USB port, afaik there is no regulation for 5V on NodeMCU board.
BTW I recommend using NPN transistor to drive 3 IR Led in series from 5V (remember most IR LEDs have 1.6V forward voltage, not around 3V like standard LEDs). I don’t recommend driving the IR LEDs directly since they can draw quite large amount of current (normal TV remotes push up to 2A through them when transmitting) and you risk burning out your GPIO.
Since I built similar project on Wemos D1 Mini board I thought I’ll chime in with possibly useful info regarding Samsung TVs.
Few useful codes: (note separate on and off codes - very useful for automation)
unsigned int irTVon[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564};
unsigned int irTVoff[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564};
unsigned int irTVhdmi1[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564};
unsigned int irTVhdmi2[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564};
unsigned int irTVhdmi3[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564};
unsigned int irTVhdmi4[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564};
unsigned int irTVvolUp[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564};
unsigned int irTVvolDown[] = {4512, 4512, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692, 564, 1692, 564, 1692, 564};
Also if you want to simulate holding the key down use 60ms delay between commands. If you want fast single presses use > 120ms delay between commands (I use 125ms).
You’ll find basically all useful IR codes for Samsung TVs in this thread: http://www.remotecentral.com/cgi-bin/mboard/rc-discrete/thread.cgi?5780
To convert them from NEC format or the hex format in this thread to timings for RAW command use: IrScrutinizer (it will generate for you timinigs with +/- signs - just remove those signs for RAW command). To learn how to use this tool read the documentation
Wow, thanks for the Samsung code list, comprehensive and very useful.
Only wish the raw codes were also provided to avoid the conversion
For the 5V question, what I meant was whether one can connect the microUSB to the NodeMCU and then use the Vin as 5V Vout to power the LED path.
[quote=“kmugh, post:59, topic:50161”]
what I meant was whether one can connect the microUSB to the NodeMCU and then use the Vin as 5V Vout to power the LED path.
[/quote]Yes, you should be able to. There are some NodeMCU clones that isolate VIN from USB but they provide separate VU pin for USB Voltage if that is the case.
Agreed, all depends on the board. Grab a multi-meter and test to be sure. @ClassicGOD thanks for the VU tip in case encountering a board like that!
New code released. I merged my Dev branch. It has support for IRLib 2.0 that was released. The authors of that library granted the “reverse signal” feature (where you send ground/LOW vs. positive/HIGH signal to the pin). Which means I no longer have to maintain my own IRLib release and you can easily change the “sendGround” variable at the top of the file. I also cleaned up folders and wiring diagrams.
I had this done for about a month but waiting for IRLib 2.0 release, me testing for a while, and the 15 minutes I needed today to merge.
Enjoy!
Hi All…
It’s me again… like a broken record …( Old School )
If anyone has an Arduino ThingShield available for sale, please let me know
still looking for a couple units.
Thanks
Ben
I have a Samsung Soundbar on top of my Refrigerator that is used for playing sound from either a PC (optical) or an Echo or Fire Tablet (Bluetooth).
It has auto off and the optical connection will turn it on after receiving sound but if it’s on Bluetooth then you have to turn it on with the remote.
I am guessing I could use this implementation to send an IR command to switch inputs and/or turn on?
Is there a parts list?
Thoroughly read the first post. A NodeMCU or a Wemos D1 Mini will suffice. I also state the exact TSAL IR Led models that are used. The pictures give away that notion of how few parts are needed. You’ll also need the IE receiver module so that you can first read in the IR signal from the remote and use that in the source code for sending the correct IR sequence. Lastly, see @Casper’s post that I link to in the OP to get you started with reading the sending IR in general.