Have I built myself into a corner?

Hi guys,

I may or may not have got myself into a corner here and need some expert advice.

I have six 4 relay boards that i was hoping to control with the mega 2560.

Each of the relays boards allow for external voltage to cover the power requirements of the transistor drives etc and the coil voltage/current of each relay.

All the Arduino has to do is turn on/off 24 LEDs in the optocouplers. Now, I know that the Mega has a max current of 200ma capability.

I cannot understand the optocouplers data sheets correctly to get a definite .ma draw for the led portion of an optocoupler.

IO have seen guys run little LED projects of 20-40 led's chasing each other and then flashing in unison on a breaboard. If the mega can run 30 leds like this ,then surly it can turn on or off 24 optocoupler leds?

Any help on this would be greatly appreciated.

Mike.

I don't know which modules you have, but I looked at some schematics for opto-isolated relay modules* and they typically have 1000 Ohm current limiting resistors for the LED side of the opto-isolator. With a 5V supply that is less than 5mA per relay, so 24 would draw less than 120mA. Well inside the 200 mA limit. You may be able to confirm the resistance by examining the board.

  • Google "opto isolated realy module schematic arduino".

With a multimeter you could measure the current draw directly.

My apologies.. these are the components I am talking about..

Arelay.jpg

Arelay.jpg

How to post images so that we don't have to download them.

Can you read and post the values of R1 and R2 on the board. I think that R2 may be the LED current limit resistor for that section. 1K would read 102.

You have not told us how many relays will be turned on at once. That will certain affect the total current draw.

Paul

Gremlin460:
My apologies.. these are the components I am talking about..

Either they have the identifying characters scrubbed off or the picture is too blurry to read them. Not much help.

A link to the catalog specification sheet / page would help the folks help you easier

As per requests..

I will need the ability to turn all 24 on at the same time. Whether this happens or not is unknown.

All the SMD resistors next to the opto couplers are the marked with R102.

My apologies for incorrectly uploading the picture in the post above.

Mike.

My apologies for incorrectly uploading the picture in the post above.

No problem.

In terms of the current that the Arduino digital output pins must supply, I really think that you have no problem. R102 is 1K resistors. Like I said before the most current per opto-isolator is 5mA and, looking at the schematics, it will be way less. By my calculation the current drawn by each opto when it is turned on (digital output LOW) each opto circuit draws about 2mA.

Current = (5V - irled Vf - indicator led Vf) / 1000 = (5 - 1.2 -1.8) / 1000 = 2 / 1000.

The current drawn by the relay coils is a different story. What is supplying power to the relay coils? How much current does each relay coil need? You will probably need an external 5V supply for the relay coils. With the current capacity to drive 24 coils at once.

The Songle 5V coils are 90ma nominal so you’ll need at least 2 amps for 24 coils. If you’re using eBay stuff, go with 50% of rated current for Chinese power supplies. That would put you into a 5 amp supply just to be safe.

I've measured the Songle 5V relays at 75 mA so 24 on at the same time (probably unlikely) would be 1.8 Amps. Make sure wires carrying power are big enough ( 20 AWG or metric equivalent, 0.5 mm^2).

To be fair I will give a quick outline of the Project and headache I am building..

Take a 18650 battery holder. feed it to:-
A reverse polarity circuit built on a home made PCB . Feed it to:-
INA-219 current sensing breakout. this feeds data to the Mega. : feed that to:-
One of those relays which selects either a TP4056 charge module or a HW586 Discharge module.

Take that line of components and multiply by twenty bays.

Due to the fact the INA-219 is a I2C device and can only have 4 (easily) selected addresses but I am using
24 of them, I am employing a TCA9548a I2C 8 channel multiplexer, giving me a total of 32 I2C ports.

The other 4 bays on the unit are for recovering "hibernating" 18650 cells. The ones that comercial chargers ignore because they are at 2vdc or below.

All the relays will have a seperate 5vdc feed from a 3A dc-dc converter fed by 12vdc @6amp.

This whole unit PSU is 45Amp capable. The arduino with be fed from a second DC-DC converter @ 7VDC to avoid fluctuation or sag from being feed with 5vdc.

The software to display all this comes from a small company in NZ called MegunoLink.
It is a fully customize able on screen setup that I highly recommend. You can program buttons and controls on the screen to send commands to an Arduino.

For example I will have a set able counter control for each bay, so if I enter "3" the arduino will let that bay charge and discharge that particular cell 3 times in a row. On each cycle the arduino will display the count less one till it reaches zero and then display a completed message for that cell.

I have a bucket full of Arduino code sketch pieces, for the INA219, for the multiplexer, etc etc.
How the hell I am going to string them all together I have zero idea. I am 64 years old tomorrow and last coded on a 286 over 30 years ago. I know enough coding to have the ability to map out what I need, and have started a flowchart mapping decisions and results needed.

Somewhere out there is a very smart Arduino programmer who may like a challenge, a bigger one than make a led flash or a motor turn on and off. I am sorry to be long winded, but I am enthusiastic about this project and get carried away.

So I will shut up now.

Mike.

Hello Mike,

Forgive my curiosity, I am wondering why you are building what you are building. What does it achieve?

I know enough coding to have the ability to map out what I need, and have started a flowchart mapping decisions and results needed.

Good start.

I am enthusiastic about this project and get carried away.

Good! Then you will keep going until you are satisfied with the result. For what it's worth, some time in the 1980s I was listening to my heating thermostat clicking on and off and thinking I could make something better. I have lost count of how many versions of improved heating controller I have made. The current version has a Nextion touch screen and controls 4 heating zones. I think I have run out of possible improvements, well, except for.... Why am I telling you this? To illustrate where enthusiasm can take you.

Hello Perry, and thank you very much for asking "why" not many do, or care that much.

The why is quite simple, as in your case with the controller, you had a piece of electronic that just was not up to par with your needs/expectations.

I am going to be building a Power Wall for a new house I am building as soon as this home is sold.
I hope to retire in less than 2 years and would like the new house to be as self sufficient as possible.

Now , most chargers that are available on the market today are woefully inadequate for my particular needs. They are perfectly fine for guys with drones or camera equipment and such products, where they may charge 4 8 or a dozen batteries. Most of them will be new batteries too.

What I am doing is going to entail testing and resurrecting used cells from defunct laptop battery packs. Currently the target is in the vicinity of 3000 cells. My first target is a bank of 14S100P cells.

To do any of this I need a unit that will process cells much more comprehensively, and the only way to do that is build one myself.
So enter the plan to build a 20slot/bay cell charger with an additional 4 slot to "massage" hibernating cells into reporting thier condition and capacity.

This is all made possible by the use of the Arduino. The Mega is the heart of the whole plan. I could just plain charge and discharge the cells without it, like many DIY power Wall builders do. That would give me no data to work with other than yes it charged or no it didnt. I believe that is next to useless for me.

Physically building this is quite easy, however programming the Arduino , well, not so much.

Here is a question, Does the sketches support nested for/next loops? I have no clue.

I will have 24 INA219's These are basically Data gathering points, the chargers have no data to feed out, the HW586's have on board readouts for what they do. The relays, well they have nothing to add except Hey Mike we Open or Hey we closed.

All the info I am going to collect comes from 24 I2C boards, each one feeds out 4 bits of data, 4 data items x 24 , 94 , I hope the Arduino is up to the task, I think it should be. I dont need constant data flow, once per second or two will be fine.

Time for coffee... bye for now.

Mike

Actually before I go.. let me expand on the question of nested for/next loops.

Remember I used to program before most of you were born ,but did mostly in Basic and a little C++ but you will get the idea..

The INA219 board gives 4 bits of data

current
bus voltage
shunt voltage
power

So as i said they have 4 addresses for any one I2C channel, they actually have 16 according to the data sheet but a lot of messing around to get them.
So I am going to use a 8 channel I2C multiplexer. I only need 6 of them (for now).

So two ways of doing this bit in the sketch..

read board 1
current
bus voltage
shunt voltage
power

read board 2
current
bus voltage
shunt voltage
power

Read board 3
current
bus voltage
shunt voltage
power

Read board 4
current
bus voltage
shunt voltage
power

change I2c Channel to next

read board 1
current
bus voltage
shunt voltage
power
read board 2
current
bus voltage
shunt voltage
power
Read board 3

---------- you get the idea and write this out 24 times once for each board.
This is going to make a BIG sketch when added to other things I need .

So I think a nested for loop be easier and shorter

For x=3 to 7 <how many I2C channels (5)
For y=1 to 4 < how many INA219's per channel
Read Channel(x) Board(y)
print Board(y)
Next y: y=0
next x: x=0

Although that is written in old basic lingo I think it should do the same job but in a lot more compact way. It may need a short delay in the loops to allow the data to be secured properly..

Which way do you guys think is best?

Mike.

Are you writing your own INA219 code from scratch or do you plan on using the Adafruit library?

I am hoping to start with the Adafruit sketch as a base then modify it from there..

Based on that response, you should first work with the library and I2C multiplexer before writing pseudo code and soliciting comments. You have some object basics to cover before jumping to code structures.

I’m not saying it is impossible to end up with something that looks like your pseudo code but you’ll not get there directly on the first iteration using a library.

Thank you Mike,
Interesting project, good luck! :slight_smile: