user43220: Im a student and working on a arduino project for IoT competition and me and my team have built a house and I made this code below.
For some reason when I upload it to my Arduino MKR1000 it constantly turns D6 and D8 on and right after their both on it turns them off and so on for ever. I cant figure out why is it doing that because its only these 2 but not the rest of them.
Quick help would be appreciated.
Please note that I'm by any means a PRO at this but I do know my share about programming.
        //Definiramo ispis na serial port
#define BLYNK_PRINT Serial

//Ucitavamo biblioteke
#include <SPI.h>
#include <WiFi101.h>
#include <BlynkSimpleMKR1000.h>

// Autorizacijski kod za aplikaciju Blynk
char auth[] = "Token";

// Podatci za WiFi
char ssid[] = "SSID";
char pass[] = "PASSWORD";

// ----- Inicializacija ledica -----
const int ledBorDim = 2;
const int ledKuh = 6;
const int ledTrp = 7;
const int ledKup = 8;
const int lediceUlaz = 9;
const int ledSpav = 10;

// ----- Inicializacija gumbova -----
const int gumbKuh = 11;
const int gumbKup = 12;
const int gumbSpav = 13;
const int gumbBor = 14;

// ----- Kontrolne varijable -----
int stanjeLedKuh = 0;
int stanjeLedKup = 0;
int stanjeLedBor = 0;
int stanjeLedSpav = 0;

int gumbStanjeKuh = 0;
int gumbStanjeSpav = 0;
int gumbStanjeBor = 0;
int gumbStanjeKup = 0;

//Led kuhinja
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("ledKuh = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(ledKuh, HIGH); 
    stanjeLedKuh = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledKuh, LOW); 
    stanjeLedKuh = 0;
  }
}

//Ledica za kupaonicu
BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("ledKup = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(ledKup, HIGH); //Promjena stanja na izlazu arduina
    stanjeLedKup = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledKup, LOW); //Promjena stanja na izlazu arduina
    stanjeLedKup = 0;
  }
}

//Paralelni spoj ledica na ulazu
BLYNK_WRITE(V6)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("lediceUlaz = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(lediceUlaz, HIGH); //Promjena stanja na izlazu arduina
  } if (pinValue == 0)
  {
    digitalWrite(lediceUlaz, LOW); //Promjena stanja na izlazu arduina
  }
}

//Dimmer za Boravak
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); //Ucitamo vrijednost
  Serial.print("Dimmer vrijednost: "); //Ispisemo na serial
  Serial.println(pinValue);
  analogWrite(ledBorDim, pinValue); //Na izlaz postavljamo vrijednost
  if (pinValue == 0)
  {
    Blynk.virtualWrite(V50, 1);
    stanjeLedBor = 0;
  } else if (pinValue > 0)
  {
    Blynk.virtualWrite(V50, 0);
    stanjeLedBor = 1;
  }
}

BLYNK_WRITE(V50)
{
  int pinValue = param.asInt(); 
  if (pinValue == 1)
  {
    analogWrite(ledBorDim, 255);
    Blynk.virtualWrite(V1, 255);
    stanjeLedBor = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledBorDim, LOW);
    Blynk.virtualWrite(V1, 0);
    stanjeLedBor = 0;
  }
}

void gumbKuhinja()
{
  gumbStanjeKuh = digitalRead(gumbKuh);
  if (gumbStanjeKuh == LOW)
  {
    if(stanjeLedKuh == 1)
    {
      digitalWrite(ledKuh, LOW);
      Blynk.virtualWrite(V3, 0);
      Serial.println("Ledica na V3/D6 je LOW");
      stanjeLedKuh = 0;

    } else if (stanjeLedKuh == 0)
    {
      digitalWrite(ledKuh, HIGH);
      Blynk.virtualWrite(V3, 1);
      Serial.println("Ledica na V3/D6 je HIGH");
      stanjeLedKuh = 1;

    }
    delay(500);
  }
}

void gumbKupaonica()
{
  gumbStanjeKup = digitalRead(gumbKup);
  if (gumbStanjeKup == LOW)
  {
    if(stanjeLedKup == 1)
    {
      digitalWrite(ledKup, LOW);
      Blynk.virtualWrite(V5, 0);
      Serial.println("Ledica na V5/D8 je LOW");
      stanjeLedKup = 0;

    } else if (stanjeLedKup == 0)
    {
      digitalWrite(ledKup, HIGH);
      Blynk.virtualWrite(V5, 1);
      Serial.println("Ledica na V5/D8 je HIGH");
      stanjeLedKup = 1;
    }
    delay(500);
  }
}

void gumbSpavaca()
{
  gumbStanjeSpav = digitalRead(gumbSpav);
  if (gumbStanjeSpav == LOW)
  {
    if(stanjeLedSpav == 1)
    {
      digitalWrite(ledSpav, LOW);
      Blynk.virtualWrite(V6, 0);
      Serial.println("Ledica na V6/D10 je LOW");
      stanjeLedSpav = 0;
    } else if (stanjeLedSpav == 0)
    {
      digitalWrite(ledSpav, HIGH);
      Blynk.virtualWrite(V6, 1);
      Serial.println("Ledica na V6/D10 je HIGH");
      stanjeLedSpav = 1;
    }
    delay(500);
  }
}

void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == LOW)
  {
    if(stanjeLedBor == 1)
    {
      analogWrite(ledBorDim, 0);
      Blynk.virtualWrite(V1, 0);
      Serial.println("Ledica na V1/D2 je 0");
      stanjeLedBor = 0;
    } else if (stanjeLedBor == 0)
    {
      analogWrite(ledBorDim, 255);
      Blynk.virtualWrite(V1, 1);
      Serial.println("Ledica na V1/D2 je 255");
      stanjeLedBor = 1;
    }
    delay(500);
  }
}

void setup()
{

  pinMode(ledBorDim, OUTPUT);
  pinMode(ledKuh, OUTPUT);
  pinMode(ledKup, OUTPUT);
  pinMode(lediceUlaz, OUTPUT);
  pinMode(ledSpav, OUTPUT);

  pinMode(gumbKuh, INPUT);
  pinMode(gumbKup, INPUT);
  pinMode(gumbSpav, INPUT);
  pinMode(gumbBor, INPUT);


  // Debug console
  Serial.begin(9600);
  //Povezivanje na WiFi i na aplikaciju Blynk
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  gumbKuhinja();
  gumbKupaonica();
  gumbSpavaca();
  gumbBoravak();
}

Serial outpout:
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255


Little label reading D14 means that that pin isnt suppoast to go to D4 but to D14 of the MKR1000 but since i dont have that board in the program im stuck with arduino Uno.
Short explanation of the code...
We build a house out of styrofoam and placed 6 Led's around and almost all can be controlled from the Blynk app on my device. Also there are 4 buttons controlling 4 Led's. I have it setup so that when i press a button it changes the state of a particular LED and then sets the appropriate value on the app (If LED is on then set app value to 1). Pretty much that that about this code. Sorry if you cant understand but I had to write it in my native language since this is going to be a compettition and I was told that they wouldn't like if the code was in english for some reason.

user30175: You had the following general problem: 
The code you were using was configuring a pin into INPUT mode and reading the value on it. On this pin you conencted a button without extern pullup or pulldown resistor. This means that if the button is not pressed, it is not connected to anything and thus a floating pin. You cannot realibly read the value of the floating pin, as its voltage level may be on pretty much anything. It picks up interference like an antenna.
To solve this the button pin must be pulled to known voltage level if it is not connected (aka button is not pressed). We achieve this by using a resistor which is on one end connected to the button pin and on the other end connected to either VCC (+5V) or GND (0V). This has the effect that when the button is not pressed, the resistor pulls the voltage level of this pin up (if connected to VCC), or down if connected to GND. 
We can either attach a resistor (e.g. 10K Ohm) in the circuit or active the internal (weak) pull-up resistors in our microcontroller. In Arduino, this is achieved by using pinMode( buttonPin, INPUT_PULLUP). 

In this circuit with INPUT_PULLUP on D2, we have:

if the button is not pressed down, no connection to GND is made. The activated pull-up resistor will pull the voltage level of D2 to HIGH
if the button is pressed down, it makes a connection to GND and overrides the pullup resistor. Pin D2 now reads LOW. 

The logic can of course also be inverted -- you can use a PULLDOWN resistor and instead of connecting the button to GND on the other side connect it do 5V. This make the button read LOW when unpressed and HIGH pressed. 
So the modified code must be changed from 
  pinMode(gumbKuh, INPUT);
  pinMode(gumbKup, INPUT);
  pinMode(gumbSpav, INPUT);
  pinMode(gumbBor, INPUT);

to 
  pinMode(gumbKuh, INPUT_PULLUP);
  pinMode(gumbKup, INPUT_PULLUP);
  pinMode(gumbSpav, INPUT_PULLUP);
  pinMode(gumbBor, INPUT_PULLUP);

and the logic which detects a button pressed must be changed to trigger an action when the pin is LOW (because a PULLUP is used, button reads LOW when pressed, HIGH else).
So from code of the form
void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == HIGH)
  {
    /* LED toggling and debouncing */
    delay(500);
  }
}

To
void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == LOW)
  {
    /* LED toggling and debouncing */
    delay(500);
  }
}

Also I recommend you to watch this youtube video to learn more about floating pins and pullup/pulldown resistors: Pull up Resistor Tutorial

43220: <p>Im a student and working on a arduino project for IoT competition and me and my team have built a house and I made this code below.
For some reason when I upload it to my Arduino MKR1000 it constantly turns D6 and D8 on and right after their both on it turns them off and so on for ever. I cant figure out why is it doing that because its only these 2 but not the rest of them.</p>

<p>Quick help would be appreciated.</p>

<p>Please note that I'm by any means a PRO at this but I do know my share about programming.</p>

<pre><code>        //Definiramo ispis na serial port
#define BLYNK_PRINT Serial

//Ucitavamo biblioteke
#include &lt;SPI.h&gt;
#include &lt;WiFi101.h&gt;
#include &lt;BlynkSimpleMKR1000.h&gt;

// Autorizacijski kod za aplikaciju Blynk
char auth[] = "Token";

// Podatci za WiFi
char ssid[] = "SSID";
char pass[] = "PASSWORD";

// ----- Inicializacija ledica -----
const int ledBorDim = 2;
const int ledKuh = 6;
const int ledTrp = 7;
const int ledKup = 8;
const int lediceUlaz = 9;
const int ledSpav = 10;

// ----- Inicializacija gumbova -----
const int gumbKuh = 11;
const int gumbKup = 12;
const int gumbSpav = 13;
const int gumbBor = 14;

// ----- Kontrolne varijable -----
int stanjeLedKuh = 0;
int stanjeLedKup = 0;
int stanjeLedBor = 0;
int stanjeLedSpav = 0;

int gumbStanjeKuh = 0;
int gumbStanjeSpav = 0;
int gumbStanjeBor = 0;
int gumbStanjeKup = 0;

//Led kuhinja
BLYNK_WRITE(V3)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("ledKuh = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(ledKuh, HIGH); 
    stanjeLedKuh = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledKuh, LOW); 
    stanjeLedKuh = 0;
  }
}

//Ledica za kupaonicu
BLYNK_WRITE(V5)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("ledKup = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(ledKup, HIGH); //Promjena stanja na izlazu arduina
    stanjeLedKup = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledKup, LOW); //Promjena stanja na izlazu arduina
    stanjeLedKup = 0;
  }
}

//Paralelni spoj ledica na ulazu
BLYNK_WRITE(V6)
{
  int pinValue = param.asInt(); //Pinvalue postavljamo da bude vrijednost ono sto postavimo na aplikaciji
  Serial.print("lediceUlaz = "); //Ispis na ekran trenutno stanje
  Serial.println(pinValue);
  if (pinValue == 1)
  {
    digitalWrite(lediceUlaz, HIGH); //Promjena stanja na izlazu arduina
  } if (pinValue == 0)
  {
    digitalWrite(lediceUlaz, LOW); //Promjena stanja na izlazu arduina
  }
}

//Dimmer za Boravak
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); //Ucitamo vrijednost
  Serial.print("Dimmer vrijednost: "); //Ispisemo na serial
  Serial.println(pinValue);
  analogWrite(ledBorDim, pinValue); //Na izlaz postavljamo vrijednost
  if (pinValue == 0)
  {
    Blynk.virtualWrite(V50, 1);
    stanjeLedBor = 0;
  } else if (pinValue &gt; 0)
  {
    Blynk.virtualWrite(V50, 0);
    stanjeLedBor = 1;
  }
}

BLYNK_WRITE(V50)
{
  int pinValue = param.asInt(); 
  if (pinValue == 1)
  {
    analogWrite(ledBorDim, 255);
    Blynk.virtualWrite(V1, 255);
    stanjeLedBor = 1;
  } if (pinValue == 0)
  {
    digitalWrite(ledBorDim, LOW);
    Blynk.virtualWrite(V1, 0);
    stanjeLedBor = 0;
  }
}

void gumbKuhinja()
{
  gumbStanjeKuh = digitalRead(gumbKuh);
  if (gumbStanjeKuh == LOW)
  {
    if(stanjeLedKuh == 1)
    {
      digitalWrite(ledKuh, LOW);
      Blynk.virtualWrite(V3, 0);
      Serial.println("Ledica na V3/D6 je LOW");
      stanjeLedKuh = 0;

    } else if (stanjeLedKuh == 0)
    {
      digitalWrite(ledKuh, HIGH);
      Blynk.virtualWrite(V3, 1);
      Serial.println("Ledica na V3/D6 je HIGH");
      stanjeLedKuh = 1;

    }
    delay(500);
  }
}

void gumbKupaonica()
{
  gumbStanjeKup = digitalRead(gumbKup);
  if (gumbStanjeKup == LOW)
  {
    if(stanjeLedKup == 1)
    {
      digitalWrite(ledKup, LOW);
      Blynk.virtualWrite(V5, 0);
      Serial.println("Ledica na V5/D8 je LOW");
      stanjeLedKup = 0;

    } else if (stanjeLedKup == 0)
    {
      digitalWrite(ledKup, HIGH);
      Blynk.virtualWrite(V5, 1);
      Serial.println("Ledica na V5/D8 je HIGH");
      stanjeLedKup = 1;
    }
    delay(500);
  }
}

void gumbSpavaca()
{
  gumbStanjeSpav = digitalRead(gumbSpav);
  if (gumbStanjeSpav == LOW)
  {
    if(stanjeLedSpav == 1)
    {
      digitalWrite(ledSpav, LOW);
      Blynk.virtualWrite(V6, 0);
      Serial.println("Ledica na V6/D10 je LOW");
      stanjeLedSpav = 0;
    } else if (stanjeLedSpav == 0)
    {
      digitalWrite(ledSpav, HIGH);
      Blynk.virtualWrite(V6, 1);
      Serial.println("Ledica na V6/D10 je HIGH");
      stanjeLedSpav = 1;
    }
    delay(500);
  }
}

void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == LOW)
  {
    if(stanjeLedBor == 1)
    {
      analogWrite(ledBorDim, 0);
      Blynk.virtualWrite(V1, 0);
      Serial.println("Ledica na V1/D2 je 0");
      stanjeLedBor = 0;
    } else if (stanjeLedBor == 0)
    {
      analogWrite(ledBorDim, 255);
      Blynk.virtualWrite(V1, 1);
      Serial.println("Ledica na V1/D2 je 255");
      stanjeLedBor = 1;
    }
    delay(500);
  }
}

void setup()
{

  pinMode(ledBorDim, OUTPUT);
  pinMode(ledKuh, OUTPUT);
  pinMode(ledKup, OUTPUT);
  pinMode(lediceUlaz, OUTPUT);
  pinMode(ledSpav, OUTPUT);

  pinMode(gumbKuh, INPUT);
  pinMode(gumbKup, INPUT);
  pinMode(gumbSpav, INPUT);
  pinMode(gumbBor, INPUT);


  // Debug console
  Serial.begin(9600);
  //Povezivanje na WiFi i na aplikaciju Blynk
  Blynk.begin(auth, ssid, pass);
}

void loop()
{
  Blynk.run();
  gumbKuhinja();
  gumbKupaonica();
  gumbSpavaca();
  gumbBoravak();
}
</code></pre>

<p>Serial outpout:</p>

<pre><code>Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
Ledica na V6/D10 je LOW
Ledica na V1/D2 je 0
Ledica na V6/D10 je HIGH
Ledica na V1/D2 je 255
</code></pre>

<p><a href="https://i.stack.imgur.com/Dtt5I.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dtt5I.png" alt="Breadboard schematic"></a></p>

<p>Little label reading D14 means that that pin isnt suppoast to go to D4 but to D14 of the MKR1000 but since i dont have that board in the program im stuck with arduino Uno.<br>
Short explanation of the code...
We build a house out of styrofoam and placed 6 Led's around and almost all can be controlled from the Blynk app on my device. Also there are 4 buttons controlling 4 Led's. I have it setup so that when i press a button it changes the state of a particular LED and then sets the appropriate value on the app (If LED is on then set app value to 1). Pretty much that that about this code. Sorry if you cant understand but I had to write it in my native language since this is going to be a compettition and I was told that they wouldn't like if the code was in english for some reason.</p>
 30175: <p>You had the following general problem: </p>

<p>The code you were using was configuring a pin into <code>INPUT</code> mode and reading the value on it. On this pin you conencted a button <strong>without extern pullup or pulldown resistor</strong>. This means that if the button is <strong>not pressed</strong>, it is not connected to anything and thus a <strong>floating pin</strong>. You cannot realibly read the value of the floating pin, as its voltage level may be on pretty much anything. It picks up interference like an antenna.</p>

<p>To solve this the button pin must be pulled to known voltage level if it is not connected (aka button is not pressed). We achieve this by using a resistor which is on one end connected to the button pin and on the other end connected to either VCC (+5V) or GND (0V). This has the effect that when the button is not pressed, the resistor pulls the voltage level of this pin up (if connected to VCC), or down if connected to GND. </p>

<p>We can either attach a resistor (e.g. 10K Ohm) in the circuit or active the internal (weak) pull-up resistors in our microcontroller. In Arduino, this is achieved by using <code>pinMode( buttonPin, INPUT_PULLUP)</code>. </p>

<p><a href="https://i.stack.imgur.com/yq9bD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yq9bD.png" alt="enter image description here"></a></p>

<p>In this circuit with <code>INPUT_PULLUP</code> on D2, we have:</p>

<ul>
<li>if the button is not pressed down, no connection to GND is made. The activated pull-up resistor will pull the voltage level of D2 to HIGH</li>
<li>if the button is pressed down, it makes a connection to GND and overrides the pullup resistor. Pin D2 now reads LOW. </li>
</ul>

<p>The logic can of course also be inverted -- you can use a PULLDOWN resistor and instead of connecting the button to GND on the other side connect it do 5V. This make the button read LOW when unpressed and HIGH pressed. </p>

<p>So the modified code must be changed from </p>

<pre><code>  pinMode(gumbKuh, INPUT);
  pinMode(gumbKup, INPUT);
  pinMode(gumbSpav, INPUT);
  pinMode(gumbBor, INPUT);
</code></pre>

<p>to </p>

<pre><code>  pinMode(gumbKuh, INPUT_PULLUP);
  pinMode(gumbKup, INPUT_PULLUP);
  pinMode(gumbSpav, INPUT_PULLUP);
  pinMode(gumbBor, INPUT_PULLUP);
</code></pre>

<p>and the logic which detects a button pressed must be changed to trigger an action when the pin is LOW (because a PULLUP is used, button reads LOW when pressed, HIGH else).</p>

<p>So from code of the form</p>

<pre><code>void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == HIGH)
  {
    /* LED toggling and debouncing */
    delay(500);
  }
}
</code></pre>

<p>To</p>

<pre><code>void gumbBoravak()
{
  gumbStanjeBor = digitalRead(gumbBor);
  if (gumbStanjeBor == LOW)
  {
    /* LED toggling and debouncing */
    delay(500);
  }
}
</code></pre>

<p>Also I recommend you to watch this youtube video to learn more about floating pins and pullup/pulldown resistors: <a href="https://www.youtube.com/watch?v=wxjerCHCEMg" rel="nofollow noreferrer">Pull up Resistor Tutorial</a></p>
