Arduino Coin Jar
Thievery no more! .. providing the thief is unfamiliar with electricity.


Ingredients
Arduino Nano
Elegoo PIR Motion Sensor Module
Elegoo Keypad
Elegoo Piezo Module
Elegoo RGB LED Module
Elegoo Relay Module
MG995 Servo
Transformer
Florescent Ballast
Neoprene Gasket Sheet



Notation(s)
1. Iris aperture print modified from (AcE_Krystal) https://www.thingiverse.com/thing:3563742
2. +/-3 days remain in the MacroFab and Mouser Useless Machine Contest - https://macrofab.com/blog/macrofab-design-contest-useless-machine-sponsored-by-mouser-electronics/ -- attempting to squeeze this one under the wire.
3. 150$ borrowed wood faux CTC Prusa i3 has finally begun to act normal - ie - poorly. TLC could only last so long before reaching its temperamental (terrible) twos.
4. For .. uh .. forgot to put in a power supply hole. (>_ლ)
5. Find code much simpler to ponder when the entirety of the project is constructed. As a right hemispheric individual -> dislike coding immensely.
6. Lesson having learnt from the toilet air freshener - distanced the high voltage furthest from components so as to prevent interference - and regardless - some residual was found flickering the servo. Does plain white PLA conduct?!
7. Here is some common sense frequently ignored - filming white PLA on white tables on white backgrounds ... stop it for fricks sakes!



Beep Boop Code
// Arduino Coin Jar
// Vije Miller

#include <Keypad.h>
#include <Password.h>
#include <VarSpeedServo.h>
VarSpeedServo jar;

// Pins
int piezo = A2;
int red = A3;
int green = A4;
int blue = A5;
int relay = 2;
int jar_pin = 3;
int pir = 4;

// Keypad
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {5, 6, 7, 8};
byte colPins[COLS] = {9, 10, 11, 12};
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

// Set Passcode
Password passcode = Password( "947" );

// States
int closed = 88;
int opened = 30;
int open_state = 0;
int pir_state = 0;
int motion;

void setup() {

Serial.begin(9600);

// Pin Placements
jar.attach(jar_pin);
pinMode(piezo, OUTPUT);
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(pir, INPUT);

// Keypad Listener
keypad.addEventListener(keypadEvent);

// Close Jar
jar.write(closed, 200, true);

// No Buzz
noTone(piezo);

// No Zap
digitalWrite(relay, LOW);

// Activate
// Form of Coin Jar
while (millis() < 2000)
{
digitalWrite(blue, HIGH);
delay(50);
digitalWrite(blue, LOW);
delay(50);
}

digitalWrite(green, LOW);
digitalWrite(red, HIGH);
pir_state = 1;
}

void loop() {
keypad.getKey();
motion_sensor();
}

void keypadEvent(KeypadEvent eKey) {
switch (keypad.getState()) {
case PRESSED:
Serial.println(eKey);
button();
switch (eKey) {
case '#': check_passcode(); break;
case '*': passcode.reset(); break;
default: passcode.append(eKey);
}
}
}

void check_passcode() {
if (passcode.evaluate()) {
if (open_state == 0) {
open_coin_jar();
passcode.reset();
} else if (open_state == 1) {
close_coin_jar();
passcode.reset();
}
} else {
digitalWrite(blue, LOW);
digitalWrite(green, LOW);
while (millis() < 2000) {
digitalWrite(red, HIGH);
delay(50);
digitalWrite(red, LOW);
delay(50);
}
}
}

void open_coin_jar() {
pir_state = 0;
digitalWrite(green, HIGH);
digitalWrite(red, LOW);
digitalWrite(relay, LOW);
jar.write(opened, 200, true);
open_state = 1;
}

void close_coin_jar() {
jar.write(closed, 200, true);
open_state = 0;
pir_state = 1;
}

void motion_sensor() {
if (pir_state == 1) {
digitalWrite(red, HIGH);
digitalWrite(green, LOW);
motion = digitalRead(pir);
if (motion == HIGH) {
digitalWrite(relay, HIGH);
delay(1000);
digitalWrite(relay, LOW);
}
} else if (pir_state == 0) {
digitalWrite(red, LOW);
digitalWrite(green, HIGH);
digitalWrite(relay, LOW);
}
}

void button() {
digitalWrite(red, LOW);
digitalWrite(green, LOW);
digitalWrite(blue, HIGH);
tone(piezo, 1000);
delay(250);
digitalWrite(blue, LOW);
noTone(piezo);
}

Archive
https://hackaday.io/project/167302-arduino-coin-jar
https://hackaday.com/2019/09/06/high-voltage-protects-low-denominations/

@pkvi
"...may not meet professional standards."
12,138 miters
5 miters today
202 tenons
Subscribe