Internet of Things module - CAT(potd)
Quick tour of the continuous assessment test
Quick tour of the continuous assessment test
What a day!🥲 Hope it was fantastic for all of us. The aim here is to give an overview of the exam. We won't dive into the theoretical questions, just the practical one.
The compulsory question was going like this:
We've been summoned to hand-draw it. So based on what we can understand from the question, let's show it in the next point.
Here's what you might have ended up with:
The setup consists of an Arduino Uno R3 (01), some LEDs (03 - green, yellow, red), Resistors (03), and an Ultrasonic Distance Sensor HC-SR04 (01).
To make it up and running, you could write something alike the following:
/**
* Object detection system using an HC-SR04 Ultrasonic Sensor (4-pin)
* Written by cuttypie.dev
*/
// Define pins for the ultrasonic sensor
const int trigPin = 9;
const int echoPin = 7;
// Define pins for the LEDs
const int greenLed = 13;
const int yellowLed = 12;
const int redLed = 11;
void setup() {
// Start serial communication for debugging
Serial.begin(9600);
// Set LED pins as OUTPUT
pinMode(greenLed, OUTPUT);
pinMode(yellowLed, OUTPUT);
pinMode(redLed, OUTPUT);
// Set ultrasonic sensor pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// Clear the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Set the trigPin HIGH for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Read the echoPin, return the sound wave travel time in microseconds
long duration = pulseIn(echoPin, HIGH);
// Calculate the distance in cm
float distance = duration * 0.034 / 2; // Speed of sound is 0.034 cm/µs
// Print distance for debugging purposes
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Control LEDs based on distance
if (distance > 50) {
digitalWrite(greenLed, HIGH); // Turn on Green LED
digitalWrite(yellowLed, LOW); // Turn off Yellow LED
digitalWrite(redLed, LOW); // Turn off Red LED
}
else if (distance > 20 && distance <= 50) {
digitalWrite(greenLed, LOW); // Turn off Green LED
digitalWrite(yellowLed, HIGH); // Turn on Yellow LED
digitalWrite(redLed, LOW); // Turn off Red LED
}
else if (distance >= 0 && distance <= 20) {
digitalWrite(greenLed, LOW); // Turn off Green LED
digitalWrite(yellowLed, LOW); // Turn off Yellow LED
digitalWrite(redLed, HIGH); // Turn on Red LED
}
else {
// If distance is out of range (negative), turn all LEDs off.
digitalWrite(greenLed, LOW);
digitalWrite(yellowLed, LOW);
digitalWrite(redLed, LOW);
}
delay(500); // Wait for half a second before next measurement
}
In summary, the exam was about building an object detection system using an Ultrasonic Sensor for the practical question. The rest of the exam was theoretical, focusing on the fundamentals of IoT.
Wishing you all success!🥳 Let's catch up for the final examination taking place next weekend. Major announcements also coming soon.