Hi, so im a noob at arduino and stuff, so I am asking for help on a very simple project.
I want to have a candy in a tube, and a servo arm blocking the candy from falling out. I want to be able to press a button, and have the servo move, let candy fall out, and then move it back. so far i have my servo on pin 8(subject to change), and my pushbutton on pin 2(also subject to change). I have my servo powered by arduino. My pushbutton is on breadboard, with one pin connected to the 5v rail of my breadboard, and the other connected by jumper wire to pin 2(subject to change). My servo's control wire leads to pin 8(subject to change), the +5v leads to the +5v on my breadboard, and my servo's gnd is connected to ground on the arduino directly. (And yes, i have connected 5v and gnd rails on breadboard to arduino.) I have been working on this project for ages, and have spent about 3+ hours just working on code, with no avail. I would have done the fritzing buisness and all, but i have no clue how to do that.
My pushbutton is on breadboard, with one pin connected to the 5v rail of my breadboard, and the other connected by jumper wire to pin 2(subject to change).
Change that so that the button is between the pin and ground instead. That way you can use INPUT_PULLUP for the pinMode and you won't need any external resistor for the button. This will mean that the button reads LOW when pressed and HIGH when not pressed.
My servo's control wire leads to pin 8(subject to change), the +5v leads to the +5v on my breadboard, and my servo's gnd is connected to ground on the arduino directly.
That's a good way to burn up your Arduino. Your servo shouldn't pull it's power through the Arduino board. Give the servo it's own power.
I have been working on this project for ages, and have spent about 3+ hours just working on code, with no avail.
And if you want to know what you did wrong or how to fix it then you're going to have to post the best failed attempt you have so we can see what you need help with.
I would have done the fritzing buisness and all, but i have no clue how to do that.
Please don't. everyone hates fritzing. It's so hard to see what is going on in those stupid things. Just draw a picture and post it here. Keep it simple, pen and paper.
Thanks for the tips. Do you mind posting some example code, as I have just started arduino 2 weeks ago, and have barely any Idea how i would code that.
Have you worked through the examples using buttons and so forth? StateChangeDetection in particular
would be useful?
Oh! I haven't thought of that! Thanks!
I can see how it might be useful, but I really don't know how to use it, so i think i will stick to for, while, and if loops so far.
Work through the examples built in to the IDE (file menu / Examples). Start at the beginning. The same examples are also discussed in more detail here.
Some of them deal with reading input from a pushbutton switch which is relevant to your project. The one on debouncing will probably be helpful. There's one about Input Pullup that Delta mentioned earlier in this thread. Blink without delay will teach you an important technique: how to time events without using the problematic delay() function.
When you've worked through those, you'll probably be ready to tackle the state change example that Mark mentioned.
Also, relevant to your project, there's a library for controlling your servos, and like most libraries it comes with some useful examples.
People will help along the way but I don't think they'll be interested if you don't seem to be putting any effort into learning yourself.
I love candy, are you portioning the candy before dispensing it?
Just opening and closing servo will give random results for a product that likes to stick to itself as much as candy does.
Now you have me thinking of Arduinoing my own classic coin candy dispenser.
With a stepper turning a wheel with one candy-size slot you could make a low-parts-count gum machine. Patience, the servo part is coming up.
When the slot is under the candy only 1 piece can fit. When the wheel turns any more candy is blocked and when the slot is down the candy falls.
Important part is there's slot and block. Instead of a vertical wheel, a horizontal wedge with a hole for candy and no-hole area to block can move back and forth to get candy then drop it down an exit to the side of the tube. Where the candy drops from tube to slot there needs to be a "floor" since the slot has to be open all the way through since it won't get turned upside down.
@Slumpert: I will be dispensing smarties, so they will not stick.