Component Counter

Hi All

I have just started a new job and one of the first things I have been asked to do is finish a project the previous guy started. Well after looking through the box of bits I have come to realise the project was never started. I have the following Items.

Arduino Uno R2
Arduino Ethernet Sheid
A small Red RTC Module
Sparkfun Electronics ADM2004D LCD unit
LEDS, resisters, cables.

They all look very nice, unfortuantly I dont have the slightest idea what to do with them.

What my employers told me is that the project is to be used to count components and monitor the state of the production line.

After further investigation I found some notes that the other guy left and his idea was.

Have a photosensor connected to the Arduino UNO, everytime a component went past the UNO it would increment its total by one and would show this on the LCD screen, if there was a pause of 60 + seconds between counts the LCD screen was to display Production Stopped and a Red LED would light, when a component passes again then it would light a green LED and continue to count. The UNO would also be connected to the Network, after every 5 components counted it would send this to a database on the network, if production stopped it would send whatever it had counted to the database along with the time the production stopped, when production starts again it sends this time to the database and so on. He also has a note that there must be some sort of redundancy so that if the UNO loses network connection it continues to store the information on an SD card and sends all the information to the database once the network is back up and running, also displaying Offline on the LCD.

I dont even know if what my employers are looking for is possible with the above, but any help will be appreciated.

Cheers

Dj

Sounds like a dream job.
I wish I would get paid for doing this...................

What you described above makes perfect sense and it is totaly doable.

It is doable, but I wouldn't say it was a beginners project.

Probably an ir laser and an ir led would make a great tripline for components to pass and count accurately, or an ir emitter/reciever and notice the difference in brightness as someting passing
idk what the rtc module could be used for, the arduino has enough accuracy to check a minute, and ur missing the sd module, although it can talk to one without you'll just have to do some level shifting

Definitely not a beginner's project, especially when

dont have the slightest idea what to do with them.

I think to help best, it would be good to know: What's your background? How versed are you with electronics? Programming (C++)? Computers in general?

It would be frustrating to say the least to explain how to build such a system to someone with no technical prowess whatsoever, but if you're an engineer that's just never used an Arduino, that's absolutely doable. We can short-track you to a working understanding.

@winner10920 The sensor will be a Photoelectric sensor as we use them with most production counting components via PLC, also the Ethernet Sheild has a built in SD card reader.

@SirNickity I am a Computer Engineer, dealing mainily with Networks and Software support, I do however program in VB.net and know back end databases very well. I have done some C++ in the past but got lazy and program mostly in VB although converting to C++ wont be to much of a stretch, I have also worked with various PLCs (Seimens, Alan Bradley, Omron ect) and have programmed them, although in the past most the electronics work I left up to my Engineering Department.

converting to C++ wont be to much of a stretch

Just remember that you only have 2kB of RAM available.

2k, so badly written c++ coding wont help then :slight_smile:

Is there currently a working prototype or is there nothing yet? (do you have code to post)

What kind of sensor is used to do the counting?
What is the number of the RTC? ds1307?
other components..

Please mail as much info as possible to get better help.

@robtillaart I was handed a box of components and an idea, hooked uno to PC and there is no code, if the other guy had code its long gone. I dont have a sensor for it yet as I am not sure of the power outpt of the Arduino, we have lots of 20v+ photoelectric sensors in stores but to use them with the UNO think I will have to use a seperate PSU for the sensor which I want to avoid. Everything I was given is listed below.

Sorry forgot to say the RTC chip says ds1307

I work a lot with industrial controls. Specifically PLC's but with some uProcessors added to the mix. Mostly PIC's but I am trying to get our engineer to consider switching to the Arduino.

Anyway this project sounds tailor made for a PLC system. Although what you have will work, due to the industrial nature and your background in PLC's would it make more sense to use an Omron or Keyence laser sensor which operates at 24v? The components would be a little more off the shelf and replacement would likely be less time consuming. I personally deal exclusively with Automation Direct PLCs which I are cheaper and easier to program . These types of components are designed to mount in an industrial environment whereas an IR sensor and detector would be more challenging. You could still use an Arduino with these types of sensors through transistors but...

As far as coding the Arduino, my background is VB6 with the move to VB.net about 2 years ago. I have dabbled in C# and avoided C++ like the plague yet I find the transition was very easy to the Arduino IDE as long as you remember the {} and the ;

I guess the company chose Arduino over PLC to save some money.

@Florinc From what I have been told this is just a test / prototype unit for something they are looking at doing, so yes the Arduinio is cheap. As we use Siemens PLC the ethernet module alone for a siemens PLC is around £150 then the PLC depending on type is £500++ then you would need either a SCADA or HMI system for any kind of integration to a backend so we are talking thousands and a PLC is overkill for 1 sensor. Everything below cost arpund £80 to buy, so a no brainer either on the company side, unfortuantly I would not agree as I am the one having to try and figure this out. ]:slight_smile:

The best thing you could do is start with some simple projects to get used to the Arduino ecosystem. Try some of the Ladyada tutorials or browse the Arduino playground.

Get the IDE installed and build up a simple button-and-LED sketch to light the LED when you press a button. And change the state from off to on with a button press. That'll get you used to the pin manipulation, basic electronics stuff (though you may already have that, from your description), and get you used to the C++ world.

Then, connect up the LCD and start using it. Press a button and have it increment a variable and display the result on the LCD. Move on to echoing serial input from the monitor console (in the IDE) to the LCD.

Once you've got that, throw in the RTC. Get the date/time and make a clock with the LCD. Use a button to change AM-PM / 24-hour mode, or cycle through date and time displays.

By then, you should be pretty comfortable with the fundamentals. Throw on the Ethernet shield and get the SD examples working. Read and write a file. Get card info.

Then, give it an IP address and ping it from your network. Set it up to listen on telnet (tcp/23) and echo back text that you send.

Build your own web server with HTML buttons to turn on an LED. Have it include the date/time from the RTC. Have it display something on the LCD (like "received HTTP POST from 10.1.1.100").

After you've done all of that, you're ready to start introducing your optical detector. You've been through SD, Ethernet, LCD, and digital I/O stuff, so you can work out your circuits and sketch to do what you originally wanted to do with the thing.

It's just building blocks. One at a time. Don't get overwhelmed, hang out around here, ask questions, and post your progress. What you're looking to do isn't difficult at all, but there's a learning curve with anything. The folks on this board are the most helpful, tenacious, understanding group I've ever seen on the Internet. As long as you take a little initiative, someone will darn near co-build the thing with you just for fun.

@SirNickity Thanks for your post, its very helpfull, I am on holiday for a week next week so I am going to take the stuff home and have a play as I am not getting a chance at work to have a play. I will take your advice and take it a bit at a time and post my results or problems.

Hi All

Ok I have been playing around with tutorials and stuff, and have done the basics, playing with LEDs, Buttons, LCD, also been playing with the inbult timers, so getting an LED to blink every 20 seconds ect without using delays.

I am having a few problems with buttons though and its mainly todo with my terrible coding in C

int switchPin = 2;             
int val;                        
int buttonState;              
char prodStatus;


void setup() {
pinMode(switchPin, INPUT);   
Serial.begin(9600);         
Serial.println("Production Stopped");
prodStatus = 1;
}
void loop(){
  val = digitalRead(switchPin);    if (val != buttonState) 
  {     
    if (val == LOW) 
    {
    if (prodStatus == 1) 
    {        
      Serial.println("Production Started");
      prodStatus = 2;
    } 
    }
  }
   if (val != buttonState) 
   {
    if (val == LOW)
    {
    if (prodStatus == 2) 
    {        
    Serial.println("Production Stopped");
     prodStatus = 1;
    }
   }
  }
  
 buttonState = val;               }

I found some of the code from an example, but basically what I am trying to do is you push the button and depending on the prodStatus it either displays "Production Started" or "Production Stopped", however what is happening is when you press the button it display "Production Started" then immediatly "Production Stopped" on a single button push, I also found sometimes the button works and sometimes not at all. So looking for a little help improving my terrible code to make my buttons work a lot better.

Also I have realised that using the LCD, several buttons, LEDs, Sensor and the ethernet sheild I am out of pins, so I searched the forums and google and seen users using an MCP23017 to put LEDs / Buttons and LCD onto its inputs/outputs then only using 2 on the UNO. Unfortuantly I cannot make head nor tail of some of the examples so was just wondering if anyone has an idiot guide to using these chips, specifically using it with an LCD as I found a box of these chips in the egineering supplies.

Cheers

Dj

Thank you, We have been recently trying to find info about this topic for a long time and yours is the better I actually?ve discovered at this point. :slight_smile:

I found some of the code from an example, but basically what I am trying to do is you push the button and depending on the prodStatus it either displays "Production Started" or "Production Stopped", however what is happening is when you press the button it display "Production Started" then immediatly "Production Stopped" on a single button push, I also found sometimes the button works and sometimes not at all. So looking for a little help improving my terrible code to make my buttons work a lot better.

Sounds like a debounce issue, you should find plenty of help on this topic searching the forums. There is a library (buttons?) that will do it for you. For a simple fix though, put a delay(20) after you detect a transition to let the switch settle.