KY -032 obstacle avoidance sensor not working

I connected the KY -032 obstacle avoidance sensor to an arduino nano using the following pins:
GND --> GND
VCC --> 5V
OUT --> D3

this is the script:

const int sensorPin = 3; // Connect the OUT pin to D3

void setup() {
  Serial.begin(9600); // Initialize serial communication for debugging (optional)
  pinMode(sensorPin, INPUT); // Set the sensor pin as an input
}

void loop() {
  int sensorValue = digitalRead(sensorPin); // Read the digital value from the sensor
  
  if (sensorValue == HIGH) {
    Serial.println("Obstacle detected!"); // Print a message when an obstacle is detected (optional)
    
    // Your code to respond to obstacle detection goes here
  }  Serial.println(sensorValue);
  // Delay to avoid rapid multiple readings (adjust as needed)
  delay(500);
}

it doesn't detect anything. I tried using a remote controller to blast IR light to the sensor and it worked so I guess the problem is the IR light not the sensor.

You probably have a problem with the sensor.
I put your code in the simulator and used an LDR sensor,
(The simulator does not have the KY-032), and the code works correctly when I adjust the sensor by clicking on it.

Have you tried to adjust the variable POT?

variable? (sorry I'm a beginner) do you mean the POT on the module? yes I have adjusted it but it still doesn't work.

I don't think the problem is with the sensor. I think it's the IR light because I tried using a separate IR light and the sensor detected it with no problem.

If it is the same as here there should be two potentiometers on the board.

Quote:

There are two small variable resistors on the board: R5 (closer to the GREEN JUMPER) and R6. R6 is used to tune the 555 oscillator to exactly 38kHz. R5 will limit current to and dim the IR LED as it is turned counter-clockwise. Both adjustments together effect the sensitivity and range of the device.

There is also a thread to be found here:

https://arduino.stackexchange.com/a/26844

Good luck!

I turned on the module and checked whether the IR light is turning on using a camera but it doesn't show that it's working.

Did you have the green jumper installed for the test? That should light up the led even without a sketch handling the EN pin (if the above linked information is true).

If you have access to an oscilloscope you might check the signal at the led pins ...

Good luck!

Yes I have the green jumper installed. Unfortunately I do not have an oscilloscope so I can't check for the signal.

If you have a microcontroller board you can turn it into a pulse counter. Here is a simple example:

https://wokwi.com/projects/377386960545098753

image

-> Sketch
/*
   Forum: https://forum.arduino.cc/t/ky-032-obstacle-avoidance-sensor-not-working/1173727/7
   Wokwi: https://wokwi.com/projects/377386960545098753

   Simple test environment to count pulses using an interrupt

*/

constexpr byte inPin = 3;
unsigned long lastTime =0;

volatile unsigned long count = 0;

void ISRroutine(){
  count++;
};


void setup() {
  // put your setup code here, to run once:
  Serial .begin(115200);
  Serial.println("Start");
  pinMode(inPin, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(inPin),ISRroutine,RISING);
  lastTime = millis();
}

void loop() {
  // put your main code here, to run repeatedly:
  if (millis()-lastTime >= 1000){
    noInterrupts();
    unsigned long lastCount = count;
     lastTime = millis();
     count =0;
     interrupts();
     Serial.println(lastCount);
  }

}

It uses an IR receiver and an IR Remote Control and prints the number of received pulses per 1000 msec. Each button press of the Remote Control results in 34 pulses in this case. If you press a button several times/second the number of pulses add up.

If you have a spare IR receiver ( e.g. like KY-022 INFRAROT-RECEIVER) you can power the KY-032 and use a setup like here to check incoming pulses. I

If not you may carefully (not to create any shortcut!) connect pin 3 to the anode of the IR diode, power the KY-032 and run the sketch. If the diode gets any pulses Serial should display values far from zero. I tested it with the following results:


Setup:

Connect the "probe" to the anode of the IR LED:
image

The frequency is the number of pulses divided by two.

Where are the results? I tried this and edited the R6 pot till I got 34 so what do I do now?(sorry I'm a beginner)

A count value over or around 73000 pulses shows that the led is triggered by the onboard 555 timer chip.

If you check the led now with a smartphone camera you should see it flickering. If it does not, the led might be defect.

Could you post your complete hardware setup?

What controller are you using?
How did you wire the KY-032?

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