amc:ss2025:group-b:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
amc:ss2025:group-b:start [2025/07/29 19:14] – 34284_students.hsrw | amc:ss2025:group-b:start [2025/07/29 19:14] (current) – 34284_students.hsrw | ||
---|---|---|---|
Line 52: | Line 52: | ||
The code was written in Arduino IDE and configured to move the motor forward in short bursts, pause for 30 seconds at each stop to simulate thermal stabilization, | The code was written in Arduino IDE and configured to move the motor forward in short bursts, pause for 30 seconds at each stop to simulate thermal stabilization, | ||
+ | |||
+ | ====== Results ====== | ||
+ | (by Kirandeep Kaur) | ||
+ | |||
+ | The Arduino code successfully controlled the descent and temperature reading collection. For the sole purpose of a demo, the code was written in such a way it samples a 3 meter deep lake or water body. This would mean a total of 5 depth levels were configured, corresponding to a total descent of 2.5 meters. Readings are not taken at the 3 meter mark as by then the temperature readings would be affected by the temperature of the waterbed. Therefore, at each step, the system printed the estimated depth and corresponding temperature reading onto the serial monitor. The readings were separated by 30-second delays to mimic the real sampling procedure. Once all data points were collected, the motor reversed and reeled in the sensor based on the total descent time. The final message confirmed the completion of the measurement cycle (Figure 5.). | ||
+ | |||
+ | <code C++> | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // Motor Shield Setup | ||
+ | Adafruit_MotorShield AFMS = Adafruit_MotorShield(); | ||
+ | Adafruit_DCMotor *motor = AFMS.getMotor(1); | ||
+ | |||
+ | // DS18B20 Setup | ||
+ | #define ONE_WIRE_BUS 2 | ||
+ | OneWire oneWire(ONE_WIRE_BUS); | ||
+ | DallasTemperature sensors(& | ||
+ | |||
+ | // Parameters | ||
+ | int totalSteps = 5; // 5 steps = 2.5 meters | ||
+ | int delayPerStep_ms = 4000; // 4 seconds per 0.5m descent (estimated at 9V) | ||
+ | int waitAfterStep_ms = 30000; | ||
+ | |||
+ | void setup() { | ||
+ | Serial.begin(9600); | ||
+ | AFMS.begin(); | ||
+ | sensors.begin(); | ||
+ | |||
+ | Serial.println(" | ||
+ | Serial.println(" | ||
+ | |||
+ | // Descent loop | ||
+ | for (int i = 1; i <= totalSteps; i++) { | ||
+ | Serial.print(" | ||
+ | Serial.print(i * 0.5); | ||
+ | Serial.println(" | ||
+ | |||
+ | // Lower motor | ||
+ | motor-> | ||
+ | motor-> | ||
+ | delay(delayPerStep_ms); | ||
+ | motor-> | ||
+ | |||
+ | // Wait before reading | ||
+ | Serial.println(" | ||
+ | delay(waitAfterStep_ms); | ||
+ | |||
+ | // Read temperature | ||
+ | sensors.requestTemperatures(); | ||
+ | float tempC = sensors.getTempCByIndex(0); | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(i * 0.5); | ||
+ | Serial.print(" | ||
+ | Serial.print(tempC); | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | // Rewind sensor to surface | ||
+ | Serial.println(" | ||
+ | |||
+ | motor-> | ||
+ | motor-> | ||
+ | delay(totalSteps * delayPerStep_ms); | ||
+ | motor-> | ||
+ | |||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | {{: | ||
+ | |||
+ | //Figure 5. Real-time output from Arduino serial monitor showing temperature readings at every 0.5m depth.// | ||
+ | |||
+ | The motor behaved as expected in both directions when supplied with 9V, although noticeably under-powered compared to its rated 12V specification. The DS18B20 sensor responded with temperature values at each level. The encoder component of the motor did not produce usable signals during testing and was omitted from the final implementation. An SD card module was not connected during this prototype phase due to time constraints, | ||
+ | |||
+ | <code C++> | ||
+ | #include < | ||
+ | |||
+ | // SD Card Setup | ||
+ | const int chipSelect = 10; // CS pin for SD card | ||
+ | |||
+ | void setup() { | ||
+ | // Initialize SD Card | ||
+ | Serial.print(" | ||
+ | if (!SD.begin(chipSelect)) { | ||
+ | Serial.println(" | ||
+ | while (1); // Halt program | ||
+ | } | ||
+ | Serial.println(" | ||
+ | |||
+ | // Open file and write header | ||
+ | dataFile = SD.open(" | ||
+ | if (dataFile) { | ||
+ | dataFile.println(" | ||
+ | dataFile.close(); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | // Log to SD | ||
+ | dataFile = SD.open(" | ||
+ | if (dataFile) { | ||
+ | dataFile.print(depth, | ||
+ | dataFile.print(", | ||
+ | dataFile.print(timestamp); | ||
+ | dataFile.print(", | ||
+ | dataFile.println(tempC, | ||
+ | dataFile.close(); | ||
+ | } else { | ||
+ | Serial.println(" | ||
+ | } | ||
+ | } | ||
+ | </ | ||
amc/ss2025/group-b/start.txt · Last modified: 2025/07/29 19:14 by 34284_students.hsrw