Module-2-Lesson-2-Workshop-6-Program Structure Arduino IDE 2-REVISED
Module-2-Lesson-2-Workshop-6-Program Structure Arduino IDE 2-REVISED
Serial Monitor 2
Objective
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
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
3|Page
BTC 319 – Microprocessors and Peripherals
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|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.