Switch on/off onboard devices

Hello everyone,
Last year I made my first custom arduino mega pcb which worked perfectly. Now I want to go a step further. The board I want to make is exactly the same but with 2 onboard devices. The first one is a bluetooth HC-05 and the second is the LoRa SX1278 Ra-01 chip. I want to be able to turn them both or each one on/off. I found out that I can use transistors for this job. The problem is what kind of transistor? PNP or NPN. I'm really confused.

You probably need to switch the power (V+) on those devices, not ground, so PNP transistors. Also, since you should never apply signals to an input on an unpowered device, the Mega outputs to those inputs should be switched to inputs (high Z) before powering the devices off. Then after powering the device on, change them back to outputs.

What do mean "Turn ON OFF"?? Control their #5 / +3.3 V power? Or enable/disable their chips?

Is the HC-05 the actual submodule you will solder to your board, or a module with 5 external pins? What about the LoRA chip?

Hi guys, thank's for replies.
I want to power them off. Completely so the 3.3V power. How am I going to change the mega's output pins to input while I'm on void loop? Both devices are IC's and will be soldered on the pcb.

You can use the pinMode function at any time in the program, not just setup().

I think that's a bit tricky. I mean the lora library doesn't use pinMode. I will post an .ino example. Also I will connect the HC-05 to the RX1,TX1 of the mega so what about that? How can I make them both rx/tx inputs when I'll power off the chip?

lora_send.ino (567 Bytes)

Rx is always an input.

Tx... Just don't attempt to transmit anything to the HC05 while it is off.

If you have specific modules in mind, tell us which ones. You can even buy switch modules or relays to switch the power.

I want to be able to turn them both or each one on/off. I found out that I can use transistors for this job.

Did you investigate turning them off in software?

First of all:

Lora IC: Ra-01 SX1278 LoRa Spread Spectrum Wireless Module 433MHz Serial SPI Interface | eBay

HC-05: https://www.ebay.com/itm/HC-05-Wireless-Bluetooth-RF-Transceiver-Module-serial-30ft-RS232-TTL-for-arduino/180957186752?epid=1342389525&hash=item2a21e38ac0:g:3ZkAAOSwYEBciFfl

I found that using LoRa.end(); puts the radio to sleep and stops the SPI. If this is true I only have to cut off the 3.3V line that goes to the lora module. Then it will be completely powered off.

In the other hand the bluetooth will be on slave mode, so it wont send any data but only receive. When I cut it's power how can I be sure that the TX1 pin of the mega doesn't transmit anything?

My board will be running 24/7 but the Lora or HC-05 modules will not be needed all the time. I want to turn them on only when I want to use them. The only reason for this is to prevent wasting power but also increase their lifetime. I can disable them with a command in my code but they will still work as long as the board is powered on.

So what battery are you using to power this? If the Mega is always running, you may just need to use a bigger battery to account for the power usage.

No other reason to be concerned about "wasting power". :roll_eyes:

You haven't actually manged to waste four other people's time with a problem that does not exist, have you? :astonished:

I'll use the board with a solard panel + battery. The thing is I don't only care for wasting power but also increase the lifetime of the 2 chips. I know for a fact that when electronics run they wear out a bit so the life expectancy drops. That's the main reason. This project will be in a place that can't be reached easily so if something fails it's gonna be very time consuming to fix. The atmega 2560 is reliable but I dont think these chinese lora & hc-05 modules are made for 24/7 use.

Hmmm. I think you have got it the wrong way around here which is why I have challenged you! :grinning:

In general, the worst thing you can do for the lifetime of electronic assemblies, is to turn them on and off repeatedly! It's called "thermal cycling". Parts physically expand and contract; they bend and eventually fail.

Aluminium electrolytic capacitors do "dry out" if running at high temperatures over time, but I am not sure whether this applies to your project and the absolute heat of operation is unlikely to be that great, but it will be the variation in temperature from powering on and off that would be of most concern. :astonished:

So you mean that if the modules don't warm up it's safe to run 24/7? If that is true I don't think I'll have a problem after all. With my recent experience, I can tell you that the lora module does not heat up.

I frankly do not see that the other modules would be any more or less reliable that the 2560.

When you get down to it, the result of American corporate "planning" is that all of these things are in fact made in China, so it is most difficult to discern that one sold by a "reputable" dealer will be in any way different to one sold on eBay. Most of us have had good experiences from eBay, a few not. :grinning:

It is generally a bad idea to have unpowered devices connected to powered ones, which is why good designers use sleep modes.

Guys, I think my problem is kinda solved now. After a little research and using your answers I found that the best and easiest method is to put the modules on sleep mode rather than make a cirquit to physically turn them off. For the lora it's easy enough, but I really didn't find anything usefull about HC-05's sleep mode. The only thing I found is when the bluetooth is not connected, it enters a sleep mode. That means that it is still detectable by a mobile phone or pc. Is there any command that makes the hc-05 non-detectable?

Did you Google something like "HC-05 AT command list".

Yeah, I did but I only found AT commands. Unfortunatelly I wont be able to send these types of commands because they require serial communication through a pc. I was thinking to use millis to track how much time passed since a device disconnected and when (let's say) 10 mins have passed, the code will tell hc-05 to get into sleep mode. The thing is I don't know any command that does this. That's why I'm asking. If it can't be done, I'll just leave it powered on.

I wont be able to send these types of commands because they require serial communication through a pc.


I assumed you had the BT module connected to Serial1, or-2, or -3 of the Mega.
Not to Serial, that's used for USB/PC comms.
If connected to Serial1 RX/TX, then you should have full control over the BT module.
Never tried to sleep a HC-05, so keep us informed.

You said it right. I'll connect it on RX1/TX1, but in order to use AT commands I have to press a button on the hc-05 module while I power on my board. This won't work with my use because it will be out of reach. So I'm gonna make a research to find out if what I'm looking for is possible and I will post here any results.