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 (https://cdn.sparkfun.com/datasheets/Sensors/Proximity/HCSR04.pdf) 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
The Landing is a social site for Athabasca University staff, students and invited guests. It is a space where they can share, communicate and connect with anyone or everyone.
Unless you are logged in, you will only be able to see the fraction of posts on the site that have been made public. Right now you are not logged in.
If you have an Athabasca University login ID, use your standard username and password to access this site.
We welcome comments on public posts from members of the public. Please note, however, that all comments made on public posts must be moderated by their owners before they become visible on the site. The owner of the post (and no one else) has to do that.
If you want the full range of features and you have a login ID, log in using the links at the top of the page or at https://landing.athabascau.ca/login (logins are secure and encrypted)
Posts made here are the responsibility of their owners and may not reflect the views of Athabasca University.