Distance Sensing with Arduino

Here is a simple example of using a Sharp IR Distance sensor with an RGB LED. It affects the red pin of the LED and modifies the color based on the distance your hand is from the sensor.

Distance Sensing with Arduino from niki selken on Vimeo.

int sensor = 0;
int sensor2 = 1;
int sensor3 = 2;
int value = 0;
int value1 = 0;
int value2 = 0;
int value3 = 0;

int red = 6;
int green = 5;
int blue = 3;

void setup () {
pinMode (red,OUTPUT);
pinMode (green,OUTPUT);
pinMode (blue,OUTPUT);


void loop (){

value = analogRead (sensor); //read value from the sensor
value = map(value, 0, 1023, 255, 0); //maps the two number scales
Serial.print(value); // print the reading from the variable window
delay (20);


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s