Hi,
I'm tring to work on a simple IR emitter-reciver sistem and I've spent on it 5 days now and still is not working .The pourpouse is to understand is there is an obstacle between the emitter-reciver, but I have several problems. As a reciver I'm using a TSOP32238 of Vishay, is a 3 pin sensor, 38,5khz and is the only thing that work because I've connected its signal to a led and it's blinking if I use my stereo remote on it. The emitter seems not working properly, dont think because of electrical connection, probably is a code issue. Here's the code I'm using:
//define pins. I used pins 4 and 5 #define irLedPin 4 // IR Led on this pin #define irSensorPin 5 // IR sensor on this pin
int irRead(int readPin, int triggerPin); //function prototype
void setup()
{
pinMode(irSensorPin, INPUT);
pinMode(irLedPin, OUTPUT);
Serial.begin(9600);
// prints title with ending line break
Serial.println("Program Starting");
// wait for the long string to be sent
delay(100);
}
void loop()
{
Serial.println(irRead(irSensorPin, irLedPin)); //display the results
delay(10); //wait for the string to be sent
}
int irRead(int readPin, int triggerPin)
{
int halfPeriod = 13; //one period at 38.5khZ is aproximately 26 microseconds
int cycles = 38; //26 microseconds * 38 is more or less 1 millisecond
int i;
for (i=0; i <=cycles; i++)
{
digitalWrite(triggerPin, HIGH);
delayMicroseconds(halfPeriod);
digitalWrite(triggerPin, LOW);
delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead
}
return digitalRead(readPin);
}
Does anyone know where I made a mistake?
ps if it's needed I could post the electrical scheme overhere.
Ok, thx PaulS, I have worked with the library you suggested me. First of all it works and helped me to learn more about ir, but now I still have a problem: this library cant allow you to transmit and recive at same time..... so for my project is not complete. Do you have any other suggestion?
hello,
i am making an automatic street light controller using ir sensor.
in my project i have 4 ir sensor and 5 power LED(will act as street light).I gave the 5v input to the IR sensors from arduino 5v pin (to all 4 sensor). and connected the led to the respective digital pins. but i tried to upload the code the code wasn't uploading.
Next what i did :
i took the supply from external source and gave it 5v and gnd of the sensors. and nly connect the out of ir sensor to arduino. Even the Power led i connected through Transistor such that base was given to transistor, collector to external supply, and emitter the power led and other pin of led to gnd. still i had the same problem
this is my code #define IR1 1 #define IR2 2 #define IR3 3 #define IR4 4
int detection1; // no obstacle
int detection2;
int detection3;
int detection4;
int ledPin1 = 6;
int ledPin2 = 7;
int ledPin3 = 8;
int ledPin4 = 8;
int ledPin5 = 9;
int Value1=10;
int Value2=50;
void setup()
{
Serial.begin(9600);
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
pinMode(IR3, INPUT);
pinMode(IR4, INPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
}
void loop() {
detection1 = digitalRead(IR1);
detection2 = digitalRead(IR2);
detection3 = digitalRead(IR3);
detection4 = digitalRead(IR4);
analogWrite(ledPin1, Value1);
analogWrite(ledPin2, Value1);
analogWrite(ledPin3, Value1);
analogWrite(ledPin4, Value1);
analogWrite(ledPin5, Value1);
if(detection1 == LOW)
{
analogWrite(ledPin1, Value1);
}
else
{
analogWrite(ledPin1, Value2);
analogWrite(ledPin2, Value2);
Sorry that program i had corrected sent a old program by mistake.
could u please help in why that could is not getting dumpped even when i am apply external power supply(reason being that the sensor and power led of 1w should not drain the current from the arduino on board pins)