Professional Documents
Culture Documents
Lab 3 Microprocessor and Microcomputer (Arduino) - 2019
Lab 3 Microprocessor and Microcomputer (Arduino) - 2019
EEE 2241
ELECTRICAL & ELECTRONIC ENGINEERING
LAB II
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
PRELAB WORK
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:
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
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
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)
Keep increasing the blink rate; what is the fastest blink rate you can detect with your eye?
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!
LAB 3-5
Figure 2: Schematic for your RGB LED experiment
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?
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!
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)
}
How do you control the tone? Can you mimic other song?
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
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.
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.
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.
int sensorValue;
int sensorHigh = 0;
LAB 3-9
// LED pin
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
sensorValue = analogRead(A0);
sensorHigh = sensorValue;
sensorLow = sensorValue;
// turn the LED off, signaling the end of the calibration period
digitalWrite(ledPin, LOW);
void loop() {
sensorValue = analogRead(A0);
LAB 3-10
// map the sensor values to a wide range of pitches
delay(10);
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:
LAB 3-12