Power makes led turn ON and OFF

Hi, I want to receive energy in PIN7 and when it happens I want the led (pin13) to turn ON. if the energy stops the led should go OFF.
I can do that, the problem is that it’s not reliable, sometimes i’m not giving energy in PIN7 and it’s keeps saying that i’m doing that. Can someone help me pls

The code might not be the best (i’m new) if you have improvements fell free to add them.
And sorry if my english was not the best…

power_led.ino (401 Bytes)

You don't supply "energy" to a pin. You supply a voltage. How do you supply that voltage?

How, exactly, are you feeding energy to pin 7? It sounds to me like you have a "floating input" (Google that). Inputs are very high input impedance. That means that it takes very little energy to make the input change state. Just moving your hand close and away can affect the state. The way to prevent a floating input is to make sure that the input is always in a known state. If you change the pinMode from INPUT to INPUT_PULLUP you will see that the input will always read HIGH when unconnected (no energy) and always read LOW when connected to ground. That is the proper way to wire a switch.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :)

I give power using a Power Supply, like I put the pin in contact with the end of the power transformer... maybe I shouldn't do that?!...

does it help???

ps: it’s the same image sry…

Yes, you shouldn't play with things you don't understand.

But since you will anyway, why not just use an LED to make that connection? When power is going in to pin 7, it will pass through the LED and light up real pretty.

Welcome.

Better add some sticky pads to the bottom of the Arduino, else you will get yelled at. :wink:

Ahahaha sure will do, sry for my behavior xD Thanks guys, I will keep trying. Have a nice day!

I'll update later