Introduction: Build Your Own Electronic Pencil Dispenser
Hello, I am going to demonstrate the steps required to build the electronic pencil dispenser as shown in the picture above. I built this thing for my school during my spare time and I thought that it would be cool if someone else tried to make it also. Thanks and I hope you try it out. (Video is not the final version with all the new stickers in the picture.)
P.S : Also, if you could VOTE this for the contest at the top of the page it would be helpful.
Step 1: Gather the Materials
First off, we will start with the List of all the materials that I have used. You can substitute anything out if you would like to improve on the machine, but this is what I had laying around.
Straw Dispenser(Pencil Dispenser)-
Straw Dispenser used to hold the pencil. You can make your own mechanism but this was easiest because I already had it.
E12-T2N1-
This photoelectric sensor is used to detect if the dispenser is out of stock in pencils. This can be replaced with a smaller sensor if you want.
Arduino Uno-
The Arduino is a micro-controller which controls all the functions of the dispenser.
Coin Acceptor[CH-923 SINTRON]-
The coin acceptor takes coins and converts them into values read by the Arduino by pulses.
LED (One red, one green)-
These are used to indicate whether the machine is on, and if it is out of stock.
DC 3 Wire Diffuse Type NPN NO Photoelectric Sensor-
This is used to detect whether or not a pencil has fallen.
Some of the materials are not listed. These are minor parts which you can change up. Make it your own. Also things like wires, soldering iron, resistors are also not listed.
Step 2: The Dispenser
I started by holding down the acrylic dispenser by screwing two metal pieces over the bottom part of the dispenser. Drill holes through the bottom part of the the encasing you are using and us the holes in the metal pieces (you can drill some if need be) to put your screw and nut into . Drilling directly into the Dispenser is not ideal because it was hard to get a drill into so this was very convenient. (Last Screw was covered up so no picture)
Step 3: The Stepper Motor
Next, we will screw the stepper motor down onto the base also. The shaft of the motor should be somewhat aligned with the end of the turning rod inside the acrylic dispenser. This is so we can run a pulley system to turn the rod and dispense a pencil.
To attach the plastic pulley to the shaft of the dispenser, just place it between the knob and the screw and tighten it. It holds on pretty well and you don't need any other adhesive
Step 4: Cut Out the Front Facing Part of the Enclosure
Cut two rectangular slots. One for the coin acceptor and one at the bottom for the pencils to come out from. Also drill two holes on the top right for the two leds.
Step 5: Insert a Ramp for the Pencil to Roll Down
To make this just cut some acrylic and put two pieces at the end to create a stopper for the pencils using another sheet of acrylic and use acrylic glue. Then insert the ramp under the part where the pencils will fall from. (Before doing this you will have to sand down the original stopper of the pencils if you used the dispenser in the picture. If you have questions just ask.)
Glue a platform made of acrylic to the front of the dispenser. Line it up to where your coins fall, then make a box out of anything such as cardboard.
Step 6: Drill Two Holes Just Big Enough for the Photoelectric Sensor
Put the sensors in and hold them in place with the nuts. Put them as low as possible so the fewest pencils are left when it goes out of stock. Line them up to the best of your ability.
Step 7: Get Your Arduino Board
Set up your arduino. Get the IDE from their website. Make sure your board is uploading programs and working properly. I used Arduino Uno but you can use other Arduino board if you already have one.
Disregard the configuration of wire in the arduino, I was testing something else with it. Also, I am using a spare one and not the UNO in the actual build for the photo.
Step 8: Start With the Motor
So now its time to get the stepper working. Take the driver that we are using and start to solder the wires in these places:
1. For the four wires coming out of the stepper motor, you have to solder them in this order:
The red and yellow are a group and go into the two holes marked as A
The gray and green go into the two holes marked
Solder all of these in place
2. Now for the step portion of the driver
Solder any wire in any order into the three. The one labeled as GND will go to ground and the other two will go to ports in the arduino, so we will worry about all three later.
3.The last part is giving the driver 12 Volts and Ground. For the 12 volts I used an old laptop charger and cut the head off. The outer wire is ground and the insulated middle wire is the positive. Use a female to male wire to plug in the pins on the driver(or you could just solder them)
To test it you can go and use the accel stepper library and upload a default program. Here is the download of the library.
Step 9: Wiring Up the Sensors
Use this diagram to wire up the two photoelectric sensors. DIAGRAM
The whole image of the circuit also has the wired up stepper.
NOTE (I have soldered the whole circuit onto a prototype board)
After you power up the two sensors, you can see if they are working by looking at an led on one of the sensors. Put your hand or something between them and the led should work.
Step 10: Time to Set Up the Coin Acceptor
To start this off, you are going to want to connect the ground and the power pins to a 12 volt supply(same as the two sensors). It should beep and the led should light up. After that, look at the manual in the box with the acceptor and follow the steps to set up the coins you wish to use.
Step 11: Install Lock and Drill Away Wood for Wire Space
To put in the lock, I took a circular drill bit and made a hole just big enough for it to fit into. Then I installed the lock and cut a slot in the side of the other piece of wood so the lock would turn into it.
Chisel a space for your wires to go under the door of the box you assembled.
Step 12: Put in the Pencil Detector
This part is going to stop the stepper after it insures a pencil has dropped. The three wires coming out from the back are as follows :
Brown : Positive(+)
Black : Signal
Blue: Negative(-)
Attach a 330 ohm resistor(Orange, Orange, Brown) to the Brown wire. Then, take the wire and give it 12V from the power supply. Ground the negative to the supplies negative.
Step 13: Now We Are Going to Connect All the Pins to the Arduino Interface
1. The one signal wire coming from the two photo sensors are going to connect to pin number 5
2. The Dir from the stepper driver goes to pin 9 and the Step goes to pin 8.
3. The white wire coming out from the coin acceptor goes into pin number 2
4. A led that I am using will just connect to 5v and ground(Power light)
5. A out of stock led will go to ground and pin 13.
6. Connect the Ground from the power adapter(12v) to a ground port in your arduino. This will ground everything together(photoelectric sensor, coin acceptor)
Step 14: Upload This Code Onto Your Board
//Parts of this is commented out for the infrared diffuser that will be placed in the instructions later #include <AccelStepper.h> //#define IRPIN A0 // Pin for the input from infrared diffuser int ofs = 5; // pin for out of stock sensor int led = 13; // out of stock led const int coinInt = 0; // interrupt pin number (insert the wire into pin 2 in arduino) int pencilDispensed = 11; volatile float coinVal = 0.00; // set to volatile for the interrupt function(so it is properly updated) int coinIn = 0; AccelStepper stepper(1,9,8); void setup() { Serial.begin(9600); stepper.setMaxSpeed(3000); stepper.setSpeed(3000); attachInterrupt(coinInt, coin, RISING); pinMode(ofs, INPUT); pinMode(led, OUTPUT); //pinMode(IRPIN, INPUT); } void coin() { coinVal = coinVal + 0.05; coinIn = 1; }void pencil(){ Serial.println("Pencil"); } void loop() { int outofstock = digitalRead(ofs); if(outofstock == 1){ digitalWrite(led,HIGH); } else{ digitalWrite(led,LOW); } if(coinIn == 1) //Check if coin has been inserted { if(outofstock == 1){ coinIn = 0; } else{ coinVal = 0; //while(!digitalRead(pencilDispensed)){ stepper.runSpeed(); //} coinIn = 0; } } }
Step 15: Done
If you have any questions don't hesitate to ask!

Participated in the
First Time Author Contest
36 Comments
Question 1 year ago on Step 8
Looks good. Will be making this soon. What model/brand of stepper motor did you use for the Build Your own Electronic Pencil Dispenser? It's not on the list of supplies. Thanks. Greg
4 years ago
What stepper motor did you use???
4 years ago
Here is the manual pencil vending machine
Question 4 years ago on Step 15
Just finished a manual pencil machine. I would like my next one to be electric. Is there a way to allow two pencils to drop?
6 years ago
Does anyone know the dimensions of the body, it would be very useful.
7 years ago
Hello,
Where can I find a metal box like that? I'm not sure if there is a specific name for it or if it is from another vending machine but I'd love to know where they are from.
Thanks
7 years ago
Any idea what is cost to build?
Any chance you'd build one to sell?
Reply 7 years ago
I am in the process o finishing one up. I have an estimate cost of $70 dollars. right of the top of my head.
7 years ago
Hello, I am in the process of building this instructable. I think is really neat. But I have a couple comments that I think will help improve the clarity of this instructable. First the diagram shows motor cables oin a different setp than what i found on the drivers site: schmalzhaus.com. And second the code only works with the while statement uncommented. at least with the wire setup that i have.
one last thing. I have had a great deal of trouble making the stepper turn for exact ammount of steps. If you could point me towards the right direction I would appreciate it. i tried stepper.move(200); but it would not move.
7 years ago
Awesome !! I have just a small question... What is the mechanism to drop only one pencil not more each time?
Thank you
7 years ago
hmmm....thinking you might be from MCHS?
7 years ago
I've got to ask... are you a fan of Orphan Black? :D
Reply 7 years ago
I've never watched it. Should I have?
Reply 7 years ago
Well, yes, but the joke here is kind of gruesome. I'd say if you like action, adventure, sci-fi & humor, you might like it!
7 years ago
Good luck Saumya
7 years ago
THIS IS SICK BRO!
7 years ago
cool!
Reply 7 years ago
Glad you liked it
7 years ago
Great somya!!! Keep it up
Reply 7 years ago
Thank you!