push the button to switch relay, (keep push while arduino doing setup)
then arduino output D2 HIGH.
D2 keep switch on.
And make it LOW after several jobs,
then turn off arduino.
It works.
But I'm not sure its safe.
Is there something wrong in circuit?
kind of electric problem?
or could you give me some advices to improve its safety.
Currently with the circuit that you have, you will power the Arduino through the output pin just for a moment when you hit the button. This could possibly hurt the Arduino.
If you run the black wire or negative power through the relay, instead of the red wire which is positive, the Arduino will be protected at least until it has power to it.
With the negative disconnected at the relay, the Arduino will not be able to see the button voltage so Arduino will not get hurt.
But.
I do worry about positive.
I can't explain,
I just know(think? heard?) that everything has ground.
I think
Device connected GND only - Hmm, It's OK. It has no electricity.
Device connected Positive only - Oh, It's dangerous! it will be fire!
am I wrong?
===
I did wire it as new one.
It has problem.
If i connect power to new wiring,
then tick,tick,tick,tick,tick,tick,tick, relay switch rapidly.
I dont know why.
if I push the button to turn on arduino, it works.
And LOW to D2(close relay, turn off arduino),
then tick,tick,tick,tick,tick,tick,tick, switch rapidly again.
The DC jack voltage has to be between 7V to 12V for the UNO on board regulator to work.
If you put 5V into the DC jack, you will have problems getting the UNO working.
If your external power supply is regulated 5 volts, you can connect it to the 5V and GND pins on the Arduino as in my image.
Remove these connections when powering the Arduino from the USB connector.
In that wiring, use 5V,GND pin instead of DC jack.
because 5V is too weak to run arduino through DC jack.
So, It must be sure 5V power source.
Thank you.
Can I ask more?
If I do not cut 5V,GND when connect USB,
what hanppen?
is it dangerous? may burn arduino or relay or plug? shut down whole electricity in the house?
"1. I need a diode to prevent power to D2.
2. In that wiring, use 5V,GND pin instead of DC jack.
because 5V is too weak to run arduino through DC jack.
So, It must be sure 5V power source."
Can I ask more?
If I do NOT cut 5V,GND when connect USB and switch relay on,
what hanppen?
is it dangerous? may burn arduino or relay or plug? shut down whole electricity in the house?