Portfolio Introduction
Workshop Activities 50% Weighting
Mini Project 50% Weighting
This completed portfolio will need submitting to Canvas by the
due date.
Questions please email
Dr Sarah Slater
[email protected]
Student Name Student Number
Portfolio
Contents
Workbook 1 ................................ ................................ ................................ ................................ .................. 4
Activity 1.1: Actual voltage across 5V breadboard pins. ................................ ................................ .......... 4
Activity 1.2: Actual voltage across 3.3V breadboard pins. ................................ ................................ ....... 4
Activity 1.3: Potential Divider Calculations ................................ ................................ ............................. 5
Activity 1.4: 3V Calculations from either the 5V supply or 3.3V supply ................................ ................. 6
Activity 1.5: Voltage Divider circuit readings from Breadboard circuit. ................................ ................ 6
Activity 1.6: LED Circuits ................................ ................................ ................................ ....................... 6
Activity 1.7: Current Measurement ................................ ................................ ................................ ......... 8
Activity 1.8: Fritzing for 4 switches & LEDS ................................ ................................ ......................... 9
Activity 1.9: Fritzing for Number 0 -7 ................................ ................................ ................................ .... 10
Workbook 2 ................................ ................................ ................................ ................................ ................ 11
Activity 2.1: LED Flashing to show decimal number 63 as binary. ................................ ....................... 11
Activity 2.2: 4 LEDâs for counting up in binary from 0 to 15. ................................ ............................... 12
Workbook 3 ................................ ................................ ................................ ................................ ................ 15
Activity 3.1: Circuit Diagram of Button & LED ................................ ................................ .................... 15
Activity 3.2: 3 Switches & Led ................................ ................................ ................................ .......... 17
Activity 3.3: 8 Buttons & LEDs (SWITCH STATEMENTS) ................................ ................................ 19
Workbook 4 ................................ ................................ ................................ ................................ ................ 22
Activity 4.1: Serial Port ................................ ................................ ................................ .......................... 22
Activity 4.2: Serial Port binary to decimal ................................ ................................ ............................. 25
Activity 4.3: Calibrating Analogue Information ................................ ................................ ..................... 28
Activity 4.4: Temperature Sensor & Serial Port ................................ ................................ ..................... 31
Workbook 5 ................................ ................................ ................................ ................................ ................ 34
Activity 5.1: RG B Led and switches ................................ ................................ ................................ ...... 34
Activity 5.2: LED Matrix MAZE ................................ ................................ ................................ ........... 36
Activity 5.3: 1602 LCD Display ................................ ................................ ................................ ............. 40
Wo rkbook 6 ................................ ................................ ................................ ................................ ................ 43
Activity 6.1: PWM ................................ ................................ ................................ ................................ .. 43
Workbook 7 ................................ ................................ ................................ ................................ ................ 46
Activity 7.1: Windscre en Wiper Code using Servos & Temperature Sensor ................................ ......... 46
Individual Project (50%) ................................ ................................ ................................ ............................. 47
Rationale ................................ ................................ ................................ ................................ ................. 47
Timescales ................................ ................................ ................................ ................................ ............... 47
Equipment ................................ ................................ ................................ ................................ ............... 47
The Project ................................ ................................ ................................ ................................ .............. 47
Step 1 produce a detai led description of your project. ................................ ................................ ........ 47
Step 2 Circuit Diagram & Fritzing Schematic ................................ ................................ .................... 47
Step 3 A Program ................................ ................................ ................................ ................................ 48
Step 4 Testing ................................ ................................ ................................ ................................ ..... 48
Step 5 Conclusions ................................ ................................ ................................ .............................. 48
Layout ................................ ................................ ................................ ................................ ................. 48
Demonstrations ................................ ................................ ................... Error! Bookmark not defined.
Marking ................................ ................................ ................................ ................................ ............... 48
All sections carry equal marks. ................................ ................................ ................................ ................... 48
Workbook 1
Activity 1.1: Actual voltage across 5V breadboard pins.
Enter the Value you got here from Step 5.
Activity 1.2: Actual voltage across 3.3V breadboard pins.
Explain in around 100 words why you think the value read by a multi meter on a circuit, may be different
to a simulator value such as TinkerCad.
If the read value is 4.84V on a 5V supply, what would be a sensible tolerance to quote, explain your
answer.
4.88 758 V
Losses experienced in the multimeter readings within the device whereas the simulation software
rids off the equipment errors. The breadboard to multimeter connection experiences resistive
losses from the equipment itself when reading analogue inputs or power input whereas with the
TinkerCAD simulation, the results are ideal as the equipment are calibrated to the data sheet
values.
3.2258 V
= â
?100%
= 5? 4.84
5 ?100%
= 3.2%
This is a sensible tolerance level as nominal voltage for line voltage in real life application is set
for voltage fluctuations [ -5%, 5%].
Activity 1.3: Potential Divider Calculations
Show the working on how you achieved 2.5V
= ? 1
1+ 6
= 5? 220
220 + 220 = 2.5
The potential divider is computed as:
Using two resistors of the same value. R1 = 220 ohms, R2 = 220ohms
Activity 1.4: 3V Calculations from either the 5V supply or 3.3V supply
Activity 1.5: Voltage Divider circuit readings from Breadboard circuit.
Activity 1.6: LED Circuits
Each resistor Value
3= 5? 1
1+ 6 ? 0.6 5+ 6 = 1
0.41= 0.62
1= 1.52
3= 3.3? 1
1+ 2 ? 0.909 1+ 2 = 1
0.091 1= 0.909 2
1= 9.98 2
To get 3V, with a 5V input,
With 3.3V input,
Vin = 4.84 V
Vout = 3.25 V
220 ohms 220 ohms
Total resistance Calculation
Measured Resistance
If measured resistance is not the same, why not? If you simulated this, why might the real value be
different.
= 1+ 6 ? 1
56
= 440
220 ?220 = 0.0091 ?
R1 || R2
0.005 ohms
Losses due to equipment noises.
Activity 1.7: Current Measurement
Calculation of current flowing into LED
Actual measured value of current
Why might they be different?
0.022 amps
0.05 amps
Due to difference in the resistance simulated as compared to the physical equipment values.
Activity 1.8: Fritzing for 4 switches & LEDS
Activity 1.9: Fritzing for Number 0 -7
Workbook 2
Activity 2.1: LED Flashing to show decimal number 63 as binary.
63 as binary, including working
Copy & Post your code with a suitable comment at the top of code with your name & student number ?
63 10 = 00111111 2
Binary 2^7 2^6 2^5 2^4 2^3 2^2 2^1 2^0
Dec
equivalent
64 32 16 8 4 2 1
63_10 - - 63 31 15 7 3 1
Binary
equivalent
0 0 1 1 1 1 1 1
// student name
// student registration number
int LedPin[] = {5,6,7,8,9,10,11,12};
void setup()
{
for (int i=0;i<8;i++)
{
pinMode(LedPin[i],OUTPUT);
}
}
}
Activity 2. 2: 4 LEDâs for counting up in binary from 0 to 15.
void loop()
{
for (int j=0;j<9; j++)
{
if(j<6)
{
digitalWrite(LedPin[j],HIGH);
}
else
{
digitalWrite(LedPin[j],LOW);
}
}
delay(3000);
for (int k=0;k<9;k++)
{
digitalWrite(LedPin[k],LOW);
}
delay(3000);
} }
Fritzing Circuit diagram for Step 4 i.e. 4 LEDs
Arduino Program for Step 4 i.e. 4 LEDs
// student_name
// student_registration_number
int LedPin[] = {2,5,8,12}; //Listed from MSB to LSB
void setup()
{
for (int i=0;i<4;i++)
pinMode(LedPin[i], OUTPUT);
}
void loop()
{
//designing an up counter from 0 to 15
for (byte c=0; c<=15; c++) //c - up counter
{
disp_binary(c);
delay(2000);
}
}
Workbook 3
Activity 3.1: Circuit Diagram of Button & LED
//printing out the binary values on the LED using a binary upcounter model
void disp_binary(byte dispval)
{
for (int j=0; j<4;j++)
{
if (bitRead(dispval, j) == 1)
{
digitalWrite(LedPin[j],HIGH);
}
else
{
digitalWrite(LedPin[j],LOW);
}
}
}}
Fritzing
Activity 3.2: 3 Swit ches & Led
Fritzing Circuit Diagram
Arduino Program
//student name
//student registration number
int buttonPin[] = {10,11,12}; //The three push buttons attached to the arduino board
int LedPin = 5; //LED pin
//Variable measured by time taken since previous debounce
long lastDebounceTime = 0;
long debounceDelay = 50;
int firstcode, secondcode, thirdcode;
//checking how many times the push button is pressed
int numberClicks = 0;
int stateB1 = 0;
int stateB2 = 0;
int stateB3 = 0;
int state LastB = 0;
void setup() {
for (int i=0; i<3; i++)
{
pinMode(buttonPin[i],INPUT);
}
pinMode(LedPin, OUTPUT);
}
Activity 3.3: 8 Buttons & LEDs (SWITCH STATEMENTS)
void loop() {
//Reading the state of the button
stateB1 = digitalRead(buttonPin[0]);
stateB2 = digitalRead(buttonPin[1]);
stateB3 = digitalRead(buttonPin[2]);
//checking the state of all the buttons
if(stateB1 == HIGH && stateB2 == LOW && stateB3 ==LOW & numberClicks == 0) {
firstcode = 1;
numberClicks = 1;
digitalWrite(LedPin, HI GH);
delay(500);
digitalWrite(LedPin, LOW);
delay(500);
}
if(stateB1 == LOW && stateB2 == HIGH && stateB3 ==LOW & numberClicks == 0) {
firstcode = 2;
numberClicks = 1;
digitalWrite(LedPin, HIGH);
delay(500);
digitalWrit e(LedPin, LOW);
delay(500);
}
if(stateB1 == LOW && stateB2 == LOW && stateB3 == HIGH & numberClicks == 0)
{
firstcode = 3;
numberClicks = 1;
Fritzing
Arduino Program
Workbook 4
Activity 4.1: Serial Port
Fritzing
Arduino Program
void setup() {
Serial.begin(9600); //9600 - baud rate
}
void loop() {
Serial.println('Testing the serial port');
delay(3500);
}
Screen Shot of Serial Port
Activity 4.2: Serial Port binary to decimal
Code
int binVal; //variable that stores the binary input
int decVal; //variable that stores the decimal output
void setup( ) {
Serial.begin(9600); //9600 - baud rate
Serial.println("Binary to Decimal converter program"); //description of the project
}
void loop() {
//reading binary input from the serial monitor
Serial.println("Enter the Binary value: "); //prompts the user input
while(Serial.available() == 0)
{
//wait for user input
}
binVal = Serial.parseInt(); //Reads the input data and type casts it to integer
decVal = convertBinaryToDecimal(binVal); //Calls the function that converts the binary in put to
Decimal.
Serial.print("Binary Value: ");
Serial.print(binVal);
Serial.print(" \t\t Decimal Value: ");
Serial.println(decVal);
}
Screen Shot of Serial Port
Activity 4.3: Calibrating Analogue Information
Code
float sensorValue = 0;
float potVal = 0;
void setup()
{
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
Serial.begin(9600);
Serial.println("Potentiometer calibration");
}
void loop()
{
// read the value from the sensor
sensorValue = analogRead(A0);
potVal = map(sensorValue, 0,1023,0,5);
Serial.print("Spin value: ");
Seri al.print(sensorValue);
Serial.print(" Voltage value: ");
Serial.println(potVal);
delay(2500);
}
Pot Resistance Clockwise
Pot Resistance Anti -clockwise
Sample of Values
Pot Resistance against Voltage change
Pot Resitance Voltage Measured
0 0
0.3 1.5
0.5 2.5
0.7 3.5
1 5
1 kohm
0 ohm
Screen Shot of Meaningful Serial Port Output, not just numbers
Activity 4.4: Temperature Sensor & Serial Port
Code - Centigrade to Serial port, but when button Pressed Fahrenheit Displayed Instead
//temperature sensor TMP
#define tempPin A0
int buttonState = 0;
float tempVal,TempF,tempC;
void setup() {
pinMode(2, INPUT);
pinMode(13, OUTPUT);
pinMode(tempPin,INPUT);
Serial.begin(9600);
}
void loop() {
//reading values from the temperature sensors
float tempC = analogRead(tempPin); //analog value r ead from the arduino board
//converts the analog data to temperature
float tempVal = double(tempC)/1024;
tempVal = tempVal * 5;
tempVal = tempVal - 0.5;
tempVal = tempVal *100;
// converting the temperature to fahrenheit
float tempF = ((temp Val*9)/5)+32;
// read the state of the pushbutton value
buttonState = digitalRead(2);
}
// check if pushbutton is pressed. if it is, the
// buttonState is HIGH
if (buttonState == HIGH) {
// turn read the temperature in Fahrenheit
Serial.print("Temp(Fahrenheit): ");
Serial.println(tempF);
} else {
// read the temperature in celsius
Serial.print("Temp(Celsius): ");
Serial.p rintln(tempVal);
}
delay(1000); // Delay a little bit to improve simulation performance
}
Screen Shot of Serial Port
Workbook 5
Activity 5.1: RGB Led and switches
Fritzing
Arduino Program
Activity 5.2: LED Matrix MAZE
int buttons[] = {9,10,11};
int rgb[]={3,5,6}; //Red, Green, Blue
void setup(){
for (int i=0;i<3;i++)
{
pinMode(buttons[i],INPUT);
}
for (int j=0; j<3;j++)
{
pinMode(rgb[j],OUTPUT);
}
void loop() {
//printing out blue color
if(digitalRead(buttons[0]) ==HIGH) {
digitalWrite(rgb[2],1 );
}
else {
digitalWrite(rgb[2],0);
}
//printing out red color
if(digitalRead(buttons[1]) ==HIGH) {
digitalWrite(rgb[0],1);
}
else
{
Arduino Code
#define ROW_1 2
#define ROW_2 3
#define ROW_3 4
#define ROW_4 5
#define ROW_5 6
#define ROW_6 7
#define ROW_7 8
#define ROW_8 9
#define COL_1 10
#define COL_2 11
#define COL_3 12
#define COL_4 13
#define COL_5 A0
#define COL_6 A1
#define COL_7 A2
#define COL_8 A3
const byte rows [] = {
ROW_1 , ROW_2 , ROW_3 , ROW_4 , ROW_5 , ROW_6 , ROW_7 , ROW_8
};
const byte col [] = {
COL_1 ,COL_2 , COL_3 , COL_4 , COL_5 , COL_6 , COL_7 , COL_8
};
// The display buffer
// It's prefilled with a smiling face (1 = ON, 0 = OFF)
byte ALL [] =
{B11111111 ,B11111111 ,B11111111 ,B11111111 ,B11111111 ,B11111111 ,B1111111
1,B11111111 };
byte EX [] =
{B00000000 ,B00010000 ,B00010000 ,B00010000 ,B00010000 ,B00000000 ,B0001000
0,B00000000 };
byte A[] = {
B00000000 ,B00111100 ,B01100110 ,B01100110 ,B01111110 ,B01100110 ,B01100110
,B01100110 };
byte B[] =
float timeCount = 0;
void setup ()
{
// Open serial port
Serial .begin (9600 );
// Set all used pins to OUTPUT
// This is very important! If the pins are set to input
// the display will be very dim.
for (byte i = 2; i <= 13 ; i++ )
pinMode (i, OUTPUT );
pinMode (A0 , OUTPUT );
pinMode (A1 , OUTPUT );
pinMode (A2 , OUTPUT );
pinMode (A3 , OUTPUT );
}
void loop () {
// This could be rewritten to not use a delay, which would make it
appear brighter
delay (5);
timeCount += 1;
if (timeCount < 20 )
{
drawScreen (A);
}
else if (timeCount < 40 )
{
drawScreen (R);
}
else if (timeCount < 60 )
{
drawScreen (D);
}
else if (timeCount < 80 )
{
drawScreen (U);
}
else if (timeCount < 100 )
{
drawScreen (I);
}
else if (timeCount < 120 )
{
drawScreen (N);
}
else if (timeCount < 140 ) {
drawScreen (O);
}
else if (timeCount < 160 )
{
drawScreen (ALL );
}
else if (timeCount < 180 )
{
drawScreen (ALL );
}
else {
// back to the start
timeCount = 0;
}
}
void drawScreen (byte buffer2 [])
{
// Turn on each row in series
for (byte i = 0; i < 8; i++ ) // count next row
{
digitalWrite (rows [i], HIGH ); //initiate whole row
for (byte a = 0; a < 8; a++ ) // count next row
{
// if You set (~buffer2[i] >> a) then You will have
Take a picture of your LED Matrix Maze and include it here, please reduce the size and quality as it will
be too large else ?
Activity 5.3: 1602 LCD Display
Fritzing
Arduino Program
// include the library code:
#include