You are on page 1of 7

ELEN30031 Electronic System Implementation

Workshop One
Arduino Programming

Welcome to Workshop 1 for Electronic System Implementation. The objective of this workshop is to get
yourself familiar with Arduino programming which you will require to complete the radar system design.

1 Introduction to Adrino
Arduino is an open-source electronic platform based on Arduino boards. Figure 1 shows the PIN diagram of

m
er as
the Arduino UNO board you will use during the workshop series. Take some time to observe the analogue,
digital input/output (I/O) pins and the power supply pins of the board. The board is able to read input and

co
output using its I/O ports such as detecting light on a sensor and activating a motor or touch on a switch,

eH w
and switching on an LED accordingly. In order to tell the board what to do, you have to use the Arduino

o.
Programming Language. The open-source IDE can be downloaded for free. More information is available on:
rs e
http://www.arduino.cc
ou urc
o
aC s
vi y re
ed d
ar stu
is
Th
sh

Figure 1: Pin diagram of a Arduino UNO

2 Getting Started with Arduino


• Visit www.tinkercad.com and create a free account
• Select Circuit − > Create new Circuit (Figure 2)
• Search a breadbaord and a Arduino UNO board and drop them into the circuit area (Figure 3).
• Select Code and the coding area will appear with the following pre-written code. Note: remember to
select the ”text” version of the code. (Figure 4)
https://www.coursehero.com/file/59350819/ws1pdf/
1
Figure 2: Creating a circuit in Tinkercad

m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu

Figure 3: Adding circuit elements in Tinkercad


is

void setup()
{
Th

pinMode(13, OUTPUT);
}
void loop()
{
sh

digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
digitalWrite(13, LOW);
delay(1000); // Wait for 1000 millisecond(s)
}

• Select Start Simulation and observe what is happening to the LED indicators on the Arduino UNO.

• Identify what the code is trying to do.


• STOP the simulation

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 2
m
er as
Figure 4: Displaying the code in Tinkercad

co
eH w
3 Digital output

o.
rs e
Note the digital I/O pins of the Arduino shown in Figure 1. During this exercise, we will observe a waveform
ou urc
at a digital output using an oscilloscope.

• Build the circuit shown in Figure 5 and run the simulation. Note you will have to search and include an
oscilloscope.
o

• Observe the waveform shown in the oscilloscope. Include this waveform in your log book.
aC s
vi y re

• Observe the warning message shown in the LED. In order to run the program without any warning, how
would you modify your circuit?

• Simulate your solution in Tinkercad. Include your revised circuit diagram on your log book.
ed d

• Save your circuit in Tinkercad. The circuit will be automatically be saved on the cloud. Mark sure you
ar stu

observe All changes saved at the upper right hand corner of your Tinkercad window.
• STOP the simulation.

• Go to the Tinkercad home page. Browse your design and rename your circuit under the propertities of
is

the your circuit.


Th
sh

Figure 5: Displaying the digital output in an oscilloscope

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 3
4 Analog Input and Serial.print()
Note the analog I/O pins of the Arduino shown in Figure 1. During this exercise, we will observe the waveform
at an analog output using an oscilloscope. The analog signal will be generated by a power supply.
• Create a new circuit in Tinkercad and implement the circuit shown in Figure 6.
• Set the voltage of the power supply to 5V. You can do this by (a) adjusting the dial in the power supply
or (b) by clicking on the device and changing the value.
• Copy and paste the following code in the code editor and run the simulation.
/* AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools ¿ Serial Plotter menu) Attach the center
pin of a potentiometer to pin A0, and the outside pins to +5V and ground. */
int sensorValue;

// the setup routine runs once when you press reset:


void setup() {

m
Serial.begin(9600); // initialize serial communication at 9600 bits per second:

er as
}

co
eH w
// the loop routine runs over and over again forever:
void loop() {

o.
sensorValue = analogRead(A0); // read the input on analog pin 0:
rs e
Serial.println(sensorValue); // print out the value you read:
ou urc
delay(1000); // delay in between reads for stability
}
• Open the serial monitor within the code editor environment. Select ”code” and the ”Serial Monitor” will
o

be displayed at the bottom right corner (Figure 7). Select the ”Graph” icon for a graphical representation
aC s

of the value.
vi y re

• Change the voltage of the DC voltage output from -1 to 6 V What are the corresponding values shown
on the serial monitor? Explain your observations.
ed d
ar stu
is
Th
sh

Figure 6: Observing the analog input in Tinkercad

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 4
m
er as
co
Figure 7: Display values in serial monitor in Tinkercad

eH w
o.
5 Hardware experiment using Arduino
rs e
ou urc
• Connect your Arduino UNO board to your computer and open the Arduino IDE
• Select the ports and your Arduino under “Tools − > Ports” in the menu.Make sure your board is connected
to your computer.
o

• Configure the circuit shown in Figure 8 using the breadboard, LED, and resistors provided to you.
aC s
vi y re

• Copy the pre-written code in Section 2 into the Arduino IDE compiler and verify and compile the code
(Figure 9). If there is any error message, debug it accordingly.
• Upload the code to your Arduino UNO.
ed d

• Observe and investigate your circuit. Is your circuit working?


ar stu

• To control the blinking speed, which variable needs to be modified?


is
Th
sh

Figure 8: Hardware implementation of the blinking LED using Arduino

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 5
m
er as
co
eH w
o.
rs e
ou urc
Figure 9: Verifying and compiling in Arduino IDE

6 Implementing a basic Knight Rider circuit


o
aC s

In this task, you are required to design a simple LED knight-rider circuit that make use of the digital output
vi y re

PINs of the Arduino UNO.A video demonsting a Knight Rider is uploaded on the LMS.

• Construct the circuit as shown in Figure 10 in Tinkercad

• In Tinkercad, design your Arduino code for each LED to blink for 0.5s
ed d
ar stu

• Simulate your circuit and save your circuit and code for future reference
• Include your code on your log book
• Implement circuit shown in Figure 10 in hardware .
is

• Copy your code from Tinkercad to Arduino IDE software and run the program.
Th

• Compare the performance of the knight rider circuit in simulation and hardware. Discuss your findings.
sh

7 Implementing an ultrasonic sensor to measure the distance


• Create a new Tinkercad circuit

• Search and insert the “Ultrasonic Range Finder” circuit as shown in Figure 11. Note this ultrasonic sensor
is different to the actual one you will use during the implementation of the radar system.
• Click “Code” and investigate how this circuit estimate the distance to an object.
• Run the simulation. Change the code so that the serial monitor can display ”Out of range” for any object
placed outside the range of 5 - 10 cm.
• Run the simulation and change the position of your object and observe if the serial monitor displays the
message when the object is out of the specified range.

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 6
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re

Figure 10: Knight rider circuit in Tinkercad


ed d
ar stu
is
Th
sh

Figure 11: Ultrasonic Range Finder in Tinkercad

https://www.coursehero.com/file/59350819/ws1pdf/
Prepared by Alan Lee and Imali Dias July 2019 7

Powered by TCPDF (www.tcpdf.org)

You might also like