Object counter « counting box »

A capacitive sensor will NOT detect a plastic bag passing by. Non-conductive materials are generally not detectable by such as sensor.

It may however detect the metal bits in the jewellery, depending on how much metal is in there and how sensitive it is. It also requires a capacitor that is designed to detect proximity, not touch.

wvmarle:
A capacitive sensor will NOT detect a plastic bag passing by. Non-conductive materials are generally not detectable by such as sensor.

<>

Capacitive sensors are used for non-contact detection of metallic objects & nonmetallic objects (liquid, plastic, wooden materials and so on).

Of course plastic does affect the electric fields.
A little.
If there's enough plastic.
Covalent bonds in the plastic will help a lot.
Thin polyethylene bags? Won't work.

Hi,

I’ve started to build the circuit, and i’m facing the 1st issues i didn’t think about.
With the 7-segment with 3 digits, i’m using 11 pins on the arduino. Then with the 3 buttons (reset, +1, -1), and the ir sensors, it’s minimum 4 pins additionnal (and more if i use more IR sensors...). But the arduino only has 12 pins available.
I was checking on the internet, and i found a way to reduce the amount of pins used for the 7-segments from 11 to 7 pins, using a 7447.

But it would still be ready sharp for amounts of pins.

  • is the 7447 solution good, or is there a most recent way to do it, or easier or cheaper ?

  • is there a way to reduce even more the amount of pins needed, that they all fit on the arduino without any restrictions ?

For information, i'll be using an Arduino Nano (i don't have any other), but i guess it will be enough for this.

Thank you,

The MAX7219 display driver is mentioned often here. It's a serial interface requiring only three Arduino I/O pins.

Sounds great.
I’ve checked on google, and found a tutorial on how to configure it (plaisirarduino.fr or Arduino MAX 7219 CNG Basic Circuit : LED, 7 Segment Displays)
I just bought on ebay the MAX7219CNG.

I’ll use a 10kOhm resistor, but not yet the 2 capacitors proposed (it seems like it’s only to have a more stable signal, so it will be in phase 2 for all improvements :slight_smile: )

Also : i had to buy a new 3-digits 7-segment, as mine was Anode and it seems like the MAX7219CNG only accepts Cathode. Too bad :frowning:

I’ll try to build the circuit on Fritzing, to document all of this, and also start checking the Arduino code.

Hi,

Attached the Fritzing schematic from this project.
I've tried to make it as easy to read as possible.

Can somebody validate it, or tell me what to change/improve ?

Thank you,

It's a very nice looking drawing but, (sorry) for a circuit of more than a few connections it becomes very difficult for someone not familiar with the thing to decode what they're seeing. This is because with all the components out there, some with tens of pin connections, it's nearly impossible to tell just by looking how something is wired up. Most experienced people are used to looking at schematics where the parts' pins are named & numbered so you can see at a glance what's connected to what. Here's an example from Maxim's site:

This emphasizes the Maxim part but it illustrates the principle. A full schematic would include all connections, with pin names/numbers, for *all *components. Unfortunately this would also mean expanding signals grouped into a single line for brevity like the digit and segment lines in the drawing.

Even a hand-drawn schematic including the pin names/numbers is better in this case than a pictorial and would, IMHO, get more responses and allow people to see more exactly how you've made all the connections and so give an informed response.

Yes, it's more work but it would be a useful experience. Besides, you'll need a real drawing to work from and to have available for future reference. There are choices of drawing software but I use the free ExpressSCH.

Agreed, totally unreadable. Especially as the MAX7219 and display pinouts are not given. So can't tell whether the connections are correct or not.

No decoupling cap at the MAX7219. That's an issue.

Ahah, i guessed you would answer that it’s unreadable :slight_smile:

I’ll try to make a more readable one, following your advices.

Also, i’ll add the 10 uf electrolytic and 0.1uf(100n) ceramic capacitors, as it seems like it’s mandatory to have them.

Would that be ok ?

Thanks,

The 100n one yes - all digital ICs need one. You can also see one in the reference circuits of the datasheet, p.12/13.

The 10u, where did you find this? I don't see an obvious need for it, but that doesn't mean it's not necessary.

Great, thank you. I can even see where to install it :slight_smile:

For the second capacitor, i found it there :

Honestly, i trust more what you say than any website. So if you say only the one for 100 nm is enough, then i’ll only install this one :slight_smile: I need to order it too :slight_smile:

I’ll update the Fritzing sketch, but that might take some days. In between, i’ll start with the Arduino code, as now i know exactly which components i use, so i have all ly inputs/outputs.

Trust the manufacturer's data sheet; not what random people (including myself) tell you on the Internet.

Just checked the link - and found one major issue in the image where they have the two capacitors, and that's with the physical layout.

The 100nF should be placed physically as close as possible to the pin. That wire is a pretty bad thing here, it adds stray induction which in turn negates a lot of the effect of that cap. The 100 nF should go between the GND bus and the strip the Vcc pin is connected, when placing it on a breadboard (and even closer when you're using a proper PCB - there are chips that have the GND and Vcc power pins next to one another, soldering a 0805 package on top of those two leads is then the ideal placement).

Adding a 10µF electrolytic capacitor won't hurt, anyway. Just try it out.

If you order components you may consider adding a pack of 20 x 10 values of electrolytic, and 20 x 30 values of ceramics. Something like that. It's just very convenient to have those values on hand even if you end up not using half of them, they're really cheap so it's not much of a financial investment.

Awesome, thank you for the advise. I’ll take care of it when i’ll have all components to make the physical layout.

Hi,

I was writting the code, everything was going well until i got this error message : Exit status 1, Error compiling for board Arduino Nano.
Do you know what can be the problem ?

Below the code (not finished yet, as i'm still checking how to display the numbers with the Max7219+7segments) :

#include "LedControl.h"
LedControl lc = LedControl(4,5,6,4);

// ----- Code for Change State for FC-51
// this constant won't change:
const int  PinFC51 = 2;    // the pin that the pushbutton is attached to
const int  PinButtonPlus1 = 3;    // the pin that the pushbutton is attached to
const int  PinButtonMinus1 = 4;    // the pin that the pushbutton is attached to
const int  PinButtonReset = 5;    // the pin that the pushbutton is attached to
const int PinLED = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonStateFC51 = 0;         // current state of the FC51
int lastButtonStateFC51 = 0;     // previous state of the FC51

int buttonStatePlus1 = 0;         // current state of the button
int lastButtonStatePlus1 = 0;     // previous state of the button

int buttonStateMinus1 = 0;         // current state of the button
int lastButtonStateMinus1 = 0;     // previous state of the button

int buttonStateReset = 0;         // current state of the button

int FC51 = 0;
int ButtonPlus1 = 0;
int ButtonMinus1 = 0;
int ButtonReset = 0;


// ----- Code for Max7219 + LEDs
int count = 1000;


void setup()
{

// ----- Code for Change State for FC-51
  // initialize the button pin as an input:
  pinMode(PinFC51, INPUT);
  pinMode(PinButtonPlus1, INPUT);
  pinMode(PinButtonMinus1, INPUT);
  pinMode(PinButtonReset, INPUT);
  
  // initialize the LED as an output:
  pinMode(PinLED, OUTPUT);
  
  // initialize serial communication:
  Serial.begin(9600);

// ----- Code for Max7219 + LEDs
    lc.shutdown(0,false);
    lc.setIntensity(0,5);
    lc.clearDisplay(0);
}

void loop() {

// if FC51 changes the state, it does +1
ChangeStateFC51();
if (FC51 == 1) { 
  Plus1();
  Update7segment();
  FC51=0;
  }

// if PushButtonPlus1 is active, it does +1
PushButtonPlus1();
if (ButtonPlus1 == 1) { 
  Plus1();
  Update7segment();
  ButtonPlus1=0;
  }

// if PushButtonMinus1 is active, it does -1
PushButtonMinus1();
if (ButtonMinus1 == 1) { 
  Minus1();
  Update7segment();
  ButtonMinus1=0;
  }

// if PushButtonReset is active, it resets to 0
PushButtonReset();
if (ButtonReset == 1) { 
  Reset();
  Update7segment();
  ButtonReset=0; 
  }

}

void ChangeStateFC51() {

  // read the FC51 input pin:
  buttonStateFC51 = digitalRead(PinFC51);

  // compare the buttonState to its previous state
  if (buttonStateFC51 != lastButtonStateFC51) {
    // if the state has changed from low to high, increment the counter otherwise don't
    if (buttonStateFC51 == HIGH) {
      FC51=1;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonStateFC51 = buttonStateFC51;

}

void PushButtonPlus1() {
  
  // read the pushbutton input pin:
  buttonStatePlus1 = digitalRead(PinButtonPlus1);

  // compare the buttonState to its previous state
  if (buttonStatePlus1 != lastButtonStatePlus1) {
    // if the state has changed from low to high, increment the counter otherwise don't
    if (buttonStatePlus1 == HIGH) {
      ButtonPlus1=1;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonStatePlus1 = buttonStatePlus1;
  
}

void PushButtonMinus1() {
  
  // read the pushbutton input pin:
  buttonStateMinus1 = digitalRead(PinButtonMinus1);

  // compare the buttonState to its previous state
  if (buttonStateMinus1 != lastButtonStateMinus1) {
    // if the state has changed from low to high, increment the counter otherwise don't
    if (buttonStateMinus1 == HIGH) {
      ButtonMinus1=1;
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonStateMinus1 = buttonStateMinus1;
  
}

void PushButtonReset() {
  
  // read the pushbutton input pin:
  buttonStateReset = digitalRead(PinButtonReset);

  // compare the buttonState to its previous state
  if (buttonStateReset = 1) {
      ButtonReset=1;
    }
    // Delay a little bit to avoid bouncing
    delay(50);

}

void Plus1()
{
  
}

void Minus1()
{
  
}

void Reset()
{
  
}

void Update7segment() {

// ----- Code for Max7219 + LEDs
    String t = String(count++);
    lc.setDigit(0,0,(int)(t[0]-'0'),true);
    lc.setDigit(0,1,(int)(t[1]-'0'),false);
    lc.setDigit(0,2,(int)(t[2]-'0'),false);
    lc.setDigit(0,3,(int)(t[3]-'0'),false);
    delay(100);
    lc.shutdown(0,true);
    lc.shutdown(0,false);

}

PS : If you find already something wrong in the code (not linked to this issue), you can already let me know :slight_smile:

Why don't you post the whole error message? The problem is in the part you didn't post... the part where the compiler tells you what happened.

Here is the full error message :

C:\Users\xxx\Documents\Arduino\libraries\LedControl\src\LedControl.cpp: In function 'setDigit.constprop':

C:\Users\xxx\Documents\Arduino\libraries\LedControl\src\LedControl.cpp:169:1: internal compiler error: Segmentation fault

 }

 ^

Please submit a full bug report,

with preprocessed source if appropriate.

See <http://gcc.gnu.org/bugs.html> for instructions.

lto-wrapper.exe: fatal error: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.21.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avr-gcc returned 1 exit status

compilation terminated.

c:/program files/windowsapps/arduinollc.arduinoide_1.8.21.0_x86__mdqgnx93n4wtt/hardware/tools/avr/bin/../lib/gcc/avr/5.4.0/../../../../avr/bin/ld.exe: error: lto-wrapper failed

collect2.exe: error: ld returned 1 exit status

exit status 1
Erreur de compilation pour la carte Arduino Nano

Hope it will help more :slight_smile:

"internal compiler error"

That's about the last I expected to see! Exit status 1 is most commonly an undeclared variable, or closing } missing, something like that. Tbh no idea how to handle this one. Nasty. You just ran into a compiler bug.

Nagaro:
Please submit a full bug report,

with preprocessed source if appropriate.

See http://gcc.gnu.org/bugs.html for instructions.

I would: not alter this code at all. Save a copy of the code which produced this error and supply the information requested as above.

Hi,

I actually found on a forum on arduino a workaround for this bug (which is a compiler bug, you’re right. I changed the Arduino AVR Boards from version 1.6.23 to 1.6.21 in the preferences, and the issue doesn’t appear anymore.
I’ll anyway submit the issue via the link as dougp proposed, and continue to write the code. And let’s see if the support team will solve the issue, that i can come back to the newer version of the Arduino AVR Board.