We first tried to put only the sensor, which was the ultrasonic ranger. It can detect distance. And then we added output– a buzzer. Initially, we intend to make buzzer sounds louder as the distance get smaller, but were told that this buzzer can only make the same volunme. So we then changed our goal which is that the buzzer makes sound when the distance is longer than 20. The coding was the hardest part. Even though we can copy and paste the code from the website and examples from the Arduino, we need to figure out ways to combine them correctly. Additionally, there is something we want to improve on. The reaction duration of buzzer switching on and off is quite longer. I’d like to make it more sensitive if I have time.
Question 1
We had a buzzer as an output and an ultrasonic ranger as an input in the circuit. The buzzer starts to make sound after the sensor detects the distance is farther than 20cm. This kind of assmbly can be used by a group of hikers. For example, if they are venturing in a dangerous landscape, they can have this kind of technology attaching to their bodies. If one person is separate from his/her parnters in a certain distance, the alarm goes on and reminds them that there is one member falling behind the team.
Question 2
The one who reads the code is the computer. It only reacts to the right instructions and the right combination of instructions. So a programmer needs to be careful when coding, following the rules of coding like following the recipe if want to have a perfect meal.
Question 3
When we get used to computer, we become lazy because computer can help us do a lot of things. And it also shapes different habbit for respective generation as computer develop throughout time. For example, my grandparents and parents get used to have keyboards and mouses when facing computer, but my generation get used to screens.
The code:
// ---------------------------------------------------------------- // // Arduino Ultrasoninc Sensor HC-SR04 // Re-writed by Arbi Abdul Jabbaar // Using Arduino IDE 1.8.7 // Using HC-SR04 Module // Tested on 17 September 2019 // ---------------------------------------------------------------- // #include "pitches.h" #define echoPin 2 // attach pin D2 Arduino to pin Echo of HC-SR04 #define trigPin 3 //attach pin D3 Arduino to pin Trig of HC-SR04 // defines variables long duration; // variable for the duration of sound wave travel int distance; // variable for the distance measurement int notes[] = { NOTE_A4, NOTE_B4, NOTE_C3 }; void setup() { pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT Serial.begin(9600); // // Serial Communication is starting with 9600 of baudrate speed Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print some text in Serial Monitor Serial.println("with Arduino UNO R3"); } void loop() { // Clears the trigPin condition digitalWrite(trigPin, LOW); delayMicroseconds(2); // Sets the trigPin HIGH (ACTIVE) 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); // Calculating the distance distance = duration * 0.034 / 2; if (distance > 20){ // play the note corresponding to this sensor: tone(8, notes[1], 20000); } // Speed of sound wave divided by 2 (go and back) // Displays the distance on the Serial Monitor Serial.print("Distance: "); Serial.print(distance); Serial.println(" cm"); }
Leave a Reply