I use an Arduino Nano USB-powered and 9V battery.
The standard circuit of Arduino is so that is always uses the input with the higher voltage.
I want to but that Arduino 9V battery only be used when there is no voltage on the USB port is available.
Know someone how I can do that?
Perhaps a simple circuit?
here you have the simplest UPS circuit I ever found. I should be quite easy to adapt to your needs, but do remember, the BAT(tery) must be rechargeable!
I'm not sure the UPS example is correct for @Filippo requirement. The most simple and effective solution I can think of is to use the smallest 5V relay you can find. Have the normally closed contact connected to the 9V supply and the normally open contact connected to the 5V supply with the common going to your Arduino. Also connect the 5V to the coil and common up the zero of both supplies.
This way, whenever the 5V is present it will energise the relay and supply your circuit using the 5V supply and will completely disconnect the 9V thus preventing the battery from draining. When the 5V is removed, the relay will de-energise and re-connect the 9V. Nice and simple
I also thought of that, but a mechanical switch may force the R'duino to reset, thus restarting the program, which may be undesirable!
Also, the Relay being always energized when in USB mode, will force for a "minimum" current of a few dozens milliamps plus the board power consumption, which may not be negligible!
Instead of a relay, a P channel MOSFET, might be used as a switch for the 9V input. The MOSFET would be arranged such that without USB power the gate is low, that would switch the MOSFET on. When the USB powers the gate could be at MOSFET source level, so it is off. Might take a resistor or two. I would recommend use of a circuit simulator to test the circuit.
I have now made such a simple circuit with a optocoupler, what do you think, it may function?
I know that between the diode and 9V should include a resistance, but is now for the circuit not important.
Unfortunately it does not work with the 4N35.
I need an optocoupler which inverts the signal, that is, the battery may be used only when the USB input is not a tension.
Can anyone tell me what would be the right optocoupler?
That's the thing with opto couplers... They are always NO (normally opened)
You could use a transistor to trigger a low state when USB is plugged in, thus turning the opto coupler off
That's the thing with opto couplers... They are always NO (normally opened)
You could use a transistor to trigger a low state when USB is plugged in, thus turning the opto coupler off
There is a CPC2317N form C solidstate relay. Use the form B section. It is normally closed, but with USB on the LED emitter, it opens. The part is $2.10 USD. There are many more parts, but they cost more.
Use about 3.8k resistor to limit LED current to 1mA when powering from USB. Load needs to be under 120mA on switch side.
I might be able to help if you show the circuit you tried. Not working is not enough information. Use volt meter, measure what happens pins 1-2, and 7-8 with and without USB.
Use 3.8k resistor to limit current at pin 1. Apply +5V from USB to resistor , and ground to pin2. Use pins 7 and 8 to enable 9V feed.
Pins 7 to 8 conduct when USB is absent, with USB pins 7-8 open.
Might try to reduce 3.8k to 2k, see if more LED current helps.
I think that something is wrong at the chip CPC2317N.
Pin7 + 8 and Pin6 + 5 are always open!
Only if at Pin1+2 or pin3+4 a voltage is the Pin7+8 or Pin6+5 are closed.
Hi Filippo
You are using an operational amplifier IC but refering to it as solid-state relay. The IC LM358 is an op amp while the number in the red arrow in post# 18 is refering it as CPC2317N which is a relay.