My Infrared Sensor is not recieving on regular mBot


#1

Hello,

my arduino code is not returning anything when I try to receive something. My remote is working but I don’t know how to test my reciever if it’s not returning anything. Here’s the code:

#include “MeOrion.h”
#include <SoftwareSerial.h>

//#define dumbytest 0x

MeInfraredReceiver infraredReceiverDecode(PORT_6);

//Motor
MeDCMotor motor1 (M1); //left motor
MeDCMotor motor2 (M2); //right motor

void setup()
{
infraredReceiverDecode.begin();
Serial.begin(9600);
}

void loop()
{
uint8_t ReceiverCode;

if(infraredReceiverDecode.available())
{
ReceiverCode = infraredReceiverDecode.read();
Serial.println(ReceiverCode);
// if (ReceiverCode == dumbytest) {
// motor1.run(-100);
// motor2.run(100);
// }
}
delay(500);
}

Thank you


#2

:bulb: Tip: To keep the forum looking nice, you can format your code like this:

```c
(Your code)
```

@bm476 Check a couple of things:

  • Do you have the Mentioned libraries installed in your environment (also, what IDE are you using)?
  • Verify that the pin assignment PORT_6 for MeInfraredReceiver is correct for the sensor you are using on your mBot.

Try a simple code like this one to test the sensor:

#include "MeOrion.h"
#include <SoftwareSerial.h>

MeInfraredReceiver infraredReceiverDecode(PORT_6);

void setup() {
  infraredReceiverDecode.begin();
  Serial.begin(9600);
}

void loop() {
  if (infraredReceiverDecode.available()) {
    uint8_t data = infraredReceiverDecode.read();
    Serial.print("Data received: ");
    Serial.println(data, HEX);
  }
  delay(100);
}

If you are coding with blocks, can you please provide a screenshot or image of your block code? Thank you!


#3

With an mBot you should be using: #include <MeMCore.h> here not #include “MeOrion.h” ?


#4

Hi I put the code in and got Data Received: FF which is not what I thought to expect and I tried both libraries and it didn’t work with the new code


#5

i’m not using blocks


#6

HOw would you find out if port 6 is the correct port because that might be the problem


#7

I doubt that is the issue, since my code gave you a sensor reading. Try repeatedly pressing (do NOT press and hold) the remote buttons near the sensor while my code is running and see what you get.
@bm476


#8

problem is it’s not even printing anything in the serial monitor


#9

I don’t think it’s available…


#10

How did it print Data Received: FF previously, then? @bm476


#11

It only did it once


#12

Then what happened?
Any errors?