ITP BLOG


Lab: Digital Input and Output with an Arduino

1. Add Digital Input and Add Digital Output:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/c3106b1c-e678-48da-91b7-beb0259eb0e7/1B1BAA03-7A75-489E-A3CE-C601C280ABDF.jpeg

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/90c7b6fd-ce9c-452f-8687-c4af8c7c4676/9B1CBD32-EF02-4091-887C-FD6E0F4D8480.jpeg

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/be2f533f-8f47-4d40-a1eb-922ea768ceb4/F106FE45-41B4-4BC5-BF10-D215AEE5671C.jpeg

2. Program the Arduino

    When I first uploaded, I kept getting errors. Then I realize it is better to verify the the code and check the circuit on the breadboard before uploading the code to the Arduino. 

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/22edf0e1-4107-4ba6-8530-41508b6d564b/506C2223-DF1A-4129-A115-928DFF3DB754.jpeg

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/113200c0-7f5f-4ed8-a5e6-282c434f7d27/C39F0624-9D86-49F8-A728-FA39D2558DCF.jpeg


Pin 2 connected to the switch to the Arduino and then run the output to pin 3 & 4 connected to the yellow and red LEDs. 
void setup(){
  // put your setup code here, to run once:
  pinMode(2, INPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
  if(digitalRead(2) == HIGH) {
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    }  else {
    digitalWrite(3, LOW);
    digitalWrite(4, HIGH);
    }

}