Introduction: Build Your Own Electronic Pencil Dispenser

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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

Picture of 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!

Comments

bugattiblack (author)2017-04-25

Does anyone know the dimensions of the body, it would be very useful.

Adginito (author)2016-08-04

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

mattkimbennett (author)2016-04-13

Any idea what is cost to build?

Any chance you'd build one to sell?

JulioS47 (author)mattkimbennett2016-07-29

I am in the process o finishing one up. I have an estimate cost of $70 dollars. right of the top of my head.

JulioS47 (author)2016-07-29

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.

David Erian (author)2016-01-01

Awesome !! I have just a small question... What is the mechanism to drop only one pencil not more each time?
Thank you

DustyA2 (author)2015-11-25

hmmm....thinking you might be from MCHS?

missewon (author)2015-10-25

I've got to ask... are you a fan of Orphan Black? :D

SomyaG (author)missewon2015-11-04

I've never watched it. Should I have?

missewon (author)SomyaG2015-11-05

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!

sunnys33 (author)2015-10-21

Good luck Saumya

swagmonster (author)2015-10-21

THIS IS SICK BRO!

theoddballkid (author)2015-10-15

cool!

SomyaG (author)theoddballkid2015-10-20

Glad you liked it

Jmehta32 (author)2015-10-19

Great somya!!! Keep it up

SomyaG (author)Jmehta322015-10-20

Thank you!

DaleW6 (author)2015-10-18

Sorry am i missing something?
How does the stepper work with no number of steps in coding??
It would run forever.

SomyaG (author)DaleW62015-10-18

Yes you are right. Around the whole code are pieces of code which are commented out. These are for the photoelectric sensor meant to sense if a pencil has come out of the machine or not. This code is not necessary and can be replaced with precise rotations in steps.

Bentley_Maniac (author)2015-10-15

BTW, which code language are you using? I'm learning python, and while it bears some similarities, it has a slightly different syntax.

possibly one of the C languages?

SomyaG (author)Bentley_Maniac2015-10-15

Yes it is C with modifications from Arduino with a bunch of other features and functions. It has been adapted to work better with hardware than just with itself and other software. Not too hard to learn either.

Bentley_Maniac (author)2015-10-15

please, adapt it to sharpen the pencils as you put them in the top....

SomyaG (author)Bentley_Maniac2015-10-15

Haha, thats the next part of it!

Raphango (author)2015-10-15

Niiice!! =D

aj.oyfo.rever (author)2015-10-08

A friend of mine built one in high school 30 some years ago. 100% manual and mechanical. Worked great with only a couple of critical machined parts. More like an old parking meter with a twist knob on the front.

SomyaG (author)aj.oyfo.rever2015-10-11

That's pretty cool

HarneetS (author)2015-10-09

Good work Somya

amberrayh (author)2015-10-06

Wow, this is really neat! Thanks for sharing how you made it.

SomyaG (author)amberrayh2015-10-07

Thank you very much!

ArchibaldC (author)2015-10-07

Amazing project!

SomyaG (author)ArchibaldC2015-10-07

Thanks Mort!

Gadre (author)2015-10-07

Awesome project dude! Just take care of some spellings on some of the images :D

SomyaG (author)Gadre2015-10-07

Thank you! I will fix them right away.

Kevmaster007 (author)2015-10-07

This is awesome!

SomyaG (author)Kevmaster0072015-10-07

Thank you!

About This Instructable

26,455views

313favorites

License:

Bio: Hi, I am a normal high schooler who likes to build electronics and programming, play video games, and open to trying new technology.
More by SomyaG:Build your own Electronic Pencil Dispenser
Add instructable to: