The Automated Soap dispenser is a contactless soap dispenser with a built in 20 second countdown timer that is represented by either a LCD or a Servo. In an age where germs are the paramount threat, it is good practice to wash your hands regularly and thoroughly. This project makes that part of life just a little bit easier and more enjoyable.
9G servo (works with some soap dispensers with weak springs)
To start, you should gather all parts listed above.
First, we will create the circuit that pumps the soap bottle.
For this you will need your servo, a builder base, and three MM jumper wires.
With most 9G servos the wire colors will represent the following:
We will now connect the Servo to the Builder Base using the jumper wires as follows:
If you decided to use the servo timer instead of the LCD to display the time remaining, you will need to add a second servo to the client attached to GP1.
Timer Servo (Optional)
Now we can assemble the circuit for our LCD and Distance Sensor. If you follow the diagram below you should only need 4 MF and 6 MM jumper wires, and a bread board.
Here is wiring guide for the two components:
Build the dispenser (3D printed Case)
We’ve updated this project with a 3D printed case to house all of the components. You can find the model at the bottom of the page.
If you do not have access to a 3D printer continue down to “Step2: Building the dispenser (Old Case)” to learn how to build the model without our 3D printed box.
With this project you have two options to show the time remaining. The first option we’ll show you how to build is the LCD timer.
To place the LCD timer onto the case you will need your LCD circuit and 2 M3x 20mm bolts.
Using your M3 Bolts, secure the LCD to the front plate of your project, like so.
Next, place the client that the LCD is connected to in the rear client holder.
And that’s it for installing the LCD Timer!
The second option is the servo timer.
Start by printing out our timer graphic, cutting it out, and gluing it to the front of the case as shown below.
Next, place your servo and its wires through the rectangular hole in the center of the front plate.
Next, we will place the actuator servo on the case. Do so as shown below.
Place the servo in the slot on the left side of the face plate with the servo spline on the top half of the servo. Next, using 2 M3 screws, secure the servo to the base.
Now, we will place the servo client on the back of the case.
The client holders are designed to hold the client in place through a snug friction fit, so no velcro or adhesives are needed.
Next, we affix the distance sensor and its client to the case.
Simply place the distance sensor into its slot and bend the wires upwards so that there is clearance for the soap bottle. As for the client, place it in the remaining client holder just as we did for the previous client.
Next, we will place the soap bottle in the case. Simply squeeze the bottle into the center cutout. We sized ours to fit most generic soap bottles, but if yours doesn’t fit in the case you can modify the 3D file to fit yours.
Now, to complete the assembly of this project we need to attach our dispensing wire to the case and the servo.
Start by threading your wire through the hole that is adjacent to the distance sensor.
Then place the wire atop the dispenser nozzle.
Finally, holding the wire taught, feed the wire through one of the holes in the servo arm and tie it off.
That’s it! The assembly of this project using the 3D printed case is now complete!
Pair the Builder Base
Now we want to pair the Builder Base with our Q-Server. In order to do so, go to the Homescreen of your Q-Server.
Next click on the lift side symbol labeled “Clients”. Switch to the “Unpaired” tab at the top middle of the screen.
You should see your unpaired Builder Base. If not, check if you have plugged in the power supply for the Builder Base. Now move to the three dots below “Actions” and click “Pair”.
Once your Client is paired, click the “Setup” button.
Now you can edit your Client. Give him a Name you want and also a location where you are going to use it. Hit “Save” when you finished.
Build the Firmware
Remember: All application and firmware files are available in the resources section below!
Using the toolbar on the left hand side navigate to the firmware builder. Select “+ Create New” on the upper left hand side of the screen.
Next, name your firmware file “Servo” and hit “Create”.
Now, select the “+ Add Hardware” button. You can find hardware by using the search bar, or by scrolling through the list. Find and select, the “Servo” hardware, name it Servo, and click “Add Hardware”.
Now, repeat the previous steps and add another Servo to your firmware file. Name this one “Servo Timer”
Now you are ready to configure the devices.
Select the Servo Device and then from the Driver drop-down menu select “Generic”. For the Pin select GP0
Select the Servo Timer Device and then from the Driver drop-down menu select “Generic”. For the Pin select GP1.
That’s all we need to do for the Servo firmware file. Now you can save it by hitting the blue save button at the bottom of the screen.
We will now create the firmware file for the Distance Sensor and LCD.
Click the “+Create New” button. Name your new file “Distance Sensor + LCD” and hit “Create”.
Next, select “+ Add Hardware”. Using the search functions find the “LCD” hardware, name it “LCD”, and hit the “Add Hardware” button.
We still have to add the distance sensor, so hit the “+Add Hardware” button, search for “Distance Ultrasonic” device, name it “Distance” and hit the “Add Hardware” button. You should now have these two devices in your firmware hardware list.
To configure the LCD, click on the LCD device, and select the “Generic LCD2004 Display LCD” driver from the driver drop down menu.
Configure the driver accordingly:
I2C Address: 0x27
Now we will configure the Distance Sensor. Click on the distance sensor device and select the HC-SR04 driver from the driver drop down menu.
Configure the driver accordingly:
Echo Pin: GP3
Trigger Pin: GP4
It is important to note that your resolution will be affected by your system measurement settings. Ours is currently set to imperial, so it is measuring in inches. However, if you have the system set to metric the resolution will be in cm
Save your firmware file by hitting blue save button at the bottom of the screen.
Now you are ready to upload your Firmware files!
For both your “Servo” and “Distance+LCD” firmware files select the “Action” button adjacent to them. Under the dropdown menu select the “Upload” button.
A list of your paired Builder Bases will appear. For each firmware file be sure to upload it to the appropriate client. This means that your Servo firmware should go to the builder base that the servo is connected to, and the LCD+Distance firmware should go to the builder base that the LCD and distance sensor are connected to.
Build the App
Remember: All application and firmware files are available in the resources section below!
If you want to import the app, download it from the resources section and import it. Otherwise, as we describe the logic used in the app, you can follow along and build it yourself.
Here is the Soap Dispenser app:
The first two code blocks are the Distance Ultrasonic and the Value Compare blocks. These are the two blocks that determine wether the soap dispenser is triggered or not. The Distance Ultrasonic block constantly sends distance data into the “Value 1” port on the Value Compare block. If the value sent in to the “Value 1” port is less than the default value of the “Value 2” port the soap dispenser and Countdown sequences will be triggered.
For this we have the “Value 1” port set to trigger the evaluation when new data is received and we have the default value of “Value 2” set to 7.
What this means is that if an object comes within 7 inches of the Ultrasonic Sensor the Soap Dispenser logic will execute.
Once the Value Compare block detects a value less than 7 two Data Sequences objects will then be triggered. One of the Data Sequences handles the Soap Dispenser sequence, and the other handles the LCD Countdown timer sequence.
We will first focus on the Dispense Sequence.
This sequence controls the actuation of the servo. From the port Trigger 1 a static number block is triggered. Once the static number block is triggered it sends a value of 0 to the Servo through the “Degrees” port. This puts the servo in its 0˚ position.
Meanwhile the Timeout block has already been triggered. This block waits 500ms before another Static Number block is triggered. This block holds a value of 180 and once it is triggered it will reset the Servo back to its 180˚ position.
That is the basic logic that allows us to actuate the servo in the proper pulse.
Depending on the configuration you choose for the soap dispenser you might need to adjust the degree positions you send to your servo. You can do this by changing the default values on the Static Number blocks. To do this click on the “Value” ports and change their default values in the properties value on the right. Remember to click the “Save Properties” button on the properties panel, otherwise your changes will be lost!
Now let’s take a look at the two Countdown Sequences:
The code blocks found in the first highlighted rectangle handle the countdown sequence if you opt to use a second servo as your countdown timer.
Timing the countdown using the servo only requires three code blocks. A Ramp Up Beta object, a Manual Ranging object, and a Servo hardware object. The Ramp Up code object outputs an incrementally increasing analog value over a given period of time. So, If 20,000ms is input in the Time port and the object is started the output value will be +4095/20,000, every millisecond for 10 seconds, and the final output value will be 4095.
Configure the Ramp Up object as follows:
Next, the value out port is connected to the value in port on the Manual Ranging code object. We have the manual ranging object setup to covert the analog value to degrees. We do this by configuring the input ports as follows:
This configuration does the following:
Takes values in from 0 - 4095, the range for analog values, it then converts this value range to fit between 0 and 180 degrees. The Out Min is set to 180 and and out max to 0 in order to flip the direction of the servo.
The second rectangle handles the countdown sequence if you opt to use the LCD screen to display the timer.
The countdown sequence triggers the “Time Remaining” Static String code block, this sends the string “Time Remaining” to the String Merge block through the “String A” port.
The sequence then triggers a Static Number block with its value set to 20. This value of 20 is then sent to the Data Counter through the “Value” port, setting the current value of the counter to 20.
Once this happens the value of 20 is then sent from the Data Counter to the String Merge block through the “String B” port, combining strings A and B. String B is set to trigger, so when it receives the value of 20, it outputs the string “Time Remaining: 20” to the LCD through the “String” port on the LCD.
The string is also used to “Clear” the LCD of any other messages. The “Wait to Send” timeout port waits for 100 ms before triggering the “Send to Display” function on the LCD. This ensures that the LCD has been cleared and that the next string has been loaded in LCD in the appropriate sequence.
Once the “Send to Display” function on the LCD has been triggered, the String that was sent to it will appear on the physical LCD.
This process then repeats itself 20 times by use of the oscillator. The oscillator is triggered 20 times in 1 second intervals. Each time the Oscillator oscillates it sends a trigger to the “decrement” port on the data counter. This reduces the value of data counter by 1. Every time a decrement occurs a the new value is sent to the String Merge block, and the whole sequence of Clearing, Writing, and sending a new string to LCD repeats.
While the Oscillator decrements the count every second for 20 seconds another timeout named “20 Sec Timeout” has already been triggered by the data sequence. This waits 20 seconds before clearing and sending the string “Done” to the LCD. Once the string is sent to the LCD a 100ms timeout named “Wait to Send” is triggered. The purpose of this timeout is to make sure the clearing, receiving of string, and writing to the LCD all happen in the appropriate order.
This sums up the logic used in the Soap Dispenser project!
Map the Hardware
You should now be back on the Apps page.
Find your “Soap Dispenser” app and hit the play button.
A list containing all of the devices is your application will expand.
Next click on the “Distance Measurement” device and the client dropdown menu will appear on the right.
Select the Distance driver from the dropdown menu and hit “Done”.
Repeat the same steps for the LCD and the two servos.
Notice how the status symbols have changed to green checkmarks.
Hit “Save + Run”.
When mapping firmware devices to objects in your Apps it is important to note that only devices and objects of the same type can be mapped together. Using this app for example, we are only given the option to map the client with the button firmware to the button object.
Run the App!
Congrats on building the soap dispenser. It’s now time to use it!
Voila! Your soap dispenser project is now complete.