Dive into the world of Robotics with an Arduino Course

Home Lessons
Science &
Engineering
Robotics &
Coding
Save your &
Progress
Individual &
Lessons

Arduino Lesson 3 - If Statements

The 3th in a series of tutorials to help you understand the basics of the Arduino uno. In this session we will be covering if statements in the context of digitalReads. By the end of this session you will be able to write code to turn and LED on and off using a button. You can apply this theory to a number of more complex functions which we will go over in the next tutorial.

Here is code written in the lesson :)


                    int button = 7;
                    int led = 8;
                    
                    void setup() {
                      // put your setup code here, to run once:
                      pinMode(led, OUTPUT);
                      pinMode(button, INPUT);
                    }
                    
                    void loop() {
                      // put your main code here, to run repeatedly:
                      if(digitalRead(button) == HIGH) {
                        digitalWrite(led, HIGH);
                      }
                      else{
                        digitalWrite(led, LOW);
                      }
                    }
                    
                

I hope you enjoy the video!

Buy me a coffeeBuy me a coffee