0% found this document useful (0 votes)
40 views

Module-2-Lesson-2-Workshop-6-Program Structure Arduino IDE 2-REVISED

The document discusses using an Arduino board and serial monitor to control outputs based on sensor inputs. It provides code to: 1) Toggle an LED on and off at set intervals and display the status on the serial monitor. 2) Revise the code to toggle the LED multiple times based on input from the photoresistor, displaying "morning", "afternoon", or "evening". 3) Add a push button and revise the code to display the button state ("on" or "off") on pressing or releasing. The document seeks to demonstrate using the serial monitor interface to monitor physical outputs based on sensor readings and button inputs through Arduino code.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Module-2-Lesson-2-Workshop-6-Program Structure Arduino IDE 2-REVISED

The document discusses using an Arduino board and serial monitor to control outputs based on sensor inputs. It provides code to: 1) Toggle an LED on and off at set intervals and display the status on the serial monitor. 2) Revise the code to toggle the LED multiple times based on input from the photoresistor, displaying "morning", "afternoon", or "evening". 3) Add a push button and revise the code to display the button state ("on" or "off") on pressing or releasing. The document seeks to demonstrate using the serial monitor interface to monitor physical outputs based on sensor readings and button inputs through Arduino code.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

BTC 319 – Microprocessors and Peripherals

Serial Monitor 2

Objective

1) To configure Arduino pin configuration.


2) To design a circuit according to requirements.
3) To create a program that utilizes the serial port/function.

Materials

1 – Arduino Uno
Board
1
–Computer/Simulator
1 – 330 Ω resistor
2 – 100Ω resistor
1 – Breadboard
1 – LED
1 – photoresistor
1– 22 Ω
1– 10 KΩ
1 – tactile switch
Connecting wires

Configuration (Actual Circuit Diagram)

1|Page
BTC 319 – Microprocessors and Peripherals

Code

1) Refer to the program code, explain each line according to each uses or
function.
You may use separate sheet.
 Line 1,2 and 3, is where the declaration of variables pOut in integer data type
that states what pin number is going to be stored and StatusOn and StatusOff
in data type string where the statement that is going to be display is stored.
 Inside the void set up, the line 7 which is pinMode configures the specified pin
as output value. Line 8 where digitalWrite is stated, it configures the value of
the pin as Low. Line 9, serial. Begin function configures maximum bits per
second in transferring data in serial port context.
 Inside the void loop, Serial.printLn in line 14 and 18 is used to prints the data
to the serial port. Line 15 and 19 is function digitalWrite, it configure the value
of pOut as High and Low. Lastly, line 16 and 20 is the delay function where it
sets the time delay of displaying the output data in serial port to 1000
milliseconds.

2|Page
BTC 319 – Microprocessors and Peripherals

2) Provide a sample output based on the above code.

3|Page
BTC 319 – Microprocessors and Peripherals

3) Revise your program using the code below.

4) Explain and provide details to each line. Compare and contrast the two codes.
 Line 1,2,3 and 4 is where the declaration of variables noProcess in integer
data type for number of desire of process, pOut in integer data type that
states what pin number is going to be stored and StatusOn and StatusOff in
data type string where the statement that is going to be display is stored.
 Inside the void set up, the line 7, which is pinMode, configures the specified
pin as output value. Line 8 where digitalWrite is stated, it configures the value
of the pin as Low. Line 9, serial. Begin function configures maximum bits per
second in transferring data in serial port context.
 In void loop, line 19 is where function Serial.printLn is used to print the data to
the serial port. A condition was written in this loop in line 21 where in the
while function Serial.available is equals to 0 or the initial state, function
noProcess in line 23 is equals to the function of serial.ParseInt. For variable a
in line 26 is equals to 1 and a is less than equal to noProcess and so on.
 Inside the void loop, line 29 and 34 Serial.printLn is used to prints the data to
4|Page
BTC 319 – Microprocessors and Peripherals

the serial port. Line 30 and 35 is function digitalWrite, it configure the value of
pOut as High and Low. Lastly, line 31 and 36 is the delay function where it
sets the time delay of displaying the output data in serial port to 1000
milliseconds.

5) Provide a sample output based on the revised code.

5|Page
6) Refer to workshop 3, revised the code such that when using the photoresistor
or varying the resistance value a display and monitor using the serial monitor
would show the following: morning, afternoon, and evening. Write your circuit
and code in the succeeding page. Provide and explanation on how the circuit
and code was achieve.

 Revised code:

 Result:
6|Page
7|Page
 Explaination:
The circuit is from workshop 3 so we did not have to change anything.
In terms of coding, we just added the functions code for serial monitor
such as Serial.begin and Serial.PrintLn and adding condition if else to
the code to achieve the objective in displaying evening, morning and
noon.

7) Refer to workshop 4, revised the code such that when activating the switch
(push button) a display and monitor using the serial monitor would show the
state of the switch (on/off). Write your circuit and code in the succeeding
page. Provide and explanation on how the circuit and code was achieve.

 Revised Code:

8|Page
 Result:

 Explanation:
 The circuit is from workshop 4 so we did not have to change anything.
In terms of coding, we just added the functions code for serial monitor
such as Serial.begin and Serial.PrintLn and adding condition if else to
the code to achieve the objective in displaying the status of the Led
when turned on or off.

8) Think of an application wherein item number 7 and 8 can be applied in the


field of (Justify your answer):
a) Education, and
 Biometric used for teacher’s attendance- displaying an instruction
saying to press a thumb and after the user do the command, the
monitor will show a check icon indicating that the process is success.

b) Industrial or Home application?

 Washing machine- displaying the status if turned on or off.


9|Page

You might also like