I am attempting to build an alarm to prevent theft on a vending machine. I am using the Arduino Uno board. Today I put together the project and I've encountered a few issues. I admit I am very much a "noob" on this so I could really use some suggestions from someone with more knowledge..... Here is my situation.....
I'm sure everyone knows how a candy/snack vending machine looks. People put in money and push A1 or B2 or whatever snack they want and then the candy drops into the bottom of the machine at the dispensing tray..... Well we run into a problem with people sticking hands into the dispensing tray, reaching up into the machine, and stealing items without paying.
As of today we have installed an IR Proximity Sensor about 6 inches above the area that dispenses product from the vending machine. This was done to trigger an alarm when people stick their hand in this area and steal the product without paying for it. It is connected to an Arduino Uno which is mounted inside the machine and a buzzer was installed on the Arduino Uno as well.
The problem however, is that we do NOT want the alarm to trigger when people purchase the product and the purchased product passes by the IR Proximity Sensor when it is drops into that dispensing area. So we were trying to find a way to disable the IR Proximity Sensor whenever people actually make a purchase
Here is what I did to "TRY" and disable the IR Proximity Sensor when people purchase products from the machine -- Since there are 12 different product choices on the machine, and all 12 of the choices have an individual mechanical arm that pushes the product into the dispensing area when purchased, I wired 12 reed switches in series with the Voltage wiring for the IR Proximity Sensor. My thought process behind this was if someone tried to reach their hand in to the dispensing area and steal product, the IR Proximity Sensor would trigger. However, if someone legitimately purchased one of the 12 products in the machine then the 1 of the 12 reed switches would OPEN the circuit when the mechanical arm began moving to push the product out of the machine and by OPENING the circuit that would open the voltage connection to the IR Proximity Sensor therefore disabling the sensor and bypassing the alarm.........
As far as the code I programmed on to the Arduino for this, see the attached screen shot photo of the code. I have never written code before and I don't completely understand it, so this code is something I found via a Google search just for a basic PIR / Buzzer setup for Arduino.
The problem we ran into in doing what I described above, is when a product is purchased and 1 of the 12 reed switches open the circuit, that does NOT bypass the alarm like we wanted. It turns out that when the reed switch opens, killing the voltage to the IR Proximity Sensor, that instantly triggers the alarm...... Not at all what we were hoping for!
So I have several thoughts on this situation and I don't know if any of my thoughts are realistic possibilies for solving the issue...... If anyone with much more knowledge of the Arduino code wiring could please provide some feedback on the following.....
#1. Is there some type of code to be added that would NOT trigger the alarm when the voltage to the IR Proximity Sensor is cut? We only want the alarm to trigger when the IR Proximity Sensor is actually interrupted.
#2. If I removed the 12 reed switches that are series together to the IR Proximity Sensor's voltage wiring, would I be able to move that series of reed switches to other pins on the Arduino, completely separating them from the IR Proximity Sensor, and set up some type of code that would tell the Arduino that if the reed switch circuit opened then to IGNORE / DISABLE the IR Proximity Sensor's trigger signal for a period of maybe 5 seconds or so?? I figure in doing that the 5 second delay will allow the purchased (not stolen) product to pass through the IR Proximity Sensor's field without triggering the alarm.... What would the code be for this if it is possible?
If neither of those 2 scenarios are possible, any other suggestions are welcome..... and p.s. I know installing a camera to prevent theft solves all of this but for some reason the owner of the machine refuses to do that, lol.
The current code I have programmed is as follows. And again, since I don't know how to write code, this is just something I found via a Google search.
const int buzzerPin= 12;
const int inputPin= 2'
void setup () {
pinMode (buzzerPin, OUTPUT);
pinMode(inputPin, INPUT);
}
void loop () {
int value= digitalRead(inputPin);
if (value == LOW)
{
digitalWrite(buzzerPin, HIGH);
}
}
The IR Proximity Sensor works perfectly fine in triggering the alarm buzzer with that code above. The problem is specifically when these reed switches get involved.