Landing : Athabascau University
  • Blogs
  • SIK Guide v4.0a - Project 3B: Distance Sensor

SIK Guide v4.0a - Project 3B: Distance Sensor

Circuit 3B: Distance Sensor (I don't see an equivalent circuit in the SIK v3.3 guide)

This distance sensor circuit was cool and seems like it could be very useful. I found that I had to adjust the values to make the LED lights up a different distances. I converted the units of measure to centimeters by using the formula (as shown on the datasheet ( to uS / 58 = centimeters (as opposed to uS / 148 for inches):

 calcualtedDistance = echoTime / 58.0;

Adding a third color was easy. I did this by adding an additional else if statement that if the ultasonic device measures between the distance of 20 to 30 cm, then the RGB LED turns green, and I changed the last else statement to make the RGB lED purple / magenta if it read any other value greater then 30 cm's away:

else if(20 < distance && distance < 30){ //if the object is between medium & long distance
//make the RGB LED green
analogWrite(redPin, 0);
analogWrite(greenPin, 255);
analogWrite(bluePin, 0);

} else{ //if the object is far away

//make the RGB LED magenta
analogWrite(redPin, 100);
analogWrite(greenPin, 0);
analogWrite(bluePin, 100);

Distance Sensor:

Modified Distance Sensor:


Distance Sensor Unit of measure (UOM) change to centimeters from inches



These comments are moderated. Your comment will not be visible unless accepted by the content owner.

Only simple HTML formatting is allowed and any hyperlinks will be stripped away. If you need to include a URL then please simply type it so that users can copy and paste it if needed.