vendo machine using servo motor and multiple coinslot and arduino atmega 168

int pulsePin = 52;
int ledPin = 13;
unsigned long highCounter = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long oldMillis = 0;
void setup() {
   pinMode(pulsePin, INPUT);
   pinMode(ledPin, OUTPUT);
   digitalWrite(pulsePin, HIGH);   
   Serial.begin(4800);
}
void loop() {
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) {
    digitalWrite(ledPin, pulse);
    Serial.println(pulse);
    lastPulse = pulse;
    if (pulse == HIGH) highCounter++;
  } 
  // print and reset highCounter every seconds
  if ( millis() - oldMillis >= 1000 )
  {
    oldMillis = millis();
    Serial.println(highCounter);
    highCounter = 0;
  }

these are my codes for the multiple coinslot im having a problem on how can i program the coinslot and the servo motor . our thesis is school supply vendo machine i need to make the servo move for only 15sec when the coinslot receives a coin . please help us modify these codes.. thanks and also we will be using a push button switch .. need help badly =(

Moderator edit: CODE TAGS AGAIN.

Have you looked (and tried) at the examples for the servo library ?

Incidentally, your code as posted does not compile, probably because of copy/paste Try Auto Format (Ctrl/T) for a clue as to why.

int pulsePin = 52;
int ledPin = 13;
unsigned long highCounter = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long oldMillis = 0;
void setup() {
  pinMode(pulsePin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pulsePin, HIGH);   
  Serial.begin(4800);
}
void loop() {
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) {
    digitalWrite(ledPin, pulse);
    Serial.println(pulse);
    lastPulse = pulse;
    if (pulse == HIGH) highCounter++;
  } 
  // print and reset highCounter every seconds
  if ( millis() - oldMillis >= 1000 )
  {
    oldMillis = millis();
    Serial.println(highCounter);
    highCounter = 0;
  }
}

here i did what u told me.. thanks yup i already tried servo libriary but i cant seem to figure out how to connect the codes for the coin slot and the servo....

Moderator edit: CODE TAGS YET AGAIN. Perhaps a "three strikes and you're out" rule would improve things.

For code use TAGS code (without some parts of code can be show in a wrong manner):

read section 7, please.

im sorry im really new at this things ..

int pulsePin = 52;
int ledPin = 13;
unsigned long highCounter = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long oldMillis = 0;
void setup() {
  pinMode(pulsePin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(pulsePin, HIGH);   
  Serial.begin(4800);
}
void loop() {
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) {
    digitalWrite(ledPin, pulse);
    Serial.println(pulse);
    lastPulse = pulse;
    if (pulse == HIGH) highCounter++;
  } 
  // print and reset highCounter every seconds
  if ( millis() - oldMillis >= 1000 )
  {
    oldMillis = millis();
    Serial.println(highCounter);
    highCounter = 0;
  }
}

simple codes will do ... we will appreciate all the help we can get... =(

Have you tried any of the Servo examples supplied?
What problems did you have with them?

i am having problems on how to make the codes for the servo and coinslot…
it goes like this as we all know how the vendo machine works i cant make the servo rotate when a coin is inserted to the coin slot i am using the normal servo motor… thank you for your help…

So, you need to move a servo when a coin is inserted.

Some questions :

In your current program how do you know that a coin has been inserted ?
You know how to move a servo from the servo examples so can you construct some code that works like this pseudo code

if (coin has been inserted)
  {
    move the servo
  }

You need to define what you mean by moving the servo for 15 seconds. Should it move from its normal position to another position, wait 15 seconds then move back, or something else. Here is some more pseudo code

if (coin has been inserted)
  {
    move the servo to its activated position //HINT this is very like the sweep example for the servo library
    wait for 15 seconds
    move the servo to its normal position
  }

More things to think about. What should happen if another coin is inserted during the 15 second wait ? It is OK to say that it will be ignored as long as that is the desired behaviour but perhaps the 15 second wait should start again.

NOTE the easiest way to accomplish the 15 second wait is to use the delay() function, which I suggest you use to start with, but it prevents any other actions, such as detecting a second coin, whilst the delay() takes place. There are better ways to accomplish the wait such as using the millis() function to let you determine how long the wait has been whilst still doing other things. Once you have got the program working using delay() have a look at the BlinkWithoutDelay example in the IDE to see how to use millis().

i used this codes for the sevo motor to function …

#include <Servo.h> 
 
Servo myservo;  
int pos = 0;     
 
void setup() 
{ 
  myservo.attach(9);  
} 
 
 
void loop() 
{ 
  pos = 360;   
  {                                   
    myservo.write(pos);              
    delay(15);                        
  } 
}

Your delay there is 15 milliseconds, not 15 seconds.
You're three orders of magnitude too short.

That code should make the servo move but a value of 360 is wrong. Look at the description of the servo.write() here Servo - Arduino Reference

Also, the servo will move but will not move back and the delay(15) is irrelevant, nor is it a delay of 15 seconds.
Nor do you need the braces around

  {                                   
    myservo.write(pos);              
    delay(15);                        
  }

yes sir/maam.. i just used the servo code to test it my servo motor will move/ rotate 360 degrees ...

the other question the 15 seconds is span wherein the servo motor should rotate and then after 15 seconds it will stop.. and yes sir that's the logic of it .. we are making a school supply vendo machine...

Thank you for your time....

i just used the servo code to test it my servo motor will move/ rotate 360 degrees ...

It's a fairly rare servo that will rotate 360 degrees.
Is this a continuous rotation ex-servo?

no sir.. we modified our servo we remove the potentiometer we replaced it with a 2.2k resistor..

we modified wrecked our servo

What you have is no longer a servo, it's just a motor with a gearbox and a single wire command interface.

can we still use it in our vendo machine??....
we are planning to use a stepper motor which will be easy to use a servo or a stepper motor?..

thanks

can we still use it in our vendo machine?

How should I know?
You haven't said what it does.

we are planning to use a stepper motor which will be easy to use a servo or a stepper motor?

I don't know which is easier, but one may be more appropriate than the other. Only you know.

hakai_24:
can we still use it in our vendo machine??....
we are planning to use a stepper motor which will be easy to use a servo or a stepper motor?..

thanks

Should the motor (either kind) move to a specific position when activated or should it continue to rotate ?
Should it return to its start position after 15 seconds ?

The answers, together with a general description of your project objectives, will help to give advice.

the servo motor we are using it wont stop rotating ..

our project is a school supply vendo machine .. we are planning to use 4 servo motor so we can vend 4 items bond paper,ballpen, pencil and index card. we are using a multiple coin slot it can recognize a 10 peso coin a 5 peso coin and 1 peso coin.

our main problem is on how to make the servo function when the coin collector receives a coin... the plan is to make the servo rotate until the item falls down.. like a regular vendo machine..
thank you for your time ..
thank you very much...