Create an input interface for your Arduino, using the Serial Monitor to display the data. Write your code for Reading inputs and controlling outputs using analog pins.

Lab 1 – Using Inputs and Outputs

This LAB has three parts:

1- You follow section 2.4 of your Arduino workshop and set up your breadboard and write your code for Reading inputs and controlling outputs using digital pins. (50 points)

https://youtube.com/shorts/SYnhDQNRIU8?feature=sharLinks to an external site.

2- Follow section 2.5 of your Arduino workshop, set up your breadboard, and write your code for Reading inputs and controlling outputs using analog pins. (50 points)

Links to an external site.

3- For the last part follow section 2.6 and create an input interface for your Arduino, using the Serial Monitor to display the data. (50 points)

You can take pictures and explain each part in detail.

Module 4 Readings

In Module 3 you have learned:

How to properly structure your code

Using variables to write more capable programs

Building circuits using a breadboard

In this Module you’ll learn about the rest sections of chapter 2:

Reading inputs and controlling outputs using the digital and analog pins

Communicating via the serial port

By the end of the chapter, you will have created an input interface for your Arduino, using the Serial Monitor to display the data.

(442) Arduino Workshop – Chapter Two – Overview – YouTubeLinks to an external site.

2.4 Using Digital Pins

In this section, we’ll learn how to use digital pins to read inputs and control outputs.

(446) Arduino Workshop – Chapter Two – Using Digital Pins – YouTubeLinks to an external site.

Minimize Video

Source code for ‘LED Button’

int buttonPin = 2;

int ledPin = 3;

void setup() {

// setup pin modes

pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

}

void loop() {

// read state of buttonPin and store it as the buttonState variable

int buttonState = digitalRead(buttonPin);

// write the value of buttonState to ledPin

digitalWrite(ledPin, buttonState);

}

Wiring Diagram for ‘Digital Pins’

2.5 Using Analogue Pins

In this section, we’ll learn how to use analog pins to read inputs and control outputs.

(446) Arduino Workshop – Chapter Two – Using Analogue Pins – YouTubeLinks to an external site.

Source Code for ‘Blink Rate Control’

int ledPin = 3;

int potPin = A0;

void setup() {

// setup pin modes

pinMode(ledPin, OUTPUT);

pinMode(potPin, INPUT);

}

void loop() {

// read the value of the pot and store it as potValue

int potValue = analogRead(potPin);

// turn led on and wait for the time equal to potValue

digitalWrite(ledPin, HIGH);

delay(potValue);

// re-read the value of the pot and store it as potValue

potValue = analogRead(potPin);

// turn led off and wait for the time equal to potValue

digitalWrite(ledPin, LOW);

delay(potValue);

}

Source Code for ‘LED Brightness Control’

int ledPin = 3;

int potPin = A0;

void setup() {

// setup pin modes

pinMode(ledPin, OUTPUT);

pinMode(potPin, INPUT);

}

void loop() {

// read the value of the pot, divide it by 4, and store it as potValue

int potValue = analogRead(potPin) / 4;

// turn led on with the value of potValue

analogWrite(ledPin, potValue);

}

Wiring Diagram for ‘Analogue Pins’

2.6 Displaying Information Using the Serial Port

In this section, we’ll be looking at using the serial port on the Arduino to communicate with a computer via USB.

(446) Arduino Workshop – Chapter Two – Using Serial Monitor – YouTubeLinks to an external site.

Source Code for ‘Serial Monitoring’

int ledPin = 3;

int buttonPin = 2;

int potPin = A0;

void setup() {

// setup pin modes

pinMode(ledPin, OUTPUT);

pinMode(buttonPin, INPUT_PULLUP);

pinMode(potPin, INPUT);

// initialise serial port with baud rate of 9600

Serial.begin(9600);

}

void loop() {

// read the state of buttonPin and store it as buttonState (0 or 1)

int buttonState = digitalRead(buttonPin);

// read the value of the pot, divide it by 4, and store it as potValue

int potValue = analogRead(potPin);

int filteredPotValue = potValue / 4;

// turn led on with the value of potValue

analogWrite(ledPin,filteredPotValue);

// print the value of the button

Serial.print(“Button: “);

Serial.print(buttonState);

Serial.print(”   “);

// print the value of the pot

Serial.print(“Pot: “);

Serial.print(potValue);

Serial.print(”   “);

// print the value of the pot / 4 with a line return at the end

Serial.print(“Pot/4: “);

Serial.println(filteredPotValue);

}

Wiring Diagram for ‘Serial Reading’

Create an input interface for your Arduino, using the Serial Monitor to display the data. Write your code for Reading inputs and controlling outputs using analog pins.
Scroll to top