Campus: midrand faculty: information tecnology



Download 1.08 Mb.
Page2/4
Date25.08.2023
Size1.08 Mb.
#61919
1   2   3   4
RASPBERRY PI CODE
% Participated

1

Student Full Name

Vusi Matlou

20%

Student Number

MD.2022.Y9G2G3

Contact Number

0685966897

Signature

V.K.M

2

Student Full Name

Tanaka Nyabanga

20%

Student Number

DU.2022.T5T4D8

Contact Number

0670380258

Signature

T.N

3

Student Full Name

Louisa Mathabela

20%

Student Number

MD.2022.S8L6F8

Contact Number

076442 2413

Signature

L.M.

4

STUDENT DETAILS

Bafokeng Molisana
MD.2022.Z3V7N1
0680229410
L.M

20%

5

Student Full Name

Latisha Mashilwane

20%

Student Number

MD.2022.p0p9n6

Contact Number

084 884 2292

Signature

L.M.



Marks Awarded:







%


Signature

Date

Group Assignment Coversheet 2021 | V1.1 Page 2 of 2

TABLE OF CONTENTS

Contents


QUESTION 1 1
CODE EXPLANATION 2
SCENARIO 1 3
SCENARIO 2 3
SCENARIO 3 3
QUESTION 2 3
Arduino Thermostat 3
INTRODUCTION 3
Step 1: Materials 3
STEP 3 : ASSEMBLE THE BOARD 5
CIRCUIT DIAGRAM 6
TINKERCAD DIAGRAM 6
STEP 4: VIDEO 6
REFERENCE 7



TABLE OF FIGURES

Figure 1 SCENARIO 1 3
Figure 2 SCENARIO 2 3
Figure 3 SCENARIO 3 3
Figure 4 ARDUINO THERMOSTAT 3
Figure 5 CIRCUIT DIAGRAM 6


QUESTION 1


section .data
prompt1 db 'Enter the first integer: '
prompt1_len equ $-prompt1
prompt2 db 'Enter the second integer: '
prompt2_len equ $-prompt2
result1 db 'The first integer is larger.', 0
result1_len equ $-result1
result2 db 'The second integer is larger.', 0
result2_len equ $-result2
result3 db 'The integers are equal.', 0
result3_len equ $-result3
section .bss
firstInteger resd 1
secondInteger resd 1
section .text
global _start
_start:
; Prompt the user to enter the first integer
mov eax, 4
mov ebx, 1
mov edx, prompt1_len
mov ecx, prompt1
int 0x80
; Read the first integer from the user
mov eax, 3
mov ebx, 0
mov edx, 4
mov ecx, firstInteger
int 0x80
; Prompt the user to enter the second integer
mov eax, 4
mov ebx, 1
mov edx, prompt2_len
mov ecx, prompt2
int 0x80
; Read the second integer from the user
mov eax, 3
mov ebx, 0
mov edx, 4
mov ecx, secondInteger
int 0x80
; Compare the two integers
mov eax, [firstInteger]
cmp eax, [secondInteger]
jg first_larger
jl second_larger
; The integers are equal
mov eax, 4
mov ebx, 1
mov edx, result3_len
mov ecx, result3
int 0x80
jmp end_program
first_larger:
; The first integer is larger
mov eax, 4
mov ebx, 1
mov edx, result1_len
mov ecx, result1
int 0x80
jmp end_program
second_larger:
; The second integer is larger
mov eax, 4
mov ebx, 1
mov edx, result2_len
mov ecx, result2
int 0x80
end_program:
; Exit the program
mov eax, 1
xor ebx, ebx
int 0x80

CODE EXPLANATION


  • The .data section contains string variables for prompts and results. The prompt1 and prompt2 variables prompt the user to enter the first and second integers, respectively. The result1, result2, and result3 variables store the messages indicating which integer is larger or if they are equal.

  • The .bss section reserves memory for storing the first and second integers entered by the user. They are defined as resd (reserve doubleword) with a size of 1, which typically means reserving 4 bytes each.

  • The .text section contains the main code logic.

  • The _start label marks the entry point of the program.

  • The code uses system calls to interact with the user and perform I/O operations. It utilizes the int 0x80 instruction to invoke the appropriate system calls.

  • The program prompts the user to enter the first integer, reads it from the user, prompts for the second integer, and reads it as well.

  • The code then compares the two integers using cmp and jg (jump if greater) instructions to determine which one is larger. Depending on the result, it jumps to either the first_larger or second_larger labels.

  • If the integers are equal, the program displays the corresponding message using system calls.

  • The end_program label marks the end of the program. It exits by invoking the system call to terminate the program.



SCENARIO 1



Figure 1 SCENARIO 1

SCENARIO 2



Figure 2 SCENARIO 2

SCENARIO 3



Figure 3 SCENARIO 3

QUESTION 2

Arduino Thermostat

INTRODUCTION


The idea is simple, use an Arduino and a few simple components along with a small LCD screen to create a functioning Thermostat.
Figure 4 ARDUINO THERMOSTAT

Step 1: Materials


Hardware
1 x breadboard.
1 x UltraSonic Sensor
1 x Arduino Uno
1 x 16x2 LCD screen
1 x 10k ohm resistors 1 x LED (colour is your choice)
1 x temperature sensor(DHT11)
1 x LED light
Many Jumper wires
1 x buzzer
Software
Arduino IDE A
LAPTOP

STEP 2 : THE CODE


#include "dht.h"
// Defines pin numbers
const int trigPin = 9;
const int echoPin = 10;
const int buzzerPin = 11;
const int ledPin = 13;
const int dhtPin = A0;
// Defines variables
long duration;
int distance;
bool isBuzzerActive = false;
dht DHT;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(buzzerPin, OUTPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600); // Starts the serial communication
delay(500); // Delay to let the system boot
Serial.println("DHT11 Humidity & Temperature Sensor\n");
delay(1000); // Wait before accessing the sensor
}

void loop() {
// DHT11 Sensor Code
DHT.read11(dhtPin);
// Check temperature and humidity
if (DHT.temperature => 20 && DHT.temperature =< 25 ) {
if (!isBuzzerActive) {
digitalWrite(buzzerPin, HIGH);
digitalWrite(ledPin, HIGH);
isBuzzerActive = true;
}
} else {
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
isBuzzerActive = false;
}
// Ultrasonic Sensor Code
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH, 150000);
// Calculating the distance
distance = duration * 0.034 / 2;
// Check ultrasonic sensor distance to switch off the buzzer
if (isBuzzerActive && distance <= 50) { // Adjust the distance threshold as needed
digitalWrite(buzzerPin, LOW);
digitalWrite(ledPin, LOW);
isBuzzerActive = false;
}
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Prints the temperature and humidity on the Serial Monitor
Serial.print("Current Humidity: ");
Serial.print(DHT.humidity);
Serial.print("% Temperature: ");
Serial.print(DHT.temperature);
Serial.println("°C");
delay(1000); // Wait 1 second before accessing the sensor again
}
The above code does the following:
// This code uses an ultrasonic sensor and a DHT11 humidity and temperature sensor to monitor the environment and control a buzzer and an LED.
// The code begins by including the necessary libraries and defining the pin numbers for the sensors and actuators.
// The variables for storing duration and distance are also declared, along with a boolean variable to track the state of the buzzer.

// In the setup() function, the pin modes are set for the sensors and actuators, and the serial communication is initialized.
// A delay is added to allow the system to boot, and then a message is printed to the serial monitor.
// Another delay is added before accessing the sensors to ensure stability.

// The main logic is implemented in the loop() function.
// First, the DHT11 sensor is read and the temperature and humidity values are checked.
// If both values are greater than 25, indicating a comfortable environment, and the buzzer is not already active,
// the buzzer and LED are turned on, and the buzzer state is set to active.
// If the temperature and humidity values are not both greater than 25, the buzzer and LED are turned off, and the buzzer state is set to inactive.

// Next, the ultrasonic sensor code is executed.
// The trigPin is cleared and then set to HIGH for 10 microseconds to generate an ultrasonic pulse.
// The pulseIn() function is used to measure the duration it takes for the echo signal to return.
// The distance is calculated using the speed of sound and the measured duration.

// The code then checks if the buzzer is active and if the distance is less than or equal to 50 cm.
// If so, indicating an object is within the proximity, the buzzer and LED are turned off, and the buzzer state is set to inactive.

// The distance and sensor readings are printed to the serial monitor for debugging and monitoring purposes.


Download 1.08 Mb.

Share with your friends:
1   2   3   4




The database is protected by copyright ©ininet.org 2024
send message

    Main page