Hello World! I made another example project, I am using the KY-032 to show you how obstacle avoidance Sensors work. The code is basic but works fine for simple things. From the code you can build bigger projects.
The obstacle avoidance sensor is being used in multiple things, for example Unmanned military vehicles.
In cars, and a lot of robotics.


Parts list:
Arduino Uno, I used the RobotDyn UNO, a chinese copy with 7 Analog pins.
3 Color RGB KY-016
Obstacle Avoidance Sensor KY-032
Set of Jumper wires MM/FF/MF
9 Volt battery + Battery Plug.(optional)


//Author: Danny van den Brande. BlueCore Tech.
//This is an example code on how to use the arduino OBSTACLE AVOIDANCE sensor KY-032
//This sensor works the same as warning sensors in cars. Used in many robot projects.
int Buzzer = 3;
int AvoidancePin = 4; // define the obstacle avoidance sensor interface
int RedLed = 5 ;
int GreenLed = 6 ;
int val ;// Value High or LOW. 

// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
//              1    2    3    4    5    6    7    8    9    10   11   12   13   14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below,  digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14

void setup ()
  Serial.begin (9600);
  pinMode (RedLed, OUTPUT) ;
  pinMode (GreenLed, OUTPUT) ; 
  pinMode (Buzzer, OUTPUT) ;
  pinMode (AvoidancePin, INPUT) ;// define the obstacle avoidance sensor output interface
void loop ()
  val = digitalRead (AvoidancePin) ;// Reading from the AvoidancePin
  if (val == HIGH) 
    digitalWrite (RedLed, LOW);
    digitalWrite (GreenLed, HIGH);
    digitalWrite (Buzzer, LOW);
    digitalWrite (RedLed, HIGH);
    digitalWrite (GreenLed, LOW);
    digitalWrite (Buzzer, HIGH);
    tone(Buzzer, tones[6]);//You can change the tone choosing from 1 to 14.
Danny van den Brande

Programmer, Game Designer, 3D Designer, Web Designer, Graphic Designer. Jup this website looks crappy.. :) But enjoy the projects! Everything you need is here.

Leave a Reply

Your email address will not be published. Required fields are marked *