I'm new to Arduino, I bought the 37 sensor kit 2.0 and I was experimenting around with it.
I took a KY-032 Obstacle avoidance sensor module and a passive buzzer.
buzzer pin to digital pin 9
sensor output to digital pin 8
Basically I want the buzzer to make a sound whenever the sensor detects something, but every so often it detects something even if there's nothing in front, also I have to position it in a strange way, cuz if I lay the sensor parallel to ground it start going crazy, again, without anything in front.
Maybe instead of blasting the IR continuously you should try the approach in the second hit from a google search on "KY-032 noise" http://irsensor.wizecode.com/...which includes this quote from the datasheet (of the on-board receiver):
These products are designed to suppress spurious output pulses due to noise or disturbance signals. Data and disturbance signals can be distinguished by the devices according to:
carrier frequency,
burst length and
envelope duty cycle.
The data signal should be close to the band-pass center frequency of 38 kHz and fulfill the following conditions. After each burst of 10 to 70 cycles, a minimum gap time in the data stream of 10 cycles is needed. For bursts greater than 70 cycles, a minimum gap time in the data stream of greater than 4x the burst length is needed. When a data signal is applied to the IR receiver in the presence of a disturbance signal, the sensitivity of the receiver is reduced to insure that no spurious pulses are present at the output. Some examples of disturbance signals which are suppressed are:
DC light (e.g. from tungsten bulb or sunlight)
Continuous signals at any frequency
Strongly or weakly modulated noise from fluorescent lamps with electronic ballasts.
and this sample code (not tested or evaluated by me):
//Sample C++ code to strobe the IR LED with a 600µs pulse and test for a return:
digitalWrite( enablePin, HIGH); // Enable the internal 38kHz signal.
microDelay( 210); // Wait 210µs (8 pulses of 38kHz).
if( digitalRead( outputPin)) // If detector Output is HIGH,
{
objectDetect = false; // then no object was detected;
}
else // but if the Output is LOW,
{
microDelay( 395); // wait for another 15 pulses.
if( digitalRead( outputPin)) // If the Output is now HIGH,
{ // then first Read was noise
objectDetect = false; // and no object was detected;
}
else // but if the Output is still LOW,
{
objectDetect = true; // then an object was truly detected.
}
}
digitalWrite( enablePin, LOW); // Disable the internal 38kHz signal.
If you want to try that, be sure to read the part about disconnecting the jumper to be able to use the enable pin.......
And note the comment about extending the shielding of the IR LED.