COMP 600
Emerging Wireless Technologies
Submitted By- Jassica Sahi
Section -03
Student ID- 10294665
Lab 2: Building a Circuit with Arduino Using Simulation
Objectives:
To use Arduino boards, basic components, IDE, and programming language in basic
implementation to send output signals.
Tasks:
1. Work individually to perform all the tasks.
2. Please work individually and navigate to https://www.tinkercad.com/ and sign up for a free
account.
3. Go to the dashboard and choose “Circuits” then create a new circuit
4. Make sure to choose “Basic Components” , then add
the necessary component to build up the circuit as shown in the figure below.
Page 1 of 7
COMP 600
Emerging Wireless Technologies
Page 2 of 7
COMP 600
Emerging Wireless Technologies
5. In the “Code” area, choose text format and write the following code for Arduino
void setup()
{
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(7, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(7, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}
6. Start the simulation
7. and study carefully the previous steps, then proceed with the next steps.
8. Add another LED (to be connected to different digital pin) and modify the code so both LEDs
will blink at the same time- relatively- and increase the blinking speed. (Copy and paste your
modified code below, Also take a snapshot of your modified circuit and paste it below in the
box)
Put your modified code here:
// C++ code
//
void setup()
{
pinMode(7, INPUT);
pinMode(8,INPUT);
Page 3 of 7
COMP 600
Emerging Wireless Technologies
void loop()
{
digitalWrite(7,HIGH);
digitalWrite(8,HIGH);
delay(100);//Wait for 100 millisecond(s)
digitalWrite(7,LOW);
digitalWrite(8,LOW);
delay(100);// Wait for 100 millisecond(s)
Put your circuit here:
Page 4 of 7
COMP 600
Emerging Wireless Technologies
9. Discussion Questions:
a) What is the function in terms of programming? Explain with more details and give
illustration example.
b) What are the benefits of setup() & loop() functions? Explain with more details.
Put your Answers here:
a) It is an organized code that can be reused to perform different tasks (multiple times). It is
designed to take specific input and gives us desired output (called arguments). A function
contains a Name, Input Parameters, Body, Return Statement, and Function Call.
Name- It has a unique name that identifies with the program. (Should be descriptive and
indicate the purpose or action performed by function).
Input Parameters- These are called arguments or variables. These allow a person to pass
the value and can accept zero or more input parameters.
Body- This contains all the instructions or code that would define what exactly a function
does.
Return Statement- A function has an output which we call it a return value. It is optional.
Function Call- One needs to call a function by its name or by passing an argument to
execute it.
Example-
#include <iostream>
// Function declaration
void printHelloWorld();
int main() {
// Function call
printHelloWorld();
return 0;
}
// Function definition
void printHelloWorld() {
std::cout << "Hello, World!" << std::endl;
}
Page 5 of 7
COMP 600
Emerging Wireless Technologies
b) The benefits of setup() & loop() functions are as follows-
Setup() – It is called once when the Arduino board starts or is reset. It is used to set up
communication protocols and other necessary one-time setup tasks.
The main benefits of the setup() function are-
1. One-Time Tasks- One can perform any one-time task which is required by the project.
2. Communication Setup- We can initialize the communication protocols such as I2C or
SPI.
3. Pin configuration- One can configure pin mode by setting up pins and input or
outputs.
4. Initialization- Initialization of variable that needs to be setup before its main
execution.
Loop() – It is executed repeatedly after the setup(). It is the main part of Arduino.
The main benefits of the loop() function are-
1. Continuous Execution – It runs in an infinite loop. It allows the program to perform
the tasks continuously.
2. Event-Driven Programming – One can write code that responds to various events or
conditions. For instance- reading data, responding to button presses.
3. Real-Time Control- One has the control over timing and execution of the speed of the
code. By using the functions delay(), millis() and micros().
10. Conclusion:
Put your Conclusion here:
To recapitulate, the microcontroller ARDUINO is an open-source platform
used for creating and prototyping electronic devices. It has both software and
hardware components for building projects.
The software components include IDE which is used for writing, compiling
and uploading code.
Assessment Criteria: (Detailed Rubric shared at D2L)
Awarded
Task Steps Max. Marks Marks
Lab steps & Hands-on
requirements 5
(Discussion & Conclusion) 5
10
Page 6 of 7
COMP 600
Emerging Wireless Technologies
Submission Guidelines:
Go to D2L and answer the lab related question during the lab duration as per your
schedule.
Due Date: Check D2L. (Please submit the labs on time since no extensions; Zero
Tolerance).
Submission Method: Dropbox folder ONLY for this file.
Page 7 of 7