Go Down

Topic: IR Sensor(TSOP382) (Read 1 time) previous topic - next topic

jack1992

Hello i make a robot(Arduino Uno) that it can be controlled with tv remote control.I have the TSOP382 38KHZ and i make this connection

(Vout) Pin 1 to pin 11(Arduino)
(GND) Pin 2 to GND(Arduino)
(Vcc) Pin 3 to 5v(Arduino)

i have upload this sketch in arduino
Code: [Select]
#include <IRremote.h>
int IRpin = 11 ;
IRrecv irrecv(IRpin);
decode_results results;
int const PWMA = 6;
int const PWMB = 5;
int const dirA = 7;
int const dirB = 4;

void setup ()
{
  irrecv.enableIRIn();
  pinMode(PWMA, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(dirA, OUTPUT); 
  pinMode(dirB, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  //if some date is sent, reads it and saves in state
   if (irrecv.decode(&results))
    {
         irrecv.resume();   // Receive the next value
    }
 
   if (results.value == 1086314535)  // this is where you put in your IR remote button #
     {
       digitalWrite(dirA, HIGH);
       digitalWrite(dirB, HIGH);
       analogWrite(PWMA, 255);
       analogWrite(PWMB, 255);
    {
          Serial.println("Go Forward!");
      }
    }
//if some date is sent, reads it and saves in state   
   if (irrecv.decode(&results))
{
         irrecv.resume();   // Receive the next value
    }
    if (results.value == 1086322695)  // this is where you put in your IR remote button #
     {
       digitalWrite(dirA, LOW);
       digitalWrite(dirB, LOW);
       analogWrite(PWMA, 255);
       analogWrite(PWMB, 255);
       {
          Serial.println("Go Backward!");
      }
    }
//if some date is sent, reads it and saves in state
if (irrecv.decode(&results))
{
         irrecv.resume();   // Receive the next value
    }
    if (results.value == 1086290055)  // this is where you put in your IR remote button #
     {
        digitalWrite(dirA, HIGH);
        digitalWrite(dirB, LOW);
        analogWrite(PWMA, 255);
        analogWrite(PWMB, 255);
        {
          Serial.println("Turn Left!");
      }
    }
//if some date is sent, reads it and saves in state
if (irrecv.decode(&results))
{
         irrecv.resume();   // Receive the next value
    }
    if (results.value == 1086281895)  // this is where you put in your IR remote button #
     {
         digitalWrite(dirA, LOW);
         digitalWrite(dirB, HIGH);
         analogWrite(PWMA, 255);
         analogWrite(PWMB, 255);
         {
          Serial.println("turn Right!");
      }
    }
//if some date is sent, reads it and saves in state
if (irrecv.decode(&results))
{
         irrecv.resume();   // Receive the next value
    }
    if (results.value == 1086271695)  // this is where you put in your IR remote button #
     {
         digitalWrite(dirA, 0);
         digitalWrite(dirB, 0);
         analogWrite(PWMA, 0);
         analogWrite(PWMB, 0);
         {
          Serial.println("Stop!");
      }
    }
}


i press buttons on the serial monitor but nothing show up.I have the IR library installed.I don't know why this happens.Please can you help me?thanks in advance.

OldSteve

#1
Dec 24, 2015, 05:26 am Last Edit: Dec 24, 2015, 05:27 am by OldSteve
Assuming that the codes are correct, this is closer to what you want:-
(I assume that you previously recorded the codes.)
Code: [Select]
#include <IRremote.h>

const byte IRpin = 11;
const byte PWMA = 6;
const byte PWMB = 5;
const byte dirA = 7;
const byte dirB = 4;

IRrecv irrecv(IRpin);
decode_results results;

void setup ()
{
    irrecv.enableIRIn();
    pinMode(PWMA, OUTPUT);
    pinMode(PWMB, OUTPUT);
    pinMode(dirA, OUTPUT);
    pinMode(dirB, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
    if (irrecv.decode(&results))
    {
        if (results.value == 1086314535)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, HIGH);
            digitalWrite(dirB, HIGH);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Go Forward!");
        }

        if (results.value == 1086322695)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, LOW);
            digitalWrite(dirB, LOW);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Go Backward!");
        }

        if (results.value == 1086290055)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, HIGH);
            digitalWrite(dirB, LOW);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Turn Left!");
        }

        if (results.value == 1086281895)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, LOW);
            digitalWrite(dirB, HIGH);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("turn Right!");
        }

        if (results.value == 1086271695)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, 0);
            digitalWrite(dirB, 0);
            analogWrite(PWMA, 0);
            analogWrite(PWMB, 0);
            Serial.println("Stop!");
        }
        irrecv.resume();   // Receive the next value
    }
}
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

jack1992

Assuming that the codes are correct, this is closer to what you want:-
(I assume that you previously recorded the codes.)
Code: [Select]
#include <IRremote.h>

const byte IRpin = 11;
const byte PWMA = 6;
const byte PWMB = 5;
const byte dirA = 7;
const byte dirB = 4;

IRrecv irrecv(IRpin);
decode_results results;

void setup ()
{
    irrecv.enableIRIn();
    pinMode(PWMA, OUTPUT);
    pinMode(PWMB, OUTPUT);
    pinMode(dirA, OUTPUT);
    pinMode(dirB, OUTPUT);
    Serial.begin(9600);
}

void loop()
{
    if (irrecv.decode(&results))
    {
        if (results.value == 1086314535)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, HIGH);
            digitalWrite(dirB, HIGH);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Go Forward!");
        }

        if (results.value == 1086322695)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, LOW);
            digitalWrite(dirB, LOW);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Go Backward!");
        }

        if (results.value == 1086290055)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, HIGH);
            digitalWrite(dirB, LOW);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("Turn Left!");
        }

        if (results.value == 1086281895)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, LOW);
            digitalWrite(dirB, HIGH);
            analogWrite(PWMA, 255);
            analogWrite(PWMB, 255);
            Serial.println("turn Right!");
        }

        if (results.value == 1086271695)  // this is where you put in your IR remote button #
        {
            digitalWrite(dirA, 0);
            digitalWrite(dirB, 0);
            analogWrite(PWMA, 0);
            analogWrite(PWMB, 0);
            Serial.println("Stop!");
        }
        irrecv.resume();   // Receive the next value
    }
}


I try your code and nothing happens.What else i have to do?I have upload the test code of tsop382(to see if works)and again didn't capture codes.It has to be both(tsop and tv remote)at 38KHZ in order to work.Thank you for your reply.

OldSteve

#3
Dec 24, 2015, 09:27 am Last Edit: Dec 24, 2015, 09:47 am by OldSteve
I try your code and nothing happens.What else i have to do?I have upload the test code of tsop382(to see if works)and again didn't capture codes.It has to be both(tsop and tv remote)at 38KHZ in order to work.Thank you for your reply.
Have you recorded those codes from your remote control?
You can't just use the codes that were already in the code (of course).

I used the "IRremote" library's "IRrecvDemo" example to record the codes from my remote control one at a time and display them in hex format on the serial monitor, then copied them and used those values in similar code to that above. If the codes are correct, it should work.

You say "I have upload the test code of tsop382(to see if works)and again didn't capture codes."
Do you have a link to this code?

And have you tried using the "IRrecvDemo" example?
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

jack1992

Have you recorded those codes from your remote control?
You can't just use the codes that were already in the code (of course).

I used the "IRremote" library's "IRrecvDemo" example to record the codes from my remote control one at a time and display them in hex format on the serial monitor, then copied them and used those values in similar code to that above. If the codes are correct, it should work.

You say "I have upload the test code of tsop382(to see if works)and again didn't capture codes."
Do you have a link to this code?

And have you tried using the "IRrecvDemo" example?
My tsop382 din't capture codes from my remote control at all.I know that i can't use the codes that were already in the code(is an example).The "IRrecvDemo" example didn't capture codes.

the test code link
https://learn.adafruit.com/ir-sensor/using-an-ir-sensor

OldSteve

My tsop382 din't capture codes from my remote control at all.I know that i can't use the codes that were already in the code(is an example).The "IRrecvDemo" example didn't capture codes.
Then where did the IR codes in your program come from, if not your remote control?
Of course they weren't going to work, if you haven't yet recorded any codes.

So if "IRrecvDemo" can't capture codes, you have a problem. Are you sure that your TV remote control is 38kHz? How have you determined this?

You need to go right back to basics. You shouldn't have written any motor code yet if you haven't even got the IR part working in a separate test program.
I feel like I've been completely wasting my time.

When I posted that code for you, I said "Assuming that the codes are correct, this is closer to what you want:-
(I assume that you previously recorded the codes.)"

And you replied with "I try your code and nothing happens.", implying that the codes in the program were from your remote control.

I think you'd better do some reading in the documentation of the "IRremote" library, learn how to record raw codes, then start again.
I'm not wasting any further time on this. You've been leading me up the garden path, just because you couldn't be bothered learning how to do it in the first place.
Please do not PM me for help. I am not a personal consultant.
And others will benefit as well if you post your question publicly on the forums.

Go Up