making a simple IR transmitter - Page 1
Forum section: electronics / general

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 05:35:17 am
content: I want to make a simple IR transmitter to control something controlled by a small Chinese typical remote. I have something to sample the signal.I have come up with some strategies so far and I wonder what the issues could be1) Energizing a IR led with a headphone jack. There are IR blasters. They are usually wired 2 leds in opposite direction. I think in some cases frequency filters and transformers are maybe a barrier to arbitrary square waveforms. So maybe they are going back and forth at a high frequency to mimic a solid 1 for example with 0 drop outs.2) Gating an externally powered flip flop by like a shmitt trigger of the above signal.3) Using a USB serial bridge to energize the LED if like you can freely and quickly alter the RTS or CTS.4) Using a USB serial source signal to bias a flip flop discarding the start bit.5) Get a raspberry pi and tie the led across a GPIO6) Find some cheap usb device who's led can be set by software and resolder a IR led to.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 06:56:23 am
content: I have something I think is a emitter on a 3.5 mm headphone jack I found. It is a clear led in a small reddish case. When I use the diode test on a DMM, it lights up visible red. Does this mean it is a receiver, or does it mean the power is too great?

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 05:25:24 pm
content: Looking around here I recalled I have a remote scrapped, and also I have a devkit I got for free off the internet, so I am thinking hopefully I can solder, or use a jumper header, a IR led over the end and maybe have to add a resistor if it is like 5V. I should be able to program it to, by usb, turn the led off and on. This is what it is regarding, and at this time I am looking to make a high speed color dithering thing between color steps:

author: MosherIV
author_rank: Super Contributor
timestamp: October 28, 2020, 06:05:55 pm
content: That looks like a debugger for a low end micro.They normally talk with SWD to a micro.They have a micro in them programmed to be some kind of usb device type, usually HID and then use that device to transfer the SWD data stream to the target micro.Yes, you can re-program it to do what you want but it is a LOT of effort.Check out this threadhttps://www.eevblog.com/forum/testgear/fluke-187-making-an-ir-cable/You might be better off buying CH340 or CP2102 which are usb to serial converters and just interface to the tx pin. Both the Fluke adapter and Keysight/Aglient adapter are just USB serial chips

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 06:09:19 pm
content: Thanks for you comment. I'll consider it. Got a week to burn or so, so I don't know. I just downloaded SDCC and it supports the 8051, but there is a learning curve, and I hope it works in the end. It has to make the timings also. Not sure

author: DrG
author_rank: Super Contributor
timestamp: October 28, 2020, 06:09:50 pm
content: Quote from: msuffidy on October 28, 2020, 05:35:17 amI did a project where I wanted to increase/decrease the volume on a TV by a set number of steps.I used a Linkit 7697 and this simple circuit:IR LED operates from GPIO_P3 with a 1k resistor to the base of a 2N4401 andan 82 ohm resistor driving a LED 55b IR LED (3.3V, ~40mA, .013 W)Programming the hard stuff was made easy thanks to some good work in the form of:Raw codes were initially read using IRrepeater.inohttps://github.com/smallbeetw/arduinosketch/blob/master/IRrepeator/IRrepeator.inoand the values were smoothed to 560/1690/4500/9000 to make this code dataSpitting the codes back out used IRremote library which is included in the Linkit software but is something of a standard Arduino library seehttps://www.arduinolibraries.info/libraries/i-rremote.The whole project was pretty easy and works well. I didn't have a need for a great distance, but if I did, I would go toward cannibalizing one of the many old remotes still hanging around long after their devices have gone away.I also used a simple Promini 3v3 but went to the Linkit for BLE capabilities which was part of the project.Hope it helps.

author: madires
author_rank: Super Contributor
timestamp: October 28, 2020, 06:26:40 pm
content: Most oft the cheap remote controls are using the NEC IR protocol. And don't forget that the IR signal has usually a carrier frequency of 38 kHz.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 06:30:10 pm
content: Really good to know about a 'carrier' . Have to check that out.Oh I think you mean like the square PCM carrier which yes you can see in the capture. That is what you see is like a regular on with a single or double gap.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 28, 2020, 09:21:16 pm
content: ((I used a Linkit 7697 and this simple circuit:))Well I guess you would do this to avoid a drain on the GPIO? It is a bit more complex than I was thinking about.

author: DrG
author_rank: Super Contributor
timestamp: October 28, 2020, 09:39:41 pm
content: Quote from: msuffidy on October 28, 2020, 09:21:16 pmFor that SOC , the drive strength of the GPIO is programmable (but I never messed with that) but no more than 16mA. Off hand, I don't know of any GPIOs on the chips that I have any experience programming that can source or sink more than 25mA (not that they might not exist).I think that if you try to get more current out of one, it will drop the voltage and/or damage the chip (that is only my guess) and at my level, I strive to avoid such situationsOn the other hand, if you want to get some distance on the remote, you want more current to the LED(s) than can be provided by the GPIO. It only adds a couple of inexpensive components.

author: DrG
author_rank: Super Contributor
timestamp: October 28, 2020, 10:17:21 pm
content: Quote from: msuffidy on October 28, 2020, 09:21:16 pmWell maybe not as complicated as you might think. I could not see your remote very well in the video, but the ones that I have seen look something like this one:https://www.amazon.com/SUPERNIGHT-Controller-Compatible-Assistant-Working/dp/B08HVVRPBH/ref=sr_1_20?dchild=1&keywords=IF+Rgb+Controller&qid=1603921702&sr=8-20Basically, there are three LEDs, R, G, B and using PWM you vary the duty cycle of each - that can get you to a mess of colors. So, you need to find the codes for selecting R/G/B and then the ones that bump the duty cycle up or down (likely brightness +/-).So, if one color isBR=70%, Green=20% and B=50% and you change the PWM duty cycle on blue - by sending the command to increase brightness (duty cycle). It is probably the case that each brightness command increases/decreases duty cycle by a set amount - say 10%, so you would need to track that and provide multiple commands.Going to preset colors is the same thing, but easier. You could go to duty cycle=0 for all three and then step them up to their presets.The whole issue of color mixing with LEDs is fascinating. Some years ago (probably 10) I heard about PWM and a little PIC chip (12F1572) that had three 16 bit, PWM registers and I spent a ton of time learning with that chip. I made a "party light" ooooooahhhhh using just that chip and a couple of batteries and a step up. It goes through Roy G. Biv and some other "scripts". Works great, BUT mixing colors smoothly - going from orange to indigo for example is not trivial and there can be more math than my aged neurons can entertain...still it works and I think you should play around with your set up - you have the vision already, now you just need the code and parts to cooperate.Of course I could be all wrong about this

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 29, 2020, 04:32:05 am
content: I harvested a IR led that is seen by the sensor that also saw the remote for the lights. I can see it using only the reverse cam of my iphone. I hooked it directly to an AAA battery, which is maybe not a great idea to see if it worked but also the sensor got random trash as it connected/disconnected it. What I am expecting to see is this light thing, which I got for $6 Canadian is probably just going to have codes for like 12 colors. It seems I can switch pretty fast between them so I can make fast switching transitions, kind of pwm, but they may become stroboscopic. I am reviewing the 8051 dongle to see what the pins are exactly. I am not sure any of these pins can be used as a GPIO if this is the correct diagram. I suppose I could recalculate powering it from the 5V rail. I don't know what the source amperages are, I guess I could measure them first. I should be going for 1.2 V on the IR led and 20mA? If things work out I would run a small ribbon cable from the pinout to a small network of soldered components, and probably incase them all in a glue gun blob.I also have a Renesas M16C thing that appears to have GPIO headers. Maybe this one is OK, I think the diagram is not the right one. Now I am unsure if I can actively send it USB comm after using the USB to program it. I was going to send it a transmit frame at a time through USB.

author: Peabody
author_rank: Super Contributor
timestamp: October 29, 2020, 02:42:54 pm
content: Here's info about the NEC IR protocol:https://techdocs.altium.com/display/FPGA/NEC+Infrared+Transmission+ProtocolAll IR remotes use a carrier so they can't be triggered by ambient light, even direct sunlight. The NEC protocol is the most widely used, but manufacturers can use their own system.If you want to mess with an Arduino, they have an IRremote library that does most of the code for you. It will even capture what the Chinese remote is sending if you have an IR photodiode sensor. Or you may find that your IR LED can be used as a weak sensor. But you can also probably capture the pattern on your scope if you connect the probe to the the LED driving pin of the Chinese remote.Also, don't forget about one of the few free lunches in electronics. If you have enough voltage on the rail, you can drive two IR LEDs in series after adjusting the resistor value. Instead of dropping half the power in the resistor as heat, you use that power to generate twice as much IR. Same total current.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 29, 2020, 03:28:14 pm
content: I agree the Arduino solution would be the easiest, just I want to do this buying $0 of new equipment. I suspect it can be done. It is pretty straightforward to just sample the signals and send individual ones. Decomposing and generating them is another problem.Actually I have been thinking about the problem and what would be just the easiest thing to do without really knowing what is involved is say like output has an address or some other API call and the usb bridge thing may have a chip address. Just keep polling the input character for say 0 or 01 and set the output led. Then the computer can send a constant stream of 1 or 0s through the usb and use the devkit dongle as a led switch. It may be more like static like it is usually 00 but if it is 01 or 02 for example you could set it 1 or 0. Nope this may be a job for getchar() of fgetc().Does this mean the GPIOs are 15mA?I have 2 of these transistors from a CFL light here. Are they too far from the 5V range? I am thinking they will work.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 31, 2020, 07:54:21 am
content: I had 2 usb devkits. The Renesas one right away looks like the programmer is USB and otherwise there is no communication with the computer. The other one, the Uscale X800 looks like you can program the chips, and also there is a serial uart line open to the host. The big problem is if you are not using the windows devel software I am not sure the program runs on startup or not. There are 3 different controllers sharing the same pin header, and I don't specifically know how this all works unless the devel software is controlling them all by JTAG before they start.The uscale xc800 has a JTAG unit and a serial unit. It may be possible to just write address into the microcontrollers to set GPIO without them even properly running using JTAG. Or if may be possible to get them running using JTAG from linux.

author: madires
author_rank: Super Contributor
timestamp: October 31, 2020, 10:25:03 am
content: Quote from: msuffidy on October 29, 2020, 03:28:14 pmThose are meant to switch high voltages and have a low hFE. Use a jelly bean NPN, like 2N2222 or BC547.

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 31, 2020, 11:04:31 am
content: Thanks. I do have a lot of scrap I can review. I still think this is like I have the dongle. I have to get the JTAG thing working. Connect the dongle to a resistor and the led. Probably work. I mean sorry, I think it is 15mA gpio, so I think I can use it?

author: madires
author_rank: Super Contributor
timestamp: October 31, 2020, 11:41:14 am
content: It should work, but it won't give you much range. Many IR LEDs are rated for 100mA (as long as they stay cool).

author: msuffidy
author_rank: Frequent Contributor
timestamp: October 31, 2020, 08:10:09 pm
content: I am starting to feel like I am bothering this group much, but the uscale xc800 is not looking promising. This is because it does not simply start up outside of its windows IDE as I want to use linux. Getting it to a starting manner requires undocumented JTAG calls to the micros or a analog multiplex switcher on board. I am now reviewing getting an arduino atmega 328p for $10 in town someone is selling, or programming the Renesas devkit to trigger on a signal to its pin header GPIO in, or uart, and then turning on a GPIO out. So like a signal control switch. I am not sure what state the micros start up in with the uscale, and I am not sure if any standard source can translate into a JTAG device address access tool.

author: MosherIV
author_rank: Super Contributor
timestamp: October 31, 2020, 09:47:09 pm
content: No bother.I did warn you that trying to re-purpose debuggers would be a lot of work.Do yourself a favour, just buy a regular usb to serial adapter, preferably a well supported one like CH340 or CP2102, and then you can just use the Tx output to drive IR LED.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 01, 2020, 03:59:22 am
content: I just picked up 2 arduinos one was totally sealed so I am hoping one will do it.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 02, 2020, 03:35:47 am
content: I wasn't actually expecting to get this far today, but I potentially got the arduino code part done. It is kind of hard to tell. It is set up to light up the onboard led, which is maybe the same as one of the board headers. But the idea is what I decided to do was make it so I would upload the sample set and then it would execute it at a regular rate specified by the upload. So here is my source and a copy of the test sample. I have not hooked it to the IR led yet.

author: ledtester
author_rank: Super Contributor
timestamp: November 02, 2020, 04:01:12 am
content: Just a couple of coding tips...Intransmit_iryou can simply write:Code:digitalWrite(LED_BUILTIN, sample_array);and this code handles both cases.Forboolvariables C++ has the predefined constantstrueandfalse. You can also use 1 and 0, but it makes it more obvious that you are setting a boolean value.You can also just writeif (loadstate) { ... }- there's no need to compare it to a true value.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 02, 2020, 06:00:55 am
content: Yes I guess those are good points. I made an assumption about the code I snipped in that it was waiting for serial to be ok before getting a char. It just skipped over it if it wasn't. Now it seems to work great because I wait for it. Oh I tried TRUE and FALSE and maybe it wanted the lower case ones.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 02, 2020, 06:34:40 am
content: OK I think I fixed all.https://web.ncf.ca/fs864/pickup/sketch_irled1-003.ino

author: ledtester
author_rank: Super Contributor
timestamp: November 02, 2020, 02:17:29 pm
content: You might be interested in this project:https://youtu.be/taZQkVBzl-cNo code, unfortunately, but the details are discussed in depth.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 02, 2020, 07:40:56 pm
content: Hooray I think I got it working before destroying anything with my soldering iron. Just used a 270 ohm resistor. Seems pretty much how you do it. I encased it in glue gun to make it a bit more durable and safe.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 02, 2020, 10:39:10 pm
content: Well either I have the wrong IR EM freq, or I missed the carrier. I have some ideas, but the code may have to be changed. I may just have to oscillate the current sample. Yup I just ran everything so fast it would be like a modulation and a test receiver got something.I give up, I am starting over with a pure NEC protocol source that inputs the 32 bit transmission. Looks doable. It is not universal, but will allow me to quickly change the light puck, like 5hz or so I guess.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 03, 2020, 04:12:49 am
content: Well the good news is I seem to have it working, and I can use my arduino as a remote for the light puck. The bad news is my codes seem to be slightly different than the other one as per the linux ir-keytable response. It was doing NOTHING for a while until I experimented with lowering certain timings. I was relying on delay statements instead of using timer operations, and the execution time is different from the official timings.The input string looks like this:Y00010000111011110101000010101111ZHere are the codes that concern me:the real remote:41426.337421: event type EV_MSC(0x04): scancode = 0x800amine:42438.193464: event type EV_MSC(0x04): scancode = 0x80aalso:https://web.ncf.ca/fs864/pickup/sketch_irled1-006.ino

author: ledtester
author_rank: Super Contributor
timestamp: November 03, 2020, 05:35:25 am
content: Some immediate observations:- digitalWrite has a lot of overhead. There are "fast" versions of digitalWrite/Read which do not have the overhead of a subroutine call or Arduino pin to AVR PORT bit conversion at run time. Just google "fast digitalWrite arduino".- I am not sure about how delayMicroseconds is implemented, but I would use the avr library version:https://www.nongnu.org/avr-libc/user-manual/group__util__delay.htmlwhich, with the proper compilation flags results in inline code.- bit-banging the carrier signal is insane. I would set up a PWM pin to do that and then just enable or disable it every 562 us as needed.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 03, 2020, 05:54:36 am
content: Thanks for the comments, but hey it works so I am moving on now. I am going to make a c program that pwms between colorrs and some effects, and maybe even disco light applications. When I get some effects done I'll upload a video to youtube and post a link here.

author: ledtester
author_rank: Super Contributor
timestamp: November 03, 2020, 07:26:12 pm
content: I went into the guts of this project:https://github.com/z3t0/Arduino-IRremoteand extracted this code fragment which uses TIMER2 to generate the 38KHz signal on Arduino pin 3:Code:#include <Arduino.h>#define SYSCLOCK F_CPU#define IR_SEND_DUTY_CYCLE 50#define TIMER_ENABLE_SEND_PWM (TCCR2A |= _BV(COM2B1)) // Clear OC2B on Compare Match#define TIMER_DISABLE_SEND_PWM (TCCR2A &= ~(_BV(COM2B1))) // Normal port operation, OC2B disconnected.static void timerConfigForSend(uint16_t aFrequencyKHz) {const uint16_t pwmval = (SYSCLOCK / 2000) / (aFrequencyKHz); // 2000 instead of 1000 because of Phase Correct PWMTCCR2A = _BV(WGM20); // PWM, Phase Correct, Top is OCR2ATCCR2B = _BV(WGM22) | _BV(CS20); // CS20 -> no prescalingOCR2A = pwmval;OCR2B = pwmval * IR_SEND_DUTY_CYCLE / 100;}void setup() {pinMode(3, OUTPUT);digitalWrite(3, 0); // make sure it's low in between burststimerConfigForSend(38);}void loop() {TIMER_ENABLE_SEND_PWM;delayMicroseconds(562);TIMER_DISABLE_SEND_PWM;delayMicroseconds(562*4);}The macro TIMER_ENABLE_SEND_PWM produces the 38KHz signal and TIMER_DISABLE_SEND_PWM reverts the pin to its configuration as a digital I/O pin.

author: msuffidy
author_rank: Frequent Contributor
timestamp: November 03, 2020, 10:38:35 pm
content: Here is the end product. Just some mood lighting. The source for this is at:https://web.ncf.ca/fs864/pickup/lightfeeder.cI figured out my code was different than the remote. It seems the nibbles on the first byte are reversed.***Last note is that I went to the salvation army today and got a $1 remote and gave it another try for more distance with a smaller resistor. Originally I used a 270, and this time I used a 120. In all it works better, but only for like 2 more feet. It looks a bit more tidy. I tried to use a floppy header as a connector this time and light speaker wire.

author: VK3DRB
author_rank: Super Contributor
timestamp: November 04, 2020, 11:38:58 am
content: Consider using IrDA. Most remotes use IrDA because it saves power and ensures a high level of data integrity. Some low cost microcontrollers support IrDA encoding/decoding directly, but you can also use hardware that converts the IrDA format to a normal serial UART signal. This can be connected to a microcontroller UART or to a USB-serial converter like the FTDI-232.I recently designed IR into a product. This application could not use the microcontroller because the IR to the UART had to be accessible if we had to get into bootloader mode. The IR transceiver chip is a TFBS4711 and the hardware encoder/decoder is a TIR1000. These are very easy to use and are cheap, with generally no extra logic required, other than a 16 x the UART baud rate frequency crystal (or just drive oscillator from a microcontroller). The frequency accuracy is not that critical, so you could an LMC555 timer if it is cheaper than a crystal. The TIR1000 can be mounted in any orientation. I have tested the circuit and it works a treat - even with bright LED/Fluoro interference. You can adjust the IR LED power and range from a few centimetres to several metres very easily by changing a resistor.