Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

FAKULTI KEJURUTERAAN

JABATAN KEJURUTERAAN ELEKTRIK &


ELEKTRONIK

EEE 2241
ELECTRICAL & ELECTRONIC ENGINEERING
LAB II

Microprocessor and Microcomputer 1


(M1)
Microprocessor LAB
Group Number:

Group Members: Matrix No. :

1.

2.

3.

4.

LAB 3-1
Microprocessor and
Microcomputer 1 (M1)

OBJECTIVES

The goals for this microprocessor and microcomputer lab are for you to learn how to:

1) Setup the Arduino and the development software on the host computer
2) Write simple programming for the microprocessor and download to the Arduino
3) Interact with simple sensors and actuators
4) Acquire data to the host computer through the USB port

EQUIPEMENT REQUIRED

1) Personal computer running Windows XP/ Windows Vista/ Windows 7 with


minimum of 1GB RAM with USB ports
2) Arduino kit

PRELAB WORK

1) Install Arduino in your personal computer


2) Revise on your programming and electric circuit subjects

1. INTRODUCTION

This lab will introduce Arduino design environment for implementing microprocessor
programming in the Arduino board. In some ways you could think of Arduino as the child
of traditional desktop and laptop computers. At its roots, the Arduino is essentially a small
portable computer; microcomputer. It is capable of taking inputs (such as the push of a
button or a reading from a light sensor) and interpreting that information to control various
outputs (like a blinking LED light or an electric motor). That's where the term "physical
computing" is born - an Arduino is capable of taking the world of electronics and relating
it to the physical world in a real and tangible way.

The Arduino Uno is one of several development boards based on the ATmega328. Arduino
Uno is particularly interesting because of its extensive support network and its versatility.
It has 14 digital input/output pins (6 of which can be PWM outputs), 6 analog inputs, a 16
MHz crystal oscillator, a USB connection, a power jack, an ICSP header, and a reset button.

LAB 3-2
Once you complete this lab, you should be able to:

1) Navigate comfortably through the Arduino design environment.


2) Compile, debug and test your microprocessor programs.
3) Download and run your programs on Arduino board.

2. Install Arduino

In order to get your Arduino up and running, you'll need to download some software first
from www.arduino.cc. This software, known as the Arduino IDE, will allow you to
program the Arduino to do exactly what you want. With an internet-capable computer, open
up your favorite browser and type in the following URL into the address bar:

arduino.cc/en/Main/Software

Choose the appropriate Operating System installation package for your computer. Connect
your Arduino to one of your computers USB inputs. Install the appropriate drivers for your
Operating Systems.

3. Experiments

3.1 Blinking LED

Components:

1) Breadboard
2) LED
3) Jumper wires
4) Arduino
5) 220 Ohm resistor
6) USB A-B cable

LEDs (light-emitting diodes) are small, powerful lights that are used in many different
applications. To start off, we will program a simple task of blinking an LED; turning a light
on and off. It might not seem like much, but establishing this important baseline will give
you a solid foundation as we work toward more complex experiments.

LAB 3-3
Figure 1: Schematic for your blinking LED experiment

Below are the codes you need to program in Arduino IDE:

void setup ()
{
pinMode (3, OUTPUT);
}

void loop ()
{
digitalWrite (3, HIGH);
delay (1000);
digitalWrite (3, LOW);
delay (1000);

LAB 3-4
QUESTIONS (ALL ANSWER CORRECTLY & RELEVANT EXPLANATION – 20 MARKS)

What is the frequency of the LED blink?

How can you control the timing of the blinking?

Keep increasing the blink rate; what is the fastest blink rate you can detect with your eye?

Why do we put comments in the sketch/code?


Does setup() always come first?
Explain what it means by setting a pin using pinMode ()?
Do you always have to set pins as output?
Is pinMode() must always be attached to pin 13 or LED_BUILTIN?
Does it matter which pins you declare?
Does setting the pin mode to output is the only thing that you do in setup ()?

3.2 RGB LED

RGB, or red-green-blue, LEDs have three different color-emitting diodes that can be
combined to create all sorts of colors. In this circuit, you’ll learn how to use an RGB LED
to create unique color combinations. Depending on how bright each diode is, nearly any
color is possible!

Components needed can be referred to the circuit schematic.

LAB 3-5
Figure 2: Schematic for your RGB LED experiment

Below are the codes you need to program in Arduino IDE:

void setup ()
{
pinMode (9, OUTPUT);
pinMode (9, OUTPUT);
pinMode (9, OUTPUT);
}

void loop ()
{
// Blue Light
analogWrite (9, 0);
analogWrite (10, 255);
analogWrite (11, 255);
delay (1000);
// Green Light
analogWrite (9, 255);
analogWrite (10, 0);
analogWrite (11, 255);
delay (1000);
// Red Light
analogWrite (9, 255);
analogWrite (10, 255);
analogWrite (11, 0);
delay (1000);
}

LAB 3-6
QUESTIONS (ALL ANSWER CORRECT & RELEVANT EXPLANATION – 4 MARKS)

Sometimes the RED LED is brighter than other LEDs. How to make the brightness more
balanced in terms of circuitry and in the coding?

Why at one time, only 2 LEDs are on, and 1 is off?

3.3 Melody via piezo manipulation

In this circuit, we'll again bridge the gap between the digital world and the analog world.
We'll be using a buzzer that makes a small "click" when you apply voltage to it (try it!). By
itself that isn't terribly exciting, but if you turn the voltage on and off hundreds of times a
second, the buzzer will produce a tone. And if you string a bunch of tones together, you've
got music!

Components needed can be referred to the circuit schematic.

Figure 3: Schematic for your piezo experiment

Below are the codes you need to program in Arduino IDE:

LAB 3-7
void setup () {}

void loop ()
{
tone (9,262,250)
delay (250)
tone (9,262,250)
delay (250)
tone (9,392,250)
delay (250)
tone (9,392,250)
delay (250)
tone (9,440,250)
delay (250)
tone (9,440,250)
delay (250)
tone (9,392,500)
delay (500)
}

QUESTIONS (ALL ANSWER CORRECT & RELEVANT EXPLANATION – 11 MARKS)

How do you control the tone? Can you mimic other song?

Correct answers & explanation – 4 marks

Can you present the codes in a better, more concise way?

Code – 3 marks, connection – 2 marks , explanation – 2 marks

LAB 3-8
3.4 LIGHT THEREMIN

Components needed:

1) 1 piece of Piezo
2) 1 piece of Photoresistor
3) 10k Ohm resistor
4) Jumper wires
5) Arduino & USB A-B cable
6) Breadboard

By using a photoresistor and piezo element, make a light-based theremin.

A theremin is an instrument that makes sounds based on the movement of user’s hands around
the instrument. The theremin detects user’s hands in relation to two antennas by reading the
capacitive change on the antennas. These antennas are connected to analog circuitry that create
the sounds. In Arduino, it is possible to emulate using tone () function. You will be using
photoresistor to detect the amount of light and by moving your hand or an object over the sensor
(photoresistor), you will change the amount of light that the photoresistor may detect. The
change in voltage on the analog pin will determine the frequency note to play.

Instruction on circuit connection:

1) One pin (5V) is connected to power bus. One pin (ground) is connected to ground bus.
2) Take your piezo and connect one end to ground, the other end to digital pin 8 on the
Arduino.
3) Place your photoresistor on the breadboard, connecting one end to 5V. Connect the
other end to Arduino analog A0 pin and to ground through a 10k Ohm resistor.

Draw the circuit schematic based on the instruction.

Make your own connection on the breadboard and make sure to vary the generation of sound
based on the movement of object on the photoresistor.

The sketch/code in Arduino is given as follow:

// variable to hold sensor value

int sensorValue;

// variable to calibrate low value

int sensorLow = 1023;

// variable to calibrate high value

int sensorHigh = 0;

LAB 3-9
// LED pin

const int ledPin = 13;

void setup() {

// Make the LED pin an output and turn it on

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, HIGH);

// calibrate for the first five seconds after program runs

while (millis() < 5000) {

// record the maximum sensor value

sensorValue = analogRead(A0);

if (sensorValue > sensorHigh) {

sensorHigh = sensorValue;

// record the minimum sensor value

if (sensorValue < sensorLow) {

sensorLow = sensorValue;

// turn the LED off, signaling the end of the calibration period

digitalWrite(ledPin, LOW);

void loop() {

//read the input from A0 and store it in a variable

sensorValue = analogRead(A0);

LAB 3-10
// map the sensor values to a wide range of pitches

int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);

// play the tone for 20 ms on pin 8

tone(8, pitch, 20);

// wait for a moment

delay(10);

QUESTIONS (ALL ANSWER CORRECT & RELEVANT EXPLANATION – 4 MARKS)

1) What is the tone () function for?


2) Do we need to calibrate the sensor?

LAB 3-11
3.5 OPEN ENDED PROJECT: Music with LED

Instruction:

Based on previous basic lessons, by using previous components or by adding new components,
create some music or simple tunes, together with some lights to accompany. You can combine
the circuitry and programming to create a melody with blinking RGB LEDs.

Based on your own creativity, create your own circuit (schematic diagram) and your own
sketch to be uploaded into Arduino.

Make a video of your group explaining your project, showing the advances of your project
circuitry and/or programming and a demonstration; all within 3 minutes, send the video to your
instructor.

Optional:

Send to your lecturer to be uploaded to youtube channel and get you friends to view and like
it.

To be included in report:

 Background of the experiment – 2 marks


 Code/sketch to be uploaded in Arduino – 5 marks
 The correct circuit connections (final one is sufficient) – 5 marks
 The results of LED blinkings – 5 marks
 Discussion of your project experiment – 2 marks

To be sent to your instructor:

 Video of final development with explanation – 5 marks

LAB 3-12

You might also like