The NOT Gate With Arduino

5,274

11

2

Introduction: The NOT Gate With Arduino

About: An Electrical Engineering Teacher in Athens Greece. Most of these small projects here, are constructed for enhancing the learning of the use of Arduino as well as basic electricity and electronics for students…
/*Arduino_NOT_Logic_Gate. A simple circuit to view the NOT gate. 
And exploring simple forms of code.
Change the code to buttonStatus == HIGH and see what happens.*/
int buttonPin = 2;  
int ledPin = 8;
int buttonStatus = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}

void loop(){
buttonStatus = digitalRead(buttonPin);
if (buttonStatus == LOW) { // check if the button state is LOW if yes then turn the LED on
digitalWrite(ledPin, HIGH);
}
else { digitalWrite(ledPin, LOW); // else if the button state is HIGH turn the LED off
}
}

Step 1: Step 2 Variation

/*Arduino_NOT_Logic_Gate. Another variation in the code would be this*/
int buttonPin = 2; 
int ledPin = 8;
int buttonStatus = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop(){ 
buttonStatus = digitalRead(buttonPin); 
if (buttonStatus != HIGH) // if the button is not (!=) HIGH (hence LOW) turn on the LED
{digitalWrite(ledPin, HIGH); }

else { digitalWrite(ledPin, LOW); }
}

Step 2:

Be the First to Share

    Recommendations

    • Stone Concrete Cement Contest

      Stone Concrete Cement Contest
    • Frozen Treats Speed Challenge

      Frozen Treats Speed Challenge
    • Digital Fabrication Student Design Challenge

      Digital Fabrication Student Design Challenge

    2 Comments

    0
    StephenB252
    StephenB252

    2 years ago

    Agreed, great program, worked well and easy to adapt. Thanks!

    0
    tomatoskins
    tomatoskins

    5 years ago

    What a fun program!