Author Topic: Turn on 12v DC with logic PIC output.  (Read 8900 times)

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Turn on 12v DC with logic PIC output.
« on: August 08, 2013, 06:34:39 PM »
Hi guys

I know my electronics knowledge is massively lacking but we are talking low voltage here so pretty safe for a clown like to be playing around with without too much worry :zap:

I can code PICs at a basic level and something very very simple but I've never successfully tried it, I basically would like to know how I could turn on a 12v supply with a logic 5v output. I basically want a switch on my PIC to acknowledge an input and make a pin go logic high which in turn will turn on a 12v supply to a separate circuit. I can happily code a pic to acknowledge a input and send a pin high on receipt of this signal but I can not then create the external circuit required to switch on the 12v supply.

I'm sure the answer will be using relays etc BUT I'm asking quite specifically, exactly what circuit I would need to use...including components and sizes etc. I know quite often on here I get advice and appear not to take it but that is quite simply because it is going over my head so I admit I need some quite specific help and support here!

Cheers - all advice much appreciated  :nrocks:
Chris

Offline Lew_Merrick_PE

  • Hero Member
  • *****
  • Posts: 690
  • Country: us
Re: Turn on 12v DC with logic PIC output.
« Reply #1 on: August 08, 2013, 07:54:56 PM »
Chris,

Take a look at http://www.digikey.com/product-search/en?v=64&pv72=1&FV=fff40010%2Cfff80368&k=reed+relay&mnonly=0&newproducts=0&ColumnSort=0&page=1&quantity=0&ptm=0&fid=0&pageSize=25 -- they are solid, easy to apply, and inexpensive reed relay units that are easy to stick on PCB's and control things.  The datasheet should make it all clear.

MetalCaster

  • Guest
Re: Turn on 12v DC with logic PIC output.
« Reply #2 on: August 08, 2013, 08:03:19 PM »
In general, you need to find a relay that has a coil that operates at 5 volts (DC I assume), and verify that your PIC has the power to operate the coil of that relay.

This is a mechanical relay solution, others may have a solid state solution.

The same relay needs to have output contacts that are rated for the voltage and amperage you are trying to switch (12 vDC I assume).
For instance, if you are trying to switch 12 vDC at 10 amperes, then don't use a relay with output contacts rated less than 10 amperes at 12 vDC.

A common mistake is to use a relay that has output contacts that are not rated to switch the load, or you try and operate the relay coil, but overload and burn out the PIC circuit.

So two wires out of the PIC to the relay coil, and then loop whatever 12 vDC circuit you are trying to switch through a SPST (single-pole-single-throw) contact on the relay output.  I am guessing that you have a 12 vDC power supply.

Hope this helps.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #3 on: August 08, 2013, 08:27:35 PM »
Yes, it does help a lot!

I'm trying to create a change machine so that £1 is changed into 10x 10p using a fruit machine 10p hopper I've been given.

Apparently I need to supply 12v and a coin is dispenced. When the coin is dispenced an optical sensor sends a pulse output and it is up to my controller to tell it when to turn off.

My idea is to write a micro controller PIC code - coin is dropped in which triggers a micro switch input. This turns on the 12v and a separate input counts 10pulses before it turns the 12v off. Coin validation is a separate part and this all presumes a £1 coin has been inserted.

That is my plan - so the two issues I had were first turning on the 12v supply from my logic high and the second issue I have is trying to find out what sense pulse will be sent from the hopper to the PIc!!

Offline sparky961

  • Hero Member
  • *****
  • Posts: 844
  • Country: ca
Re: Turn on 12v DC with logic PIC output.
« Reply #4 on: August 08, 2013, 08:35:28 PM »
Chris,

Try one of these.  I've used them on lots of projects even if you don't need all of the outputs.  Dead simple to use, and very robust.

http://www.ti.com/lit/ds/symlink/uln2803a.pdf

Note that the output SINKS current, so you are switching the GROUND not the POWER.

MetalCaster

  • Guest
Re: Turn on 12v DC with logic PIC output.
« Reply #5 on: August 08, 2013, 11:06:30 PM »
I have seen some machines with a trap door with microswitch, and when the product drops, it goes through the trap door and actuates the microswitch.

The microswitch could switch perhaps a 5 v (high) or 0 v (low) signal to the PIC.

I am a physical relay guy (from the old days of working on pinball machines, which had relays or relay contacts by the hundreds).
I stopped toying with electronics when it went solid state, but I understand how the solid state stuff works, but just don't have the experience to hook it up correctly.

Sounds like an interesting project.
« Last Edit: August 09, 2013, 12:03:58 AM by MetalCaster »

Offline John Rudd

  • Hero Member
  • *****
  • Posts: 2525
  • Country: gb
Re: Turn on 12v DC with logic PIC output.
« Reply #6 on: August 09, 2013, 04:45:08 AM »
The ULN2803a options looks good, you could just use a discrete transistor (suitably rated) but dont forget the diode across the relay coil....else you will kill the output stage.. :zap:
eccentric millionaire financed by 'er indoors
Location:  Backworth Newcastle

Skype: chippiejnr

Offline ChrisC

  • Jr. Member
  • **
  • Posts: 24
  • Country: scotland
Re: Turn on 12v DC with logic PIC output.
« Reply #7 on: August 09, 2013, 05:05:07 AM »
If you are unsure about electronics, then it might be worth considering using an Arduino for this type of project.  They simply use the USB port to program the boards, the software is free, and is a version of C, easy to learn, and loads of online support.  Most significantly there are a lot of different input output boards available (called shields), which makes interfacing a doddle.  Whilst I design microcontroller based products for a living, I often use Arduino's for quick "proof of principle" models for customers.  Have a look at http://www.arduino.cc/

Chris

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #8 on: August 09, 2013, 06:33:01 AM »
Hi Chris, yes I've played with arduinos and have a duemilanove here somewhere in the house. I've also got microC Easy Pic board .... All that being said, I'm not great with either but enjoy playing!

Even if I use an arduino, I'll still need to use the circuitry being discussed here to turn on my 12v 2A supply - as neither an arduino or a PIC alone will handle this and will only turn on a logic output ...right??

Offline ChrisC

  • Jr. Member
  • **
  • Posts: 24
  • Country: scotland
Re: Turn on 12v DC with logic PIC output.
« Reply #9 on: August 09, 2013, 07:03:54 AM »
Yes you will need additional hardware, but you can buy an off the shelf arduino shield to plug directly onto your arduino board for example http://www.coolcomponents.co.uk/catalog/relay-shield-p-610.html, but there are lots of other similar shields available.  It's not the cheapest route, but it does avoid almost any electronics work!

Chris

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #10 on: August 09, 2013, 07:28:53 AM »
Aaaaaahhhh!! I see your thinking!

Pity I'm no where near as comfortable with arduino BUT I think this could be the way to go!!

I just need to see now what type of signal the hopper gives out when it releases a coin.

Thanks for your suggestion - made me feel a little more confident!

Chris

Offline ChrisC

  • Jr. Member
  • **
  • Posts: 24
  • Country: scotland
Re: Turn on 12v DC with logic PIC output.
« Reply #11 on: August 09, 2013, 08:07:50 AM »
No Problem Chris.  There is loads of help available for Arduinos (and Pics for that matter!), a number of folk on Madmodder have posted Arduino projects.  I find it a bit idiosyncratic, but if you soon get the hang of it.

I recently put together an LED controller for a quick customer demo, it took about a day from start to finish.  Not very pretty, but given that it was only going to be used once, effective.



Chris

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #12 on: August 10, 2013, 08:11:22 PM »
Hey chaps, although I've got my penny pusher build thread, unless the mods say otherwise, I'm going to keep the electronics for this hopper in this thread.

Well the hopper arrived and I've just had time to play with it for the last hour. Took me most of that time to source a suitable connection to try it out at midnight!

Anyway, hooked the 12v line and ground up to my power supply and sure enough it started spitting out 10p coins at a good rate!  :D

So as far as I can see, although the socket is 9 pin, there are only 3 pins I'm interested in. 12v, gnd and optical sense output. The other pins are 24v (which I pretty sure from what I've read is just to give to the option of powering at 24v since that is the source in some machines), two pins for low coin sensing and three redundant pins - all of which can be ignored.

Again from the Internet I have realised that it is the job of the "controller" to count the optical output and therefore how many coins have been dispensed and shut off the 12v supply.


So the big question for me now is how do I read the output of the optical sensor? Will it be a digital 5v pulse and more specifically, if I am using an arduino, what would the code commands be?


As a flow list...the controller will:

1. Input switch "on" (money dropped into machine)
2. Turn 12v on (by turning a pin "on" as discussed above)
3. Count 10 input pulses from optical sensor
4. Shut off 12v

Any help much appreciated!

Chris
 

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #13 on: August 10, 2013, 08:16:25 PM »
http://www.vendapin.com/Adobe%20files/Suzo%20Cube%20Hopper%20Mark%20II.pdf

Clearer details found in the online manual!!

1.5 Coin counting
Coin counting speed is 6 to 7 coins per second. All paid out coins pass by the optical sensor indirectly. The coin exit output changes from high impedance to low impedance status.
This output stays high as long as the hopper is in the “Off” status (power disconnected).
When a coin appears at the counter pawl under the exit bridge the PCB controls the coin verification and releases a logic signal. The opto-coupler and the counter pawl detect paid-out coins.
Payout signal: open collector NPN - active low, maximum sink of 25mA at 35Volt maximum. Minimum time obstructs optics 30ms - minimum.
Time between coins: ±100ms

Offline Bluechip

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 1513
  • Country: england
  • Derbyshire UK
Re: Turn on 12v DC with logic PIC output.
« Reply #14 on: August 11, 2013, 04:12:21 AM »
Hi Chris
 
What you seem to have is the lower left ..
 
The collector is open, so you need to put a load resistor in there connected to +5v.
That is R1. Connected from X to X'. Top left.
This will give you 0V to 5V pulses from the O/P.
560R will allow some 9mA or so current. Well within the 25mA max.
 
As I read it, the O/P is 0v when a coin is present ???
 
If you want a positive level, it needs to be inverted, so the basic single transistor inverter as per right will do the job.
 
Any small signal npn transistor will be OK. Nothing critical about that.
 
Doesn't matter if you input it to a PIC of course, code will take care of that, just poked it in anyway...
 
NB ... the emitter of the opto-isolator may not be connected to 0V if it is truly DC  isolated, so the 0V I have shown connected to it may not actually be connected to 0V in the coin mechanism, so the emitter must be connected to 0V on whatever logic doins you nail to it. Otherwise you will have no 0V reference and the O/P will be heaving and thrashing about all over the shop.
 
Dave
 
 
 
« Last Edit: August 11, 2013, 04:57:11 AM by Bluechip »
I have a few modest talents. Knowing what I'm doing isn't one of them.

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #15 on: August 12, 2013, 07:01:52 PM »
Hi Dave - many thanks for your effort but I am going to go down the microcontroller route since there are a few others uses of the arduino that are going to be in the machine.

I tested the output of the optical line output tonight with my logic probe. I know this is what I was expecting to see, but it was still pleasing to see this happening!!


Offline DMIOM

  • Hero Member
  • *****
  • Posts: 676
  • Country: gb
  • Isle of Man
OT Re: Turn on 12v DC with logic PIC output.
« Reply #16 on: August 14, 2013, 11:40:34 AM »
Chris,

I love the electro-mechanical cross-over - I've never seen anyone attach a test lead with a toolmaker's clamp before! Tiny surface-mount ICs might be somewhat more of a challenge unless Ralph (flyingtractors) has a hand in it!

Dave

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #17 on: August 14, 2013, 01:11:42 PM »
 :) :) :) haha

I thought someone may pick up on that!!  It works so....!

Online awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Turn on 12v DC with logic PIC output.
« Reply #18 on: August 14, 2013, 02:05:01 PM »
It may have been subliminal suggestion, as I saw that picture earlier, but today I was hunting around for a quick temporary way to secure an earth lead to the PLC chassis on that bar feeder I'm working on, and used a small toolmakers clamp !
Andrew Mawson
East Sussex

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #19 on: August 14, 2013, 03:45:54 PM »
It is the way forward. I believe it is not long before they start teaching the use of a tool makers clamp as a means of connecting electrical cables. :med:

 :lol:

Offline raynerd

  • Madmodder Committee
  • Hero Member
  • *****
  • Posts: 2893
  • Country: gb
    • Raynerds Projects - Raynerd.co.uk
Re: Turn on 12v DC with logic PIC output.
« Reply #20 on: August 15, 2013, 01:14:50 PM »
Wahooooo ... it works!


Online awemawson

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 8966
  • Country: gb
  • East Sussex, UK
Re: Turn on 12v DC with logic PIC output.
« Reply #21 on: August 15, 2013, 01:39:53 PM »
Nice one !

When I owned a few launderettes, customers were always wanting me to put in change machines. I vetoed it on security grounds. As you always have to give out exactly the value that your customer has put in there is no profit, hence no upside to count against the inevitable occasional ripping off the wall events!

Something to remember when you install it in the playground  :lol:
Andrew Mawson
East Sussex

Offline David Jupp

  • Sr. Member
  • ****
  • Posts: 308
  • Country: gb
  • Teesside - UK
Re: Turn on 12v DC with logic PIC output.
« Reply #22 on: August 16, 2013, 11:15:36 AM »
Surely if the 'price' is clearly displayed, there is no absolute requirement to dispense same value as is inserted....

People can always choose if your 'price' is attractive or not.

The word 'change' may have some legal implication.

The 'reverse change' machines in supermarkets which 'convert' small change to notes give out only a percentage of face value of the coins that are fed in.