Introduction: Vending Priest
Made this vending priest with Arduino Uno, ISD1820 sound recording module, fishing pole sections, and two servos.
Used a limit switch inside plastic jar to take the money. Don't really expect anyone will want to make one but will include schematic to show how switch turns on servo routine and sound card.
Step 1: Two Servos to Operate Arm
One servo pushes arm up and down and the second servo right and left.
Step 2: Build Vending Machine Switch
I just used a limit type push button switch inside a plastic jar. When you push coin through slot it depresses the switch.
Step 3: Wire Up Boards, Switch and Servos and Program
Schematic shows how to connect electrical components.
(Whoops! The 1k resistor should go on ground side of switch, not on the signal side.)
Here is code:
#include servo.h
Servo servo1,servo2,servo3; //int potPin = 2; // select the input pin for the potentiometer int servangle = 0; // servo angle variable int potPin = 4; // select the input pin for the potentiometer int soundPin = 4; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int val = 0; // variable to store the value coming from the sensor int valPot2 = 0;
int valInc = 4; int currAngle = 0; int newAngle = 0; int delayTime = 0; //Analog read pins const int buttonPin = 2; int buttonState = 0; // variable for reading the pushbutton status void myServo(int curAngle,int newAngle,int angleInc,int incDelay,int servoNum) { if (curAngle < newAngle) { for(int angle=curAngle;angle < newAngle;angle += angleInc) { if (servoNum == 1) servo1.write(angle); if (servoNum == 2) servo2.write(angle); delay(incDelay); } } else if (curAngle > newAngle) { for(int angle=curAngle;angle > newAngle;angle -= angleInc) { if (servoNum == 1) servo1.write(angle); if (servoNum == 2) servo2.write(angle); delay(incDelay); } } }
void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT //pinMode(buttonPin,INPUT); pinMode(buttonPin, INPUT); pinMode(soundPin, OUTPUT); servo1.attach(9); delay(10); myServo(90,75,1,10,1); servo2.attach(11); delay(10); myServo(90,90,1,10,2); delay(2000); }
void signOftheCross() { digitalWrite(soundPin,HIGH); delay(2000); digitalWrite(soundPin,LOW); //myServo(50,75,1,15,1); myServo(90,75,1,10,1); delay(500); myServo(90,120,1,15,2); delay(1000); myServo(120,70,1,15,2); delay(1000); myServo(70,90,1,15,2); //delay(500); myServo(80,40,1,15,1); delay(100); myServo(50,105,1,15,1); } void loop() { //Serial.print(" buttonpin= ");Serial.println(digitalRead(buttonPin)); val=1000; Serial.print(" delay val= ");Ser buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); delay(3000); signOftheCross(); delay(1000); } else { // turn LED off: digitalWrite(ledPin, LOW); }
//cli(); //delay(5000); }