IR sensor signal detected by different pin from the one connected to

I'm using an Arduino Mega for this.
Cable connections are as shown in the picture.

  • When I find something with the left IR sensor even though there is an output the Arduino pin 32 doesn't detect it.
  • When the middle sensor has output the Arduino pin 31 detects it. But the Serial monitor shows that both 31 and 32 have detected something. Playing with the left IR sensor still does nothing. Both are controlled by the middle one.
  • Right IR sensor is unaffected by them.

Instead of a breadboard I'm actually using a perforated board. The first thing I did was freshen the connections on it but nothing got fixed.
Using a multimeter I found no errors in the connections. No shorts.

#define pin1 30
#define pin2 31
#define pin3 32

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(pin1, INPUT);
  pinMode(pin2, INPUT);
  pinMode(pin3, INPUT);

  Serial.println("Starting in: ");
  Serial.println("3... ");
  delay(1000);
  Serial.println("2... ");
  delay(1000);
  Serial.println("1... ");
  delay(1000);
  Serial.println("Started!");
 
}

long timer;
bool st = false;
int c = 0;

void loop() {

  long timer_now = millis();
  
  bool s1 = digitalRead(pin1);
  bool s2 = digitalRead(pin2);
  bool s3 = digitalRead(pin3);

  if(!st) {
    st = !st;
    timer = millis();
  }
  else if(st) {
    if(timer_now - timer >= 1000) {
      Serial.println(c);
      c+=1;
  
      Serial.print("Sensor 30 :");
      Serial.println(!s1);
      Serial.print("Sensor 31 :");
      Serial.println(!s2);
      Serial.print("Sensor 32 :");
      Serial.println(!s3);
      Serial.println();

      

      st = !st;
      
    }
  }

}

What means this? When you aim an IR signal at it?

How are you shielding the other two sensors? I can't work your code just now, so I wonder if you are sure the other two can't see the same signal.

If you are shielding them for tests, be sure the material of the shield is opaque for IR wavelengths - lotsa plastic is not.

HTH

Now looking at the code it appears you are using IR receivers that expect a modulated IR signal like a remote control, and are not meant to be simply digitally read. You would need a library to help.

So say exactly what those three things that look like transistors are.

a7

1 Like

st is a Boolean so no need for that second if(). If it is not false, it has to be true

  if(!st) {
    st = !st;
    timer = millis();
  }
  else {
   ...

You also have declared your pins as INPUT so if those photo diodes or transistors are not conducting, those pins are floating (not connected to HIGH or LOW) so they could read anything. You need to make them INPUT_PULLUP or add external pullup/pulldown resistors.

Welcome! I would expect to get what you are apparently getting. Your picture shows an Arduino UNO, not a MEGA. Different boards different pins. Also how are you powering this?

I've tried doing this but still no difference.

I've tried powering the Arduino from both a 12v power supply and from my laptop. No difference.

The sensors are powered by the Arduino 5v pin.

What are these sensors?
Can you post a datasheet or a link here please

1 Like

Hi, @dionysis00
Welcome to the forum.

Can you please post some images of your project?
So we can see you component layout.

Can you please post a link to specs/data of your sensors?

Do you have a DMM? Digital MultiMeter?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

How are you shielding the other two sensors?

I haven't been shielding them. I thought about this being an issue but even when the Arduino is not receiving any other signal, the same thing is still happening. I have tried swapping cables and sensors, and nothing has changed.

You would need a library to help.

Which library would you recommend?

I temporarily moved the sensors to a breadboard for troubleshooting.

Can you please post some images of your project?
So we can see you component layout.

These sensors are part of a bigger project. At the moment everything else is turned off and only the sensors are being powered by the Arduino 5v pin.
Imgur
Imgur
Imgur

Can you please post a link to specs/data of your sensors?

I bought the sensors from here: Ηλεκτρονικά :: Αισθητήρες :: Υπερύθρων :: Infrared Obstacle Avoidance Sensor Module for Arduino

Do you have a DMM? Digital MultiMeter?

Yes, I'm using a DMM.

** I forgot to mention that a few days ago I had an issue with my Arduino: It wouldn't turn on and when I checked the voltage regulator, the OUT and GND pins of the regulator were shorted.
The next day it worked just fine. Is it possible something got fried during all this and all I have to do is just use other pins?

Thanks.

None, now that you have told us what your sensors are., which I asked you to in post #2.

Have you tried getting one sensor to work, just read and report, nothing else. no timing, no spam control, no other sensors?

// same setup and other junk, new loop:

void loop() {

  bool s1 = digitalRead(pin1) == HIGH;

  Serial.println(s1 ? "HIGH" : "           LOW");
} 

With just one sensor attached, test all three sensors.

Then use the sketch I posted and see if you can expand it to read and report two sensors.

HTH

a7

Hi, @dionysis00
Does the signal LED come on when you activate the sensor?

What are all those series resistors for with the diode?

Was anything connected to the controller at the time?

Very good idea, go back to basics.
And write a very simple code for the test.

Tom... :smiley: :+1: :coffee: :australia:

Except you have the sensors on different pins, are using a Mega not the UNO and the sensors in your picture are totally different to the ones you are actually using.

Misleading at best. You've wasted time, ours and your own.

Where did you get the idea to add the resistor and diode to the output of the sensor? If you dreamt that up yourself, stop dreaming.

a7

Your incomplete and misleading answers make it difficult to solve. Start from ground zero, new sensor(s) and Arduino. Remove the diodes and resistors, no idea what they are there for. Post links to technical information on each of the hardware devices. Good Luck!

Hey, I finally found the issue to be with the screw terminals that used to connect the cables to the Arduino and I'm not sure why. As soon as I removed them everything worked as expected.

I just want to apologize for the bad communication and say thank you to all of you for trying help, I really appreciate it!
The "start from zero" advice was good!

Hi, @dionysis00

How do you man removed them, can you please post some images of your solution?

Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.