MEGA 2560 powering 12V Electromechanical Counter

This is probably a very simple question for someone who knows who they're talking about, but I don't.

I am looking to use an Arduino output pin from a MEGA 2560 via a transistor to switch a 12V Electromechanical Counter (http://www.esr.co.uk/manuals/c-8409.pdf).

As far as I am aware, the schematic for this output should be very simple, and I've drawn it as I think it ought to be below (the VIN at the top is 12V):

As with anyone new to things like this, my question is actually a series of questions, and I would be grateful if you could aid in any of them.

  1. Are there any problems with the schematic?
  2. Do I need the protective diode, or can I simply use a resistor?
  3. As a power supply for the 12V rail, I need to use something pretty small because it's all going to be housed in a small area; if I use 8 AA batteries or an A23 battery, is the battery life going to be incredibly short? Given that there's a transistor, I was hoping that current will only really be drawn when it's in use and will therefore allow quite a long battery life span.
  4. What are the calculations I need to make to work out the resistance of the resistor?
  5. Any particular NPN Transistor I should buy?

Thank you very much in advance for your help.

Stephen.

Hi Stephen,

The diagram/design is OK.

What is the current drawn by / resistance of the counter coil? How long must current be applied for it to mechanically count? GUESS: .05 to .1 seconds.

The diode is needed to absorb the "reverse EMF" Spike from the inductance of the counter coil when it is turned OFF. This should be no problem unless you need to count several times per second. What is the maximum count rate you expect.

The Transistor can be any small NPN like 2N3904 unless the current is greater than 200 mA or so, and the on-time is longer than .1 seconds or so.

The resistor can be 220 to 270 ohms or so to limit the current from the Arduino pin.
See Arduino pin limitations here: http://arduino-info.wikispaces.com/ArduinoPinCurrent (Follow to MEGA)

Battery life: You need to add up the current (mA) times time over an hour to get mA/Hours used, and compare to mA/Hours of your battery.

You may want to search for "Arduino Sleep" and "Wake on Interrupt" of you want really long life and the counts are infrequent.

Hi Terry, thanks for your quick response.

According to the fairly limited information on the supplier's website (Electronics - Modules), it has a 'maximum counting rate' of '18 per second', so yes, around .05. The device is a set of LDRs installed in the surface of a bench that will count the people that sit on the bench via an arduino, and there are ten LDRs, so I can imagine the likely maximum amount of people sitting on the bench will be ten in a second anyway, and I suppose I'll hence need a diode.

The power drawn by the unit is 3.5W so from P = VI, I guess it's something like 0.3A of current drawn? Which makes the Resistance around 40 Ohms?

A pulse from the Arduino sent as a HIGH value for Pin 9, for example, ought to be enough to operate the device, yes?

Thank you also for your tips on battery life, I'll check them out. Incidentally, there shouldn't be a problem running the arduino itself off a 9V battery in terms of the pin outputs, should there? This is what I intend to do.

Thank you again,

Stephen,

Would this transistor be suitable: http://uk.rs-online.com/web/p/general-purpose-transistor/7390341/ ?

Hi, Your diagram shows an NPN transistor not PNP..

This is probably good: http://uk.rs-online.com/web/p/general-purpose-transistor/7390385/

A higher-power version: http://uk.rs-online.com/web/p/general-purpose-transistor/7390329/

A pulse from the Arduino sent as a HIGH value for Pin 9, for example, ought to be enough to operate the device, yes?

Yes, I would suggest a delay of about 75 ms : delay(75); when the transistor is ON. Try that and test...

You have more than 10 Digital Inputs available; you can use the Analog inputs (A0..A5) as digital inputs too. Each LDR can have a pullup resistor to +5V and the junction of the resistor and the LDR (to ground) to an input. So light = no one sitting on it = 0 and dark (Someone sitting) = 1. You'll need to pick that resistor value depending on the incident light and the LDR characteristics. Put one in place and test the resistance with a meter..

a problem running the arduino itself off a 9V battery

Hmm. if you mean a small 9V "Transistor" battery, maybe it's OK..but probably not if you need to run 24 hours..
Maybe better to run the 12V into Vin and use the onboard regulator. Maybe. How long battery life do you need?

Sorry, yes, didn't even check to make sure it was NPN - good catch! Thanks.

Currently I have my code as follows:

const byte numberOfSensors = 10;
const int THRESH = 200; // Threshold value
const byte counterPin = A10; // Counter pin

const byte ldr_pins [numberOfSensors] = { 
  A0, A1, A2, A3, A4, A5, A6, A7, A8, A9};
int now [numberOfSensors] = { 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
int then [numberOfSensors] = { 
  1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000};
int val [numberOfSensors] = {
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0};

void setup()
{
  pinMode(counterPin, OUTPUT); //Sets Counter to OUTPUT
  pinMode(13, OUTPUT); //Sets Pin 13 the LED to Output
  Serial.begin(9600);
}  // end of setup

void loop()
{

  // read sensors
  for (int i = 0; i < numberOfSensors; i++)
    now[i] = analogRead(ldr_pins[i]);

  // check each one
  for (int i = 0; i < numberOfSensors; i++)
  {
    // change over threshold?
    if (abs (then [i] - now[i]) > THRESH)
    {
      Serial.print ("Someone ");
      if (now [i] > then [i])
      {
        Serial.print ("sat on");
        digitalWrite(counterPin, HIGH);  // hit counter
        val[i]++;
      }  
      else
      {
        Serial.print ("got up from");
      }  
      Serial.print (" seat number ");
      Serial.println (i);
      Serial.print ("So far, the amount of people who have sat on seat number ");
      Serial.print (i);
      Serial.print (" is ");
      Serial.println (val[i]); 
    }  // end of over threshold

  }  // end of checking each sensor

  // remember for next time
  for (int i = 0; i < numberOfSensors; i++)
    then [i] = now [i];

  delay (100);  // brief delay
  digitalWrite(counterPin, LOW);

}  // end of loop

Thinking about the amount of time this is going to have to be running (all day, but not 24hr, for three months), I think I'm probably going to have to be looking at running it off a car battery to get the kind of longevity I need, if I run it off a battery at all.

I've just been told, however, that we can specify a power outlet as necessary, so let's assume I'm running it all from the mains. How do those connections work? I can plug the Arduino straight into the mains with the regular adaptor, and I assume I need a 12V adaptor for the Counter?

This is exhausting! Thank you so much for your help.

Hi,

Power: Line power would make this a LOT easier. Example: http://goo.gl/OPzZr
You can run the Arduino with that. It will not draw too much current itself.

I would make a direct connection to the 12V Counter (I assume it is important to have that visible to someone??)

Connect the - end (emitter) of the switching transistor to GND on the Arduino (near the Vin pin).

Also, I suggest you control the ON time of the counter coil in one place so that the time Serial output takes is not a factor. I would put it right where you turn it ON, Like this:

digitalWrite(counterPin, HIGH);  // hit counter
delay(75);
digitalWrite(counterPin, LOW);

I would suggest you test this first with only the Pin13 LED being turned on and off, not the Counter, make sure stuff works. Divide and conquer..

The rest of code looks good, without being able to run it here...

Let us know how this works out...

DISCLAIMER: Mentioned something from my own shop...

Yeah, I had the idea of getting two 12VDC >500mA adaptors and cutting the 2.1mm plug off one and directly wiring the counter up to one, as you say.

I was a little hesitant to put 'delay' in the program simply because there's always the possibility that two people will sit down at (observably) the exact same time, and if the Arduino's having a little sleepy for 75ms whilst it tells the counter about one of the guys, it might miss the other one. Though, I suppose with the current code, if it's observed on the next run through, it will also be picked up? I'm a little shaky on how the arduino will deal with this.

Thank you for your help; I'd buy your class two transformers as a thank you, but I'm in the UK =(

Hi,

Look at "Examples>Digital>Blink without delay" in your Arduino IDE... You don't have to block things...

This is all about figuring stuff out; the Thank You is when you tell us all how it worked later, so other people will learn from it...