Week 3 – Arduino Exercises

This week, we explored further with the Arduino.   The videos for the exercises are below:

      1. Digital Input

  1. 2. The Serial Monitor
  2.  For the final exercise, I decided to create a circuit and code that enables two buttons to control one LED, on and off.  Here’s the video:

I was really pleased to get this to work, as it was the first time in a while that I’ve had to figure out any code.  The code is below:

 const int buttonPinOn = 2;   
const int buttonPinOff = 4;
const int ledPin =  13;      

int buttonState1 = 0;      
int buttonState2=0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPinOn, INPUT_PULLUP);
  pinMode(buttonPinOff, INPUT_PULLUP);

void loop() {
  buttonState1 = digitalRead(buttonPinOn);
  buttonState2 = digitalRead(buttonPinOff);
  if (buttonState1 == LOW) {
    digitalWrite(ledPin, LOW);
  } else 
  if (buttonState2==LOW) 
    digitalWrite(ledPin, HIGH);