We’re working on an automated car washing machine project and have the following components: an Arduino, jumpers, a coin acceptor, buttons, and a power source to run everything.
Here’s the situation:
We’ve connected all the components with jumpers and written a working Arduino code using the Arduino IDE. On some days, everything runs smoothly and synchronizes perfectly. However, on other days, even though the setup (jumpers, Arduino, code, and components) remains exactly the same, we face issues.
The main problem lies in coin recognition. Specifically, our code currently supports recognizing 3 types of coins (pennies), but this part frequently malfunctions.
Has anyone experienced similar issues with inconsistent behavior in Arduino projects? Could it be related to hardware (e.g., jumpers, power source, coin acceptor) or perhaps the code itself? We’re open to any suggestions to troubleshoot this issue.
Please select all code in post #3, click the <CODE/> button and save the post. This will make it easier to read and copy and the forum software will display it correctly.
If the coin acceptor does not recognize differences in coin size or weight, or have the mechanism to "weigh" a coin (the new TL being aluminum, and floats on water), problems will occur.
sorry i'm a newbie here i edited it with code tags, so i think problem is not in the coin acceptor because you first adjust the coin acceptor itself with how much pulse it gonna give you for each penny, in our case: 1 impulse for 10 penny, 2 impulse for 20 penny and 3 impulse for 50 penny, when you insert a coin in coin acceptor works perfectly it recognizes every coin with certain impulses but however in the arduino ide(in serial monitor) it don't displays it correctly. So as i stated in the first post it’s like this:
one day, we gather to test everything, and everything works perfectly. Feeling happy, we go home. The next day, when we meet again for final checks, we face issues with coin recognition. We adjust the code accordingly, everything works, and we go home happy again.
This cycle has been repeating for a week now.
you are right but all the hardware things are with my friend so i can't post hardware stuff now, we will try to get all things fixed up today maybe we will buy some new arduino or jumpers i don't know. Because as i said in first post someday all the things works perfectly and another day not so i think the problem is in our hardware because "code" is a static thing, there is no such thing as working one day and not working the next
Btw nothing runs hot.
When we connect the coin port to the Arduino with a cable and measure the pulses, we randomly receive values like 3000 pulses. We are using CH 926 coin acceptor, can someone write a basic code for getting up balance for certain pulses like, 1-10,2-20,5-50,
or just modify our code `#include <TM1637Display.h>
#define COIN_PIN 2 // Coin acceptor sinyal pini (Interrupt destekli olmalı)
#define CLK 3 // TM1637 Clock pini
#define DIO 4 // TM1637 Data pini
TM1637Display display(CLK, DIO);
volatile int pulseCount = 0;
int balance = 0;
void coinInterrupt() {
pulseCount++; // Gelen pulse sayısını artır
}
void setup() {
pinMode(COIN_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(COIN_PIN), coinInterrupt, FALLING);
display.setBrightness(7); // Ekran parlaklığı ayarı
display.showNumberDec(balance);
}
void loop() {
if (pulseCount > 0) {
delay(200); // Gürültü engellemek için kısa bir gecikme
int count = pulseCount;
pulseCount = 0; // Pulse sayacını sıfırla
// Gelen pulse sayısına göre bakiye ekleme
if (count == 1) balance += 10;
else if (count == 2) balance += 20;
else if (count == 5) balance += 50;
display.showNumberDec(balance); // Bakiyeyi ekranda göster
}
And the second step is to properly deal with your volatile variable. Assuming you are using an UNO, you can not atomically deal with a 16 bit value while interrupts are enabled.
void loop() {
noInterrupts();
int count = pulseCount;
interrupts();
if (count > 0) {
delay(200); // Gürültü engellemek için kısa bir gecikme
noInterrupts();
pulseCount = 0; // Pulse sayacını sıfırla
interrupts();
...
You're right, I missed that pinmode(), sorry. But I (almost) always prefer to use external resistors, and googling around about this device (even on this very forum) the arduino built in pullup resistor looks like it works but the readings cannot be precise enough to make sure the count is the right one, especially on longer cables.
First of all, what is the exact model ot the coin acceptor? I see there are at least two versions.
Then, how it's powered and connected to Arduino? It's a 12V device, are you sure the power adapter you're using is correct for the device?
And are you sure you correctly programmed the coin acceptor? See here.
Lastly: to help us help you, please, always, always include the complete code. You missed an "#include" statement, and a closing bracket. And help us also by translating your comments in english to make it easier to read...
Anyway, as far as I can see that's not exactly the way to deal with a coin acceptor like that (even if I never used that CH926), and I don't like much the use of delay().
Impulses belonging to a single coin are close apart, so if enough time has passed after the last impulse we can assume that all incoming impulses were received and we have a proper number of impulses recorded in the variable and we can determine which coin was inserted.
This can be accomplished in many ways, one is the following (I wrote it "on the fly" so it's up to you to test it):
#include <TM1637Display.h>
#define COIN_PIN 2 // Coin acceptor sinyal pini (Interrupt destekli olmalı)
#define CLK 3 // TM1637 Clock pini
#define DIO 4 // TM1637 Data pini
// Minimum ms to detect a pulse "pause"
#define PULSE_PAUSE 100
TM1637Display display(CLK, DIO);
volatile int pulseCount = 0;
// Time of last pulse received
volatile unsigned long tmrLastPulse = 0;
int balance = 0;
void coinInterrupt() {
pulseCount++;
tmrLastPulse = millis();
}
void setup() {
pinMode(COIN_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(COIN_PIN), coinInterrupt, FALLING);
display.setBrightness(7); // Ekran parlaklığı ayarı
display.showNumberDec(balance);
}
void loop() {
if (tmrLastPulse > 0 && millis() - tmrLastPulse >= PULSE_PAUSE) {
// Ok, we can go on checking the pulses received
int count = pulseCount;
tmrLastPulse = 0;
// The following statements depend on the coin acceptor programming
if (count == 1) balance += 10;
if (count == 2) balance += 20;
if (count == 5) balance += 50;
// Show the result
display.showNumberDec(balance);
}
}