General > General Technical Chat
making a simple IR transmitter
msuffidy:
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.
ledtester:
I went into the guts of this project:
https://github.com/z3t0/Arduino-IRremote
and 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 PWM
TCCR2A = _BV(WGM20); // PWM, Phase Correct, Top is OCR2A
TCCR2B = _BV(WGM22) | _BV(CS20); // CS20 -> no prescaling
OCR2A = pwmval;
OCR2B = pwmval * IR_SEND_DUTY_CYCLE / 100;
}
void setup() {
pinMode(3, OUTPUT);
digitalWrite(3, 0); // make sure it's low in between bursts
timerConfigForSend(38);
}
void loop() {
TIMER_ENABLE_SEND_PWM;
delayMicroseconds(562);
TIMER_DISABLE_SEND_PWM;
delayMicroseconds(562*4);
}
--- End code ---
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.
msuffidy:
Here is the end product. Just some mood lighting. The source for this is at:
https://web.ncf.ca/fs864/pickup/lightfeeder.c
I 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.
VK3DRB:
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.
Navigation
[0] Message Index
[*] Previous page
Go to full version