You are on page 1of 9

QUESTION ONE (20 marks) Compulsory

a). Consider the following connection of an external LED to an Arduino board.


Write code to make the external LED blink [6 marks]

// Define the LED pin


const int ledPin = 13;

void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
}

void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on
delay(1000); // Wait for one second
digitalWrite(ledPin, LOW); // Turn the LED off
delay(1000); // Wait for one second
}

b). Distinguish between Von Neumann Architecture and the Harvard Architecture as used
in Classification of Microcontroller. [4marks]
c). We can get LEDs in a variety of colors these days, but what about an LED that can
change color. We all know that we can use a combination of Red, Green, and Blue (RGB)
to get any color. In this question, you are to design and write code for an Arduino
application that can give 16 million color combinations with an RGB LED.

i) Draw a possible wire connection on the breadboard for the case [4 marks]

RGB LED
|||
|||
|||
|||
|||
|||
|||
|||
+---| | |---+
| |
| Arduino Uno |
| |
+------------+

RGB LED pins:


- Red pin -> Arduino digital pin 9
- Green pin -> Arduino digital pin 10
- Blue pin -> Arduino digital pin 11

ii) Write code that will make the RGB LED change the few colors. [6 marks]
// Define the pins for the RGB LED
const int redPin = 9;
const int greenPin = 10;
const int bluePin = 11;

void setup() {
// Set the RGB pins as outputs
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}

void loop() {
// Cycle through some example colors
setColor(255, 0, 0); // Red
delay(1000);
setColor(0, 255, 0); // Green
delay(1000);
setColor(0, 0, 255); // Blue
delay(1000);
setColor(255, 255, 0); // Yellow
delay(1000);
setColor(255, 0, 255); // Magenta
delay(1000);
setColor(0, 255, 255); // Cyan
delay(1000);
setColor(255, 255, 255); // White
delay(1000);
}

// Function to set the RGB LED color


void setColor(int redValue, int greenValue, int blueValue) {
analogWrite(redPin, redValue);
analogWrite(greenPin, greenValue);
analogWrite(bluePin, blueValue);
}
QESTION TWO (15 marks)
Given the following timing diagram and the light on/off SM, determine the value of B0 at
the specified times. [15 marks]

i) 0 s [3 marks] - 0
ii) 1 s [3 marks] -1
iii) 2 s [3 marks] - 0
iv) 3 s [3 marks]-1
v) 4 s [3 marks] -1

QESTION THREE (15 marks)


a).Explain TWO main differences between Embedded System and General Purpose
Computing System. [4marks]
b).Other than the number of bits and memory architecture, outline three other ways of
classifying microcontrollers and give one example for each. [3marks]
● Instruction Set Architecture (ISA):
● Example: Reduced Instruction Set Computing (RISC) vs. Complex
Instruction Set Computing (CISC)
● Example: ARM Cortex-M series (RISC) vs. Intel x86 (CISC)
● Performance and Power Consumption:
● Example: Low-Power Microcontrollers vs. High-Performance
Microcontrollers
● Example: Atmel AVR (low-power) vs. Intel Core i7 (high-performance)
● Connectivity and Communication Interfaces:
● Example: Wired vs. Wireless Communication
● Example: Microchip PIC18F45K22 (wired) vs. ESP32 (wireless)

c).Explain the main difference between a microprocessor and a microcontroller in terms


of the Tasks executed. [2marks]

● Microprocessor: Primarily executes general-purpose computing tasks. It is


designed to perform arithmetic, logical, and control operations. Microprocessors
are typically used in systems where the processing requirements are dynamic
and varied, such as personal computers or servers.
● Microcontroller: Specialized for executing specific tasks or functions in
embedded systems. In addition to processing tasks, microcontrollers often
integrate memory, input/output peripherals, timers, and other components on a
single chip. They are tailored for dedicated applications and are commonly found
in devices where real-time operation, low power consumption, and cost efficiency
are critical, such as in automotive systems, consumer electronics, and industrial
control systems.

d).Write a program using a selected a language that reads a pushbutton connected to a


digital input pin 7 and turns on an LED connected to a digital output 13 when the button
is pressed.
[6marks]
// Define the pin numbers
const int buttonPin = 7; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin

// Variables will change:


int buttonState = 0; // variable for reading the pushbutton status

void setup() {
// Initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// Initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}

void loop() {
// Read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// Check if the pushbutton is pressed. If it is, the buttonState is HIGH:


if (buttonState == HIGH) {
// Turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// Turn LED off:
digitalWrite(ledPin, LOW);
}
}

QESTION FOUR (15 marks)


a).Explain and give an example of an embedded system [5 marks]
An embedded system is a combination of computer hardware and software, designed for a
specific function or functions within a larger system.
It can operate independently or as a part of a larger system.
Embedded systems are typically optimized for efficiency and performance, and they often
operate with minimal or no user interaction

One common example of an embedded system is a digital watch2. A digital watch is designed
to perform a specific task, which is to keep and display time. It operates independently without
any need for user interaction, except for setting the time. The watch uses a microcontroller to
keep track of time and to control the display. Despite its complex functionality, a digital watch is
compact, affordable, and requires very little power to operate

b).Consider the following schematic diagram for a serial communication


Two Arduino boards are used. The Arduino Uno on the left is the sender and the Arduino
Mega on the right is the receiver. We use the Mega to make it easier to display debugging
information on the computer. The Arduinos are connected together using digitals 0 and 1
(RX and TX) on the Uno and digitals 16 and 17 (RX2 and TX2) on Mega. The receiver
on one needs to be connected to the transmit on the other and vice versa. The Arduinos
also need to have a common reference between the two, this is done by running a
ground
wire. The first step in creating a serial communication system is to package the string to
be communicated. In general a packet is comprised of some start byte, a payload (the
data
you wish to send), and a checksum to validate your data. Here, the packet is: [0x53]
+[counter value]+[static value]+ [checksum]. The receiver code is shown below
Write the sender code for the above receive information
#include <SoftwareSerial.h>

SoftwareSerial mySerial(0, 1); // RX, TX

unsigned char START_BYTE = 0x53; // ASCII "S"


unsigned char counterValue = 0;
unsigned char staticValue = 5; // Example static value
unsigned char checksum;

void setup() {
mySerial.begin(9600);
}

void loop() {
counterValue++; // Increment counter value

checksum = counterValue + staticValue; // Calculate checksum

mySerial.write(START_BYTE);
mySerial.write(counterValue);
mySerial.write(staticValue);
mySerial.write(checksum);

delay(1000); // Wait for a second before sending the next packet


}

You might also like