is my arduino have problem?

hello,

i have a leonardo, and i guess it has some problem on serial communucation.

i wrote a small program

void setup() {

Serial.begin(9600);

pinMode(5,INPUT);

}

int but1=0;
void loop() {

but1=digitalRead(10);

Serial.println(but1);

delay(100);

}

when i give 5 volts to pin 10(i tried almost all pin 1,3,5,6,7,8,11), on serial print always 1 but when i take out 5 volts, on screen 1 and 0 changing randomly
, 15 second 0,
10 second 1,
2 second 0,
3 times 1...

is there any problem in my leonardo?

use Serial.println(but1, DEC); to print a decimal value...

so, i changed program like this

void setup() {

Serial.begin(9600);

pinMode(5,INPUT);

}

int but1=0; //buton de?eri 1-0
void loop() {

but1=digitalRead(5);

Serial.println(but1, DEC);

delay(100);

}

still same ,

also i just realize when i give 5 volts, a little bit later, for a small duration "0" coming, than turns to 1, after little bit later again for small duration 0 coming and it happining agian and again..

What do expert to get. Digital is high or low. If don't have 5 V what connected to the pin? Is nothing connected you don't know if it is high or low.

A floating pin won't give any consistent reading.

Please use code tags.

dear carlmikael, english is not my native language, so pls use simple english :slight_smile:

i want wrote a program, when i push button led will open, and when i push again led will close, but i couldn't read the button 0 or 1...

when there is nothing connected to pin 10, screen 1 and 0 changing randomly, when i give 5v (on arduino 5v pin) to pin 10, generally on screen 1, for a small duration 0 coming than turns 1...

dear awol i just seen to code tags, thank you.
what do you mean with "floating pin".

Use the built-in pull up resistors or fit your own external pull-downs.

when there is no cable on arduino(there was a bread board with leds and button, i take out all the cable from arduino), on screen i seen 1-0 randomly, what pull up resistor will changes. i mean without anything, numbers are coming randomly, isnt this a problem?

i mean without anything, numbers are coming randomly, isnt this a problem?

Without anything connected, what do you expect to read?
High?
Low?

Why do you expect that?

No, it isn't a problem.