Converting from Arduino based concept to alternative hardware.

Hi, I am working on a project to switch an external relay based on a sensor input.

The attached Nano breadboard setup shows my Arduino based concept.

Basically I will be attaching a remote sensor/switch to the header. Power connections (for sensor) will be added if required.

D9 is the output (to the sensor/switch) and D8 is the input from the sensor/switch.
D7 is an output which will drive a PNP transistor switch, which in turn will power an external 5v (photo-couple) relay connected to the terminal connectors.
D7 will be set to high for 5 seconds if D8 is high.

The project will be battery powered - at present my thinking is 5 volts (6V battery shown).
One objective is to get the maximum possible life out of the batteries - at least one year.
Having read the article on power saving, I am thinking of making a custom pcb with the minimum components required.
Since I only have 2 outputs and 1 input, I am thinking of using an AVR ATTiny45 microcontroller.
Processing speed in not important.

  1. I am looking for guidance on what components (and ratings) I would need to use on a custom pcb to replicate my Arduino setup - see ATTiny breadboard setup (I know 6v battery shown).

  2. Why PNP ?: Unless I am mistaken, from what I can see, on a PNP the "+5v" terminal will be "dead" unless the transistor base is powered. My thinking is that since the transistor output is connected to an external device, this will help to avoid any accidental "short" until power is applied to the transistor base.

Any hints, suggestions, corrections welcome.

A high-side PNP output is a valid option but there are a lot of reasons to choose a low-side NPN output. The primary one is that your output doesn't have to run off the same 5v supply as the Arduino. If the circuit being switched is 12v and you can connect the grounds then you can use that to power the relay coil.

But using coil relays is expensive in terms of power when you are working off batteries. An FET or other solid-state relay could run off a 3.7v coin cell for years and doesn't need the big AA batteries.

Any hints on what the sensor is? What is the duty cycle? What is the relay you've picked out? What are you switching? Does the thing being switched take power from this battery? What is its power consumption?

@MorganS - thanks for responding.

I have attached a pic of the kind of relay I have in mind.
I assumed, maybe mistakenly, that the pictured relay is not an electro-mechanical coil relay, but switching is done by a photo-coupler....?

The relay will switch the supply to a 12V DC motor which draws about 6 amps.
The motor power source is a 12V battery connected via n/o contacts on the relay.
Duty cycle is estimated at 10 operations per day, with each operation of 5 seconds duration i.e. D7 will be held high for 5 seconds following a high detection signal on D8.

The sensor will probably be a proximity sensor. As the application is for an outdoor environment, I am thinking of using an ultrasonic sensor (like HC-SR04) as I believe (from research) that infra-red and daylight do not play well together.

I thought I might take one step back.

I have attached a new breadboard layout giving more of an overview of what I am trying to do.

My focus for now is to get the Arduino concept right.

Am I missing any resistors on my breadboard layout - in particular in relation to the PNP transistor cicuitry?

I don't see why it has to be so complex.

The Arduino can run off 12v, so long as you remember to hook it up to the VIN pin the right way round.

Without looking up the part number that relay board looks like it is a mechanical relay. The power consumption of this is miniscule compared to the motor, so that's no problem.

The relay board also looks like it contains other components to drive the relay. Maybe not an optocoupler but I can see at least one transistor. So you don't need the PNP transistor at all. Just hook it directly to the Arduion output pin. The relay and its associated circuitry takes care of the 12v/5v isolation for you. You should be able to find example circuits from the relay board maker.

The relay module shown is advertised as having an octo-coupler.

Actually I am trying to make it as simple as possible.
I am using the Nano for design and "lab" testing/coding etc.
I will build a field test model using a Mini Pro.
The final item won't be using an Arduino, but a microcontroller chip on a custom PCB.
So to use 12V I would have to include a voltage reduction circuit for the PCB, which I want to avoid.
Based on your comments I am considering replacing the transistor with an octo-coupler to switch the relay, which means we could probably use a cheaper or even mechanical relay since the power source for the relay will be the lead acid battery.

At the moment I have ordered a 5V Mini Pro for field tests.
I am wondering if I won't be better served with a 3V unit.
I guess the one thing to bear in mind is the sensor will be running all the time.
Although I could probably put it to sleep for one second between pulses...need to think that through.

Using a 3.3V Promini with a NPN transistor, or low Rds N-channel MOSFET with low Vgs

to sink current from the relay coil would be fine.

There are many way switching regulators available to supply 3.3V from 12V, for example

or

or

@CrossRoads -Thanks for the input, I will look into your 3.3V design suggestions.

One major factor for the project, since it will be placed in an unattended location, is long battery life.
Whilst tapping 12V from the motor power source to power the sensor control unit may be feasible for use with the Mini Pro field test unit, I am actually designing with the final unit in mind i.e. custom pcb.

Having read Nick Gammon's post on power saving - I have noted 3 important pointers (for Arduinos anyway) viz.

  1. The lower the voltage the longer the battery life.
  2. Turn off IC features u don't need.
  3. There is no point trying to conserve battery if u use components that are just going to suck up power constantly e.g. voltage reducing components.

FWIW the lead acid battery,motor and relay are housed together in an enclosure. Present operation is via a strategically placed (and separately mounted) micro-switch which is mechanically "tripped". The objective is to replace the existing micro-switch with a strategically mounted sensor control unit which will need/have in its own enclosure.

My objective is a barebones design which would be a very basic microcontroller (like ATTiny) on a custom pcb to control the switching of the relay. If I could use a coin type 3V battery - that would be ideal.

Any experience with how long a coin type battery could power an ultrasonic HC-SR04 type sensor?

Note to self : term is Optocoupler and not Octocoupler - even if it has 8 legs (pins) - sorry for error in previous posts.

That relay board only has an opto coupler between the input and the realy coil drivers. The realy itself is mechanical and the design decision of using an opto coupler before this is stupid.

@Grumpy_Mike : Your comments are noted. I accept that the design basis might be stupid, but that is why I am here - seeking guidance.

Now given this forum is supposedly a place to obtain guidance, which I read as constructive criticism, and since you have decided to deride the design, how about being true to the idea of the forum and providing some constructive guidance...?

FWIW I am already working on a redesign. I have decided (for now) to use a 12 V DC electro-mechanical relay with fly-wheel diode and to switch the 12V DC supply circuit to the relay coil (inrush of 70 mA) with one of 3 options :

  1. PNP Transistor Switch
  2. Mosfet Switch
  3. Optocoupler (although this is apparently a stupid idea)

N.B. I will be having 2 different voltages flowing through the switch.

Any guidance as to the best option would be appreciated.

FWIW I am attaching a breadboard of the Optocoupler option - sorry Grumpy Mike I just happened to do this one first. Should the inline limiting resistor be before or after the optocoupler, or is it like LED's where it does not matter?
I would really appreciate comments on the circuit for correctness, just so I know if I am doing this right or not. Suitability is a different story...

Another point to note is I first want t get the concept right, then I will do the various calcs to get the correctly rated components.

I was deriding the design decision of the makers of that relay board not your design.

However if low power is the aim then do not use a relay but a DC SSR. Most SSRs are AC only but you can get power FETs packeges up to act as a DC SSR.

@ Grumpy_Mike. On re-reading your post I now realize I misread it initially - my apologies.

I did previously look at SS relays and found them to be always AC rated.

FWIW I prefer to keep the relay housed with the motor and not part of the sensor controller. As such, I am happy to switch the relay coil supply via the sensor controller but prefer not to switch the motor supply via the sensor controller. I also prefer not to drive the relay from the sensor controller supply batteries, which means it will have to be 12v to be driven from the motor supply battery.

Would you please be so kind as to look at the design in post #10 and give me specific feedback on the merits and correctness of that design.

Given that I will not be switching a high current i.e. only the relay coil, could I use a PNP transistor or P-channel Mosfet to do the switching? i.e. replace the optocoupler in post #10 with a transistor or Mosfet - also using 2 voltages.

I am just not finding any good/clear 2 voltage examples in my mosfet Google searches.
Thanks in advance for any help.

I did previously look at SS relays and found them to be always AC rated.

Include DC in the google search.

Given that I will not be switching a high current i.e. only the relay coil, could I use a PNP transistor or P-channel Mosfet to do the switching?

Why? Just use an NPN it is much easier.

Would you please be so kind as to look at the design in post #10 and give me specific feedback on the merits and correctness of that design.

It is only a physical layout diagram, I would need a schematic. Images posted should be 1000 pixels wide or less so it fits on a screen.

@ Grumpy Mike : I need to find some software to do a circuit diagram. The Fritzing schematics don't work so well for me. BTW the were done as a Fritzing export and it seems to have a mind of its own regarding size. I find the best way to view pics on this forum is to right click and select open in new tab - u can then resize the image to suit in your browser (bottom right hand corner).

I have done more research which indicates I can use an optocoupler or a mosfet or a transistors as a switch.
The other thing I have learnt is that irrespective of what I use as the actual switch, I should couple it with an NPN transistor to protect the microcontroller pin.

So my idea is now to use a PNP transistor as the power switch to the relay coil with an NPN transistor to control the input to the base of the PNP transistor.

FWIW just as personal preference I prefer to source rather than sink switch which is why I prefer a PNP to an NPN switch. My reasoning is simply that by switching the negative (sink) it is more likely to cause an accidental short, which is less likely with a source switch e.g. if replacing the external relay.

Any reason why this approach is not sound?

Eagle is a fantastic program to draw schematic diagrams. They don't look the best but I found Eagle much more effective than other alternatives.

The real advantage of using Eagle is when you do make a custom PCB, everything that's on the schematic ends up on the PCB. You can't forget to put a connection on the board.

For forum discussion, I often use expresspcb.com schematic software, free download and very easy to use, including making a new symbol if needed.

I'm content with my eagle (have various free and full versions loaded) maybe move to Altium sometime.

I use Pro version of Eagle for PCB design work too. Not interested in moving on to something else.
Gettting quite good at making really, I mean really, dense surface mount designs on double sided boards, with parts on both sides. Glad I am not assembling them!

I use Pro version of Eagle for PCB design work too. Not interested in moving on to something else.
Gettting quite good at making really, I mean really, dense surface mount designs on double sided boards, with parts on both sides. Glad I am not assembling them!

Same with me Sir!
using the PRO version, I have been making boards with a min. 0805 package + SMT designs at times with QFN :o micros on em! had been successful many times and failed a few times but learnt a lot.

At times I made both sides SMD too and being clever! in making the boards as I was going to be the one to solder them myself so made boards like on TOP layer had those SMT parts which can't be soldered by hands like the uSD card socket and at bottom layer had those SMT parts which I could solder by hand, so after reflowing the top layer I did hand solder the SMT parts on the bottom layer :wink:

Thanks for the software recommendations.
I did mange to do it in Fritzing, but very annoyingly the program makes changes in to the breadboard when I edit the schematic - so gave up.

Started with ExpressPCB and managed to put something together. problem I see with ExpressPCB is it is really for experts who know the manufacturers and part numbers.
I will probably only be doing one or two projects, so I just don't see myself learning all those part numbers etc.

R1 & R2 will be 100k Ohm.
I need to calculate R3 & R4.
Hoping someone will help with some recommendations for the bipolar transistors.

Nano+Sensor+2Transistors.png