Uno Blinks LED Randomly, Counter To Uploaded Code


code: [select]

int ledpin = 13;
int button = 8;

void setup()
{
 pinmode(ledpin, output);
 pinmode(button, input);
}

void loop()
{
 if (digitalread(button) == high)
  {
   digitalwrite(ledpin, high);
  }
 else
  {
   digitalwrite(ledpin, low);
  }
}


i'm trying flash led upon input pin 8.
problem is, led flashes randomly. led connected pin 13.
if leave board still, stops. if move it, starts. i've measured connection, , it's working intended.
i have tried manual reset, usb , jack power.

3.3v -> switch/wire shortening -> pin 8 input
pin 13 -> gnd on same rail

wiring diagram (dropbox)

i'm using sainsmart uno, latest edition.

kind of lost here... arduino programming knowledge i've got far how write simple code shown above. i'm not sure if it's code needs changing, assume it's not, since works other people.

bad board perhaps?

:smiley-eek:

tags: issue r3 random reset tried usb power

you haven't shown wiring diagram symptoms describe sound floating input.

try following code, connect push button switch pin 8 , gnd. input high when press switch become low, turning on led.

code: [select]
int ledpin = 13;
int button = 8;

void setup()
{
 pinmode(ledpin, output);
 pinmode(button, input_pullup);
}

void loop()
{
 if (digitalread(button) == low)
  {
   digitalwrite(ledpin, high);
  }
 else
  {
   digitalwrite(ledpin, low);
  }
}


Arduino Forum > Using Arduino > Project Guidance > Uno Blinks LED Randomly, Counter To Uploaded Code


arduino

Comments