Week 2: Enhanced Homemade Switch

Sept 16th, 2019       Physical Computing

Soap Holder Switch

Last week, I made a stainless soap switch where the soap itself is the switch that connects

two wires together. But I didn't finish my original goal of making it change color, so I decided to add this function to this new version.

first version of homemade switch

This time, the goal is that when the soap leaves the holder, the light turns red to signal people that the soap is not in place; when the soap is put back to the holder, the light turns green, which indicates it's in a 'safe place'.  Since I don't want to use 2 LED lights, I'll need a RGB LED that switches the color based on how far the soap is to the soap holder.

I found this tutorial in the SparkFun handbook, which seem to show exactly the effect that I want to create. It requires a distance sensor to detect how far the object is from the sensor, and then use Arduino to control what light to switch to based on the distance value. 


After the first trial on the breadboard, everything seem to work just fine, but I noticed that when I hold put the soap super close / directly on the sensor, the light turns back to red again, and the distance shown on the serial monitor is significantly higher and is not exactly correct. 

I didn't figure out the exact reason (maybe has something to do with echo).

So I simply changed the code and made the greenPin turn on when distance > 350.

And it worked!

In order to make it look more simple, I got rid of the breadboard, attached all the wires together

and hide the sensor and everything under a box I made to make the prototype.

and DONE!

  • Grey LinkedIn Icon
  • Grey Instagram Icon