Coin-O-Matic Token Dispenser

About: Love white padded rooms...

At our office we have a vending machine that can either take real money or tokens. Management decided that we could get some free sweets (within limits) to keep us happy and content with the low salaries that we earning. The problem was, how would you control that? The vending machine belongs to an outside company, so modifications to the vending machine was out of the question.

Enter the Frankenstein Coin-O-Matic, a creation of my sick mind. Deciding how to do this, I thought that RFID tags would be the best, give each employee a RFID tag and keep record of how many time the RFID tag gets swiped. When the tag is swiped, a token get dispensed for use with the vending machine (one free vent). Each time the TAG get swiped, record the information on a SD card. The TAG number is also uploaded to the "cloud" using LoraWAN. I've already been playing with LoRaWAN and thethingsnetwork (TTN) with some temperature and humidity sensors, so we do have a TTN Gateway. The TTN Gateway is a Raspberry PI 3 with a IMST concentrator connected to TTN.

Step 1: Bill of Materials

  1. Some 3mm Perspex
  2. Some 1mm Perspex
  3. Arduino Mega
  4. Arduino Pro Mini
  5. RFM95 Lora Radio
  6. Tiny RTC DS1307 Real Time Clock I2C Module
  7. Graphical Colour 2.2" TFT LCD 240x320 ILI9341
  8. 2 x 4 Channel Bidirectional Level Converters
  9. NeoPixel Ring 24 - RGB LED WS2812
  10. RFID Starter Kit 13.56MHz
  11. ESP8266 ESP12 Test Board WiFi Module
  12. SD Card Module
  13. 5 x Push buttons
  14. 2 x Tri-colour LED
  15. Lots and lots of cable ties
  16. Lots of breadboard jumpers
  17. 40mm x 40mm wood
  18. 2 Channel 5V Relay Module 10 AMP
  19. 5VDC Infrared Light Beam Photoelectric Sensor Module

Step 2: Started Building a Base Out of Wood and Perpex

Started with building a box to house all the electronics from 3mm Perspex, the Perspex and logo was cut using a CNC machine. The front cover of the box houses the screen, buttons and some flashing LEDs. The LEDs are normal tri-colour LEDs that cycle though the colours, see BOM

I then used some 40mm x40mm wooden block to build a place for the coin dispenser and a chute for the token to drop into. The token dispenser consist of 3 Perspex round plates, the top and bottom one are 3mm Perspex and the middle one that carries the token is 1mm Perspex. The way it works is that the middle plate turns and grabs a token from the stack and drags it to the hole in the bottom plate and the token drops into the token chute into the grubby waiting hands of some hungry employee.

The token stacker is a old sprinkler tube that I had laying around and the diameter was exactly the same as the tokens. I drilled some holes in the sprinkler tube so that you could see how many tokens are stacked for refill if needed. The sprinkler tube was superglued to the top Perspex plate.

Step 3: The Token Dispenser

The motor to drive the middle plate is a 220V AC synchronous motor from .... I have no idea, found it in my spares box, as long as it is slow and strong. The shaft was glued to the middle plate with some epoxy glue called Pratex. The relay module is triggered and the live wire is connected to make the motor run. I drilled some holes in the bottom plate to counter friction, if it makes a difference, I do not know. 2 holes were cut on either sides of the middle plate to "grab" the tokens. The diameter of the holes are just a bit bigger than the diameter of the tokens, so that there is some margin for error when grabbing the tokens.

Step 4: Detecting If a Token Was Dispensed

I used a Photoelectric Sensor Module for this, we don't want to ostracise an employee, if he/she did not receive a token after scanning a tag. now would we?. The record is only written to the SD card, when the detection of the token is successful, if no token was detected, the display goes into a rage, blaming the service in the company and that the service sucks.. No record is written in the case where there are no tokens to dispense. I glued the photo transistor to the bottom of the chute so that the token will break the beam when it passes through the beam

Step 5: Electronics

Arduino Mega - This is the brain of the Coin-o-Matic, all the sensors etc are connected to the Mega

Arduino Pro Mini and RFM95 Lora Radio - The Arduino Pro Mini and the Arduino Mega is connected to each other via the serial bus, when a tag is scanned, the tag number is send on the serial bus from the Mega to the Pro Mini. The Pro Mini is in a loop all the time, as soon as something is received on the Pro Mini's serial bus, the tag number is uploaded to thethingsnetwork (TTN) using LoraWan. I have not done any integration on that, but the plan would be to have a AWS instance to store and sort the information. See next step for more information.

Tiny RTC DS1307 Real Time Clock I2C Module - When the Coin-O-Matic boots up, it will log onto the WiFi network and get the time from an NTP server via the ESP8266 ESP12 Test Board WiFi Module and then set the RTC time accordingly

Graphical Colour 2.2" TFT LCD 240x320 ILI93412 - The main display, it normally shows a clock and will give some words of thought to the user

4 Channel Bidirectional Level Converters - As the Mega's digital pins are 5V, I needed the convertors to communicate at a safe level to some of the modules

NeoPixel Ring 24 RGB LED WS2812 - Make some light to daze and confuse the user

RFID Starter Kit 13.56MHz - The RFID reader

SD Card Module - Write the tag number, date and time for each tag swipe

Push buttons - Administrator that has the master tag, will load new tags and I use one of the buttons to pause the display until they can copy the tag number and records who has the tag. The other 4 buttons are wired but not being used at this time

Tri-colour LED - More light to daze and confuse the users

Lots and lots of cable ties - Try and get some order to all the wires

Lots of breadboard jumpers - Wire the stuff up

2 Channel 5V Relay Module 10 AMP 5VDC - The one relay is used to power the coin dispenser motor and the other to power up the ESP8266 module, the ESP8266 module program is in a loop as well, as soon as it get power, it will log onto the WiFi network and do a get NTP time call. To minimize the NTP time calls, I decided to power it with the relay, IE activate the relay, activate the ESP module, ESP module get the time and relay power the module down again... And it makes nice clicking sounds as well

Infrared Light Beam Photoelectric Sensor Module - To detect if a token was dispensed

Step 6: LoRaWAN Sensor Board

The Eagle design files are attached, the board is of my making, but I use a company to produce the board itself. This board can be used as a LoRAWAN sensor board as well, it is extremely small, ~37mm x 54mm, it does cater for a DHT 22 or DHT 11 Temperature and Humidity Sensor as is.

Step 7: TTN - the Things Network

There is a lot of information on this at

https://www.thethingsnetwork.org/

Basically, the Coin-O-Matic talk via LoraWAN (The Arduino Pro Mini with the RFM95 radio) to a gateway (Raspberry Pi with IMST concentrator) that is connected to TTN via the internet, from TTN you can do a lot of integrations, IE Swagger, AWS, http etc, the picture above shows some swipes of tags in the office

Step 8: Software

The software is divided into 3 parts

getNTPtime_instructables - The ESP8266 program, you have to change the ssid, password and ntpServerName before uploading. I use a FTDI basic programmer, connect ground, TX and RX. Remember to choose the ESP module in the Arduino IDE and sort out the pins on the ESP to put it into programming mode

Coin-O-Matic_instructables - The Coin-O-Matic program. This gets loaded on the Arduino Mega, changes needed here is the Master Tag number -

byte masterCard[cardSize] = {121,178,151,26};

pro_mini_instructables - The LoRaWAN program. This gets loaded on the Pro Mini, see schematic for more details on how to wire the radio and which PINs to use. The Device Address, Network Session Key and the App Session Key must be changed after the device registration is done on TTN, if you will be using ABP

static const PROGMEM u1_t NWKSKEY[16] = { };s]

static const u1_t PROGMEM APPSKEY[16] = { };

static const u4_t DEVADDR = 0x; // <-- Change this address for every node!

Step 9: Boot Up

The video shows the relay being activated (relay 1), the ESP8266 module logs onto the WiFi Network, send a getNTP time signal and gets the time from the NTP server, after the time was successfully updated, the relay deactivates and remove power to the ESP8266. If something goes wrong and there is no successful time update, the Arduino Mega reboots and tries again. The ESP8266 module and the Arduino Mega is connected to each other via the serial ports (Serial2 on the Mega), The Arduino Mega listens for a answer from the ESP8266, the message looks like this "UNX[and the epoch time stamp]", I'm in GMT+2, so in the Arduino Mega code, I add GMT+2 as follow

time_t gmtTimeVar = newTimeVar+7200;
rtc.adjust(DateTime(gmtTimeVar));

Step 10: Adding/removing a Tag

The Master tag is scanned and the display indicates that this is the master tag. The new tag is scanned and the tag number is displayed on the screen and it gives the user time to take down the number and records who has the new tag. The tag number will be written to the database as soon as the user presses the left button. The same procedure is followed to remove a tag from the database

Step 11: Some Videos Showing the Operation of the Coin-O-Matic

I used node-red to integrate with Telegram, node-red has a integration module to TTN, so what happens when you scan a tag?

  • Tag is scanned
  • txt file on SD card is read to see if it is a valid tag
  • If the tag is valid, a time stamp with the tag number is written to a txt file on the SD card
  • The tag number is send via LoRaWAN and the Raspberry PI Gateway to the TTN network
  • Node-red subscribes to the MQTT messages at the TTN network
  • Node-Red send the decoded HEX to DEC tag number to a bash script file running on a server locally
  • The bash script scans a txt file with TAG NUMBERS and NAMES
  • The bash script file uploads the message to a Telegram BOT with curl containing the TAG NUMBER and the person's name

Nice and complex, I love how such a simple task becomes soooo complex

Let me know what you think in the comments below

PCB Contest

This is an entry in the
PCB Contest

Share

    Recommendations

    • Toys Contest

      Toys Contest
    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest
    • Epilog X Contest

      Epilog X Contest

    2 Discussions

    0
    None
    WynandJ1

    5 weeks ago

    Thank you!