InnoVech
Published

Lesson 4 - IF and Else Statements

In this lesson we will be learning to use conditional statements on the Arduino.

IntermediateProtip1 hour18,884
Lesson 4 - IF and Else Statements

Things used in this project

Story

Read more

Code

Conditional Statements

Arduino
Lesson 4 Source Code
//Complete Guide to Arduino
//Created by Zaqyas Mahmood, InnoVech
//Lesson 4 IF ELSE Statements

//Global Scope

//LED pin 13 declared as a constant integer
const int LED = 13;
//Variable count declared as an integer data type
int Count = 0;


void setup() {
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  if (Count < 10) {
    digitalWrite(LED, HIGH);  // turn led on
    delay(500);               // half a second delay
    digitalWrite(LED, LOW);   // turn led off
    delay(500);               // half a second delay
    Count ++;                 // increment by 1
    Serial.println(Count);    // display count in serial monitor
  }

  else{
    digitalWrite(LED, LOW); //turn the LED off completely
  }

}

Credits

InnoVech

InnoVech

11 projects • 8 followers
We strive to share our projects with engineering hobbyists and students who are driven to play their roles in the future of engineering.

Comments