Robotics Design Project
After the ProjectIn this project, my strengths were coding, as I am familiar with the language and able to understand the Arduino syntax. However, I was not as proficient with the CAD modeling software Onshape as my partner, Thomas is. If we were to continue this project, I would edit the code to make it have less of a lag between when the commands were sent and when they were executed. I would also add a weight on the end so it didn’t need to be held down. ExplanationOur project uses a spool and temperature sensor to sense the temperature at different depths in the Ala Wai. By typing in 1, the temperature sensor is reeled fully in, and 2 reels the temperature all the way out. By sending the command 3, it reels in the temperature sensor continually until told to stop, and 4 reels the temperature sensor out continually until told to stop. Entering zero will stop the movement of the motor, and 5 reads the temperature values gathered by the sensor. Final Code/********************************************************************/
// First we include the libraries #include <OneWire.h> #include <Servo.h> #include <DallasTemperature.h> /********************************************************************/ // Data wire is plugged into pin 2 on the Arduino #define ONE_WIRE_BUS 2 /********************************************************************/ // Setup a oneWire instance to communicate with any OneWire devices // (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS); /********************************************************************/ // Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire); /********************************************************************/ Servo myservo; double temperatureValue = 0; int brightness = 0; int otherOne = 0; int REDPin = 3; // RED pin of the LED to PWM pin 4 int GREENPin = 5; // GREEN pin of the LED to PWM pin 5 int BLUEPin = 6; // BLUE pin of the LED to PWM pin 6 int delayValue = 12.5*1000; void setup(void) { // start serial port Serial.begin(9600); myservo.attach(9); pinMode(6, OUTPUT); pinMode(5, OUTPUT); pinMode(3, OUTPUT); Serial.println("Dallas Temperature IC Control Library Demo"); // Start up the library Serial.println(" "); Serial.println("1 reels in the temperature sensor for delayValue"); Serial.println("2 reels out the temperature sensor for delayValue"); Serial.println("3 reels in the temperature sensor until told to stop"); Serial.println("4 reels out the temperature sensor until told to stop"); Serial.println("5 read the temperature from the sensor"); Serial.println("0 tells the temperature to stop"); Serial.println(" "); sensors.begin(); } void loop(void) { /* analogWrite(REDPin, 255-0); analogWrite(GREENPin, 255-0); analogWrite(BLUEPin, 255-0); */ //Serial.println("RUN SUCCESSFUL (probably)"); // call sensors.requestTemperatures() to issue a global temperature // request to all devices on the bus /********************************************************************/ //Serial.print(" Requesting temperatures..."); sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); //Serial.println("DONE"); //if(Serial.available()) //{ char ch = Serial.read(); while(ch == '0' or ch == '1' or ch == '2' or ch == '3' or ch == '4') { while(ch == '0') { ch = '0'; myservo.write(93); ch = '9'; } while(ch == '1') { ch = '1'; myservo.write(123); delay(delayValue); myservo.write(93); ch = '9'; } while(ch == '2') { ch = '2'; myservo.write(63); delay(delayValue); myservo.write(93); ch = '9'; } while(ch == '3') { ch = '3'; myservo.write(123); ch = '9'; } while(ch == '4') { ch = '4'; myservo.write(63); ch = '9'; } } while(ch == '5') { ch = Serial.read(); if(temperatureValue >= 50 && temperatureValue <= 60) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-0); analogWrite(GREENPin, 255-0); analogWrite(BLUEPin, 255-255); ch = '9'; } if(temperatureValue > 60 && temperatureValue <= 70) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-0); analogWrite(GREENPin, 255-255); analogWrite(BLUEPin, 255-255); ch = '9'; } if(temperatureValue > 70 && temperatureValue <= 80) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-0); analogWrite(GREENPin, 255-255); analogWrite(BLUEPin, 255-0); ch = '9'; } if(temperatureValue > 80 && temperatureValue <= 85) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-255); analogWrite(GREENPin, 255-255); analogWrite(BLUEPin, 255-0); ch = '9'; } if(temperatureValue > 85 && temperatureValue <= 90) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-255); analogWrite(GREENPin, 255-0); analogWrite(BLUEPin, 255-0); ch = '9'; } if(temperatureValue > 90 && temperatureValue <= 100) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-255); analogWrite(GREENPin, 255-0); analogWrite(BLUEPin, 255-255); ch = '9'; } if(temperatureValue < 50 && temperatureValue > 100) { sensors.requestTemperatures(); // Send the command to get temperature readings temperatureValue = sensors.getTempFByIndex(0); Serial.print("Temperature is: "); Serial.println(temperatureValue); analogWrite(REDPin, 255-170); analogWrite(GREENPin, 255-0); analogWrite(BLUEPin, 255-255); ch = '9'; } } //} } /********************************************************************/ /* int REDPin = 6; int GREENPin = 5; int BLUEPin = 3; void setup() { pinMode(REDPin, OUTPUT); pinMode(GREENPin, OUTPUT); pinMode(BLUEPin, OUTPUT); } void loop() { analogWrite(REDPin, 255); analogWrite(GREENPin, 255); analogWrite(BLUEPin, 255); delay(1000); analogWrite(REDPin, 0); analogWrite(GREENPin, 0); analogWrite(BLUEPin, 0); delay(1000); } */
0 Comments
Leave a Reply. |
Archives
May 2018
Categories |