#Blog 5 Recitation 3 Sensors
Documentation
We started with the vibration sensor. I read the instruction written by the professor and was confused because it wrote “you will need a piezo disk and a 1 mega ohm resistor”. What is a 1 mega ohm resister? I checked in my toolkit and was even more confused since the resistors are not labeled with numbers. I asked an LA and she grabbed me a multimeter. We tested out the properties of the resistance.
We still didn’t find 1M ohm resistor, so we sought help from the professor. It turned out that this sensor doesn’t actually need an extra resistor. It was just a test to see whether we have carefully read the instructions or not. Now that the mystery was solved, we began to build the circuit. We followed the instructions and added a LED output. Then we use the sample code from “Arduino>File>Examples>0.6Sensors>Knock”. We knocked, nothing happened.
We thought that maybe the threshold is too high, so we changed it to 50. We knocked again, but nothing happened. We could do nothing but check the circuit thoroughly. At last, we found that we plug one foot of the resistor, ground, and both feet of the LED into the same roll, which caused a short circuit. We replaced these feet and now it worked.
We thought that the delay was too long, and it might decrease its level of interactivity, so we changed the delay into 20.
Here is the final code we used:
/* Knock Sensor This sketch reads a piezo element to detect a knocking sound. It reads an analog pin and compares the result to a set threshold. If the result is greater than the threshold, it writes "knock" to the serial port, and toggles the LED on pin 13. The circuit: - positive connection of the piezo attached to analog in 0 - negative connection of the piezo attached to ground - 1 megohm resistor attached from analog in 0 to ground created 25 Mar 2007 by David Cuartielles <http://www.0j0.org> modified 30 Aug 2011 by Tom Igoe This example code is in the public domain. https://www.arduino.cc/en/Tutorial/BuiltInExamples/Knock */ // these constants won't change: const int ledPin = 13; // LED connected to digital pin 13 const int knockSensor = A0; // the piezo is connected to analog pin 0 const int threshold = 50; // threshold value to decide when the detected sound is a knock or not // these variables will change: int sensorReading = 0; // variable to store the value read from the sensor pin int ledState = LOW; // variable used to store the last LED status, to toggle the light void setup() { pinMode(ledPin, OUTPUT); // declare the ledPin as as OUTPUT Serial.begin(9600); // use the serial port } void loop() { // read the sensor and store it in the variable sensorReading: sensorReading = analogRead(knockSensor); // if the sensor reading is greater than the threshold: if (sensorReading >= threshold) { // toggle the status of the ledPin: ledState = !ledState; // update the LED pin itself: digitalWrite(ledPin, ledState); // send the string "Knock!" back to the computer, followed by newline Serial.println("Knock!"); } delay(20); // delay to avoid overloading the serial port buffer }
Diagram of how all components are connected:
This one is rather easy. We just followed the instructions on the Arduino website and finished it.
Here is the code we used:
// 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 // ---------------------------------------------------------------- // #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 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; // 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"); }
Diagram of how all components are connected:
(https://create.arduino.cc/projecthub/abdularbi17/ultrasonic-sensor-hc-sr04-with-arduino-tutorial-327ff6)
We tried to find the moisture sensor from our toolkit, however, we mistaken it with the pressure sensor. After I asked Prof. Marcela, she gave me this correct one and a sponge. First, we looked at the instructions on seeed website. It kind of misguided us. It made us think that we needed a base shield to complete the whole thing.
However, we found that what we need to do is only to plug three wires directly into “5v”, “GND”, and “A0” according to the sign on the sensor.
Here is the code we used:
int sensorPin = A0; int sensorValue = 0; void setup() { Serial.begin(9600); } void loop() { // read the value from the sensor: sensorValue = analogRead(sensorPin); Serial.print("Moisture = " ); Serial.println(sensorValue); delay(1000); }
Diagram of how all components are connected:
Questions
Question 1: What did you intend to assemble in the recitation exercise? If your sensor/actuator combination were to be used for pragmatic purposes, who would use it, why would they use it, and how could it be used?
I intended to assemble a vibration sensor and a LED light. If it were to be used for pragmatic purpose, I think paralyzed people would use it. Paralyzed people sometimes suffer from spasticity which can lead to severe uncontrollable limbs movements. If the patients are not protected well, spasticity can result in pain, permanent joint deformity, urinary tract infection, chronic constipation, and pressure sores (Johns Hopkins Medicine). So, with this vibration sensor, I can create a blanket that is set underneath the patient, and when the nurses have to leave the patient, they can turn on the sensor system. In this way, when the patients have spasticity, the sensors detect vibration, and lights implemented on the nurses’ bracelets would light up. Thus, nurses would be able to take care of the situation in time and minimize the patients’ pain.
Question 2: Code is often compared to following a recipe or tutorial. Why do you think that is?
It is because we can consider both code and recipe or tutorial as input. Code is the input people give to a computer, while a recipe is an input given by the experienced to green hands. The computer and our brain program the input and give output according to the guidance. However, there is one difference that distinguishes the two: code must be precisely inputted and the results are precise. In contrast, a recipe or tutorial can itself be slightly wrong and the results may differ due to various aspects, including people, environment, etc.
Question 3: In the Language of New Media, Manovich describes the influence of computers on new media. In what ways do you believe the computer influences our human behaviors?
For individuals, we are less capable or willing to remember small things such as phone numbers, birthdays, etc. by ourselves. With the computer, we have a place to store most of our memories and knowledge easily. Since we lose the need to memorize, this kind of ability and behavior has faded.
Also, through computers, the development of information technology will be accelerated, the channels for people to understand information and transmit information will increase. People can get information at a faster speed and have aroused higher demand for timeliness and effectiveness of information.
In addition, we can use the computer network to input our thinking and methods into the machine to complete tasks that we would otherwise have to complete by hand. For example, in the production of a company, we can not only use computers to make a new design for the shape, packaging, and performance of a product but also control the entire production, packaging, and distribution process, saving a lot of human and financial resources.
Feb 26, 2022, Century Avenue, Younian Liu
great documentation Younian, it was really fun to read! 🙂