hi, I have led, IR emitter and IR detector and I want to create a 1 meter connection between emitter and detector and if I breaks connection the led light turn on.
someone can write me a simple code?
thanks
Presuming that the IR receiver is a digital device:
int IROutPin = 8;
int IRInPin = 6;
int LEDPin = 5;
void setup()
{
pinMode(IROutPin, OUTPUT);
pinMode(LEDPin, OUTPUT);
pinMode(IRInPin, INPUT);
digitalWrite(IROutPin, HIGH); // Turn emitter on
}
void loop()
{
if(digitalRead(IRInPin) == HIGH)
{
// Beam is unbroken
digitalWrite(LEDPin, HIGH);
}
else
{
// Beam is broken
digitalWrite(LEDPin, LOW);
}
}
I want to create a 1 meter connection between emitter and detector
1 meter may be (well) beyond the capabilities of the IR emitter you have. Ambient light may interfere (greatly).
this code works only if I move IR emitter
if emitter stay still dosn't work
To do this you need a TSOP4038 as a receiver, This is because it contains a built in amplifier that is designed for continuous beams. A lot of IR receivers are designed for remote controls which is not suitable for your application.
Then you need to drive the emitter with a transistor and make the IR light modulated (turn on an off quickly) at a rate of 38KHz. This can be done either with an NE555 chip or an interrupt driven software routine on your arduino.
it works in this code:
#define IR_CLOCK_RATE 36000L
....
void setup() {
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
....
but I do not understand this code
If you just name the actual receiver you are using we could tell if it is the best system to use.
but I do not understand this code
It is setting up the timer registers to give you as close to 36KHz signal as possible on the PWM output pin you are driving the LED emitter from.
Look at the data sheet of the processor for a description of what the bits in these three registers actually do. However be warned this is an advanced topic and I don't expect you to understand it without a lot of effort.
I have TSOP1738 it is similar to TSOP4038?
I have TSOP1738
So in that code you should put:-
#define IR_CLOCK_RATE 38000L
it is similar to TSOP4038?
It is similar but not the same. You will find that prolonged exposure to the bean (more than a few milliseconds) causes it's output to go like it never saw the beam. That is why it will appear to work if you move it. You are interrupting the beam and it is starting to acquire the signal again. Your receiver is not suitable for what you are trying to do with it.
You might get it to work if you had some macro modulation, that is the modulated beam is turned off every ten cycles for four cycles, but you will have to write that yourself.
does it work with TSOP34838 38kHz or TSOP34836 36kHz?
my emitter and detector looks like this: http://postimage.org/image/oa7g9lef5/
and work with code:
#define IR_CLOCK_RATE 38000L
#define IROutPin 11
#define IRInPin 12
#define LEDPin 2
int signal = 0;
void setup() {
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
pinMode(IROutPin, OUTPUT);
pinMode(LEDPin, OUTPUT);
pinMode(IRInPin, INPUT);
}
void loop() {
signal = digitalRead(IRInPin);
digitalWrite(IROutPin, HIGH);
if(signal == LOW){
digitalWrite(LEDPin, HIGH);
}
digitalWrite(LEDPin, LOW);
}
but IROutPin does't work with other PIN only with 11, so I just want change IROutPin PIN to another
does it work with TSOP34838 38kHz or TSOP34836 36kHz?
I don't understand the question.
The 38 or 36 at the end of the part number denotes the working frequency in KHz.
but IROutPin does't work with other PIN only with 11,
I think you will find it will also work with Pin 3 as well.
Changing it to another pin involves a lot of work and you will screw up other stuff that depends on the timers.
I presume this relates, in some way, to the TLC Connection thread.
I just want use IR and TLC5940NT like this:
http://tlc5940arduino.googlecode.com/svn/wiki/images/breadboard-arduino-tlc5940_close.png
but both need 11 PIN
You haven't posted your code on the the TLC Connection thread, so we can't see if it can be modified.
I dont have code still, because first I want to know how to use IR and TLC
I want to do like this: SEQUA® Automatische LED-Treppenbeleuchtung (Sensorgesteuert) - Automatic LED stair-light controller - YouTube
then cross IR, leds on
I have more then 17 leds so I need TLC to do this
I can show you my old code with 6 leds and 4 IR
#define IR_CLOCK_RATE 36000L
#define siuntejas 11
#define gavejas1 12
#define gavejas2 10
#define gavejas3 9
#define gavejas4 8
int zmonesSK = 0;
int koja1 = 0;
int koja2 = 0;
int koja3 = 0;
int koja4 = 0;
int sviesa = 0;
int signalas1 = 0;
int signalas2 = 0;
int signalas3 = 0;
int signalas4 = 0;
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int led6 = 7;
void setup() {
TCCR2A = _BV(WGM21) | _BV(COM2A0);
TCCR2B = _BV(CS20);
OCR2A = (F_CPU/(IR_CLOCK_RATE*2L)-1);
pinMode(siuntejas, OUTPUT);
pinMode(gavejas1, INPUT);
pinMode(gavejas2, INPUT);
pinMode(gavejas3, INPUT);
pinMode(gavejas4, INPUT);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(led6, OUTPUT);
}
void loop() {
signalas1 = digitalRead(gavejas1);
signalas2 = digitalRead(gavejas2);
signalas3 = digitalRead(gavejas3);
signalas4 = digitalRead(gavejas4);
if(signalas1 == HIGH && signalas2 == LOW) {
koja1 = 1;
}
if(signalas1 == HIGH && signalas2 == HIGH) {
if(koja1 == 1) {
UP();
}
}
if(signalas1 == LOW && signalas2 == HIGH) {
koja2 = 1;
}
if(signalas1 == HIGH && signalas2 == HIGH) {
if(koja2 == 1) {
DOWN();
}
}
if(signalas3 == HIGH && signalas4 == LOW) {
koja3 = 1;
}
if(signalas3 == HIGH && signalas4 == HIGH) {
if(koja3 == 1) {
DOWN();
}
}
if(signalas3 == LOW && signalas4 == HIGH) {
koja4 = 1;
}
if(signalas3 == HIGH && signalas4 == HIGH) {
if(koja4 == 1) {
UP();
}
}
}
void UP() {
zmonesSK++;
zmones();
}
void DOWN() {
zmonesSK--;
zmones();
}
void zmones() {
koja1 = 0;
koja2 = 0;
koja3 = 0;
koja4 = 0;
if(zmonesSK > 0) {
digitalWrite(led1, HIGH);
digitalWrite(led2, HIGH);
digitalWrite(led3, HIGH);
digitalWrite(led4, HIGH);
digitalWrite(led5, HIGH);
digitalWrite(led6, HIGH);
}
if(zmonesSK <= 0) {
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
digitalWrite(led3, LOW);
digitalWrite(led4, LOW);
digitalWrite(led5, LOW);
digitalWrite(led6, LOW);
}
}
It might be better to merge the two threads.
If you intend to use the library on Google Code Archive - Long-term storage for Google Code Project Hosting., then you do need pin 11, as it specifically states that it needs that pin.
If you use the code here http://pixelriot.com/pmatp/node/15. You don't need pin 11 for the TLC.
in this code: http://pixelriot.com/pmatp/node/15
are some error: int word[] = {
and then I conect tlc like this could you explain to me how just turn one led using tlc
I'd be really grateful to you
int word[] = {
Using a reserved word as a variable name always leads to problems. The solution is blindingly obvious.
could enyone write me a simple code witch turns on one led using tlc, then I connect tlc to arduino like this: http://pixelriot.com/pmatp/node/15
You can't use the TLC library with this IR code because they both want to use Timer 2. This translates to both using pin 11.
What you will have to do is either:-
- Use one of the other two timers to generate the PWM signal at the correct frequency. However, this screw other things up like the millis() timer.
- Use an NE555 to generate the signal to modulate the IR emitter.