Advertisement
Guest User

Capstone

a guest
Apr 28th, 2016
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. /*
  2. Mechanical Analysis and Design II
  3. Capstone Project - Home Brew Automation
  4. */
  5.  
  6. //Temp Sensor Setup
  7. #include <OneWire.h>
  8. #include <DallasTemperature.h>
  9. #define ONE_WIRE_BUS 40
  10. OneWire oneWire(ONE_WIRE_BUS);
  11. DallasTemperature sensors(&oneWire);
  12. DeviceAddress insideThermometer = { 0x28, 0x6F, 0xC3, 0xA6, 0x07, 0x00, 0x00, 0x4F };
  13. float tempF;
  14.  
  15. //Pump and Motor I/O
  16. int Pump = 48;
  17. int Button = 22;
  18. int Pumpstate = LOW;
  19. int Motor = 52;
  20. int buttonstate = LOW;
  21.  
  22. //Ultrasonic Setup
  23. #define trigPin 13
  24. #define echoPin 12
  25. #define Red 11
  26. #define Green 10
  27.  
  28.  
  29.  
  30.  
  31.  
  32. void setup()
  33. {
  34.  
  35. //Motor and Pump
  36. pinMode(Motor,OUTPUT);
  37. pinMode(Pump,OUTPUT);
  38. pinMode(Button,INPUT);
  39. pinMode(Solenoid,OUTPUT);
  40.  
  41. //Ultrasonic Sensor
  42. Serial.begin(9600);
  43. pinMode(trigPin, OUTPUT);
  44. pinMode(echoPin, INPUT);
  45. pinMode(Red, OUTPUT);
  46. pinMode(Green, OUTPUT);
  47.  
  48. //Temp Sensor
  49. sensors.begin();
  50. sensors.setResolution(insideThermometer, 10);
  51. }
  52.  
  53.  
  54.  
  55.  
  56. //Temp Sensor Conversions
  57. void printTemperature(DeviceAddress deviceAddress)
  58. {
  59. float TempF;
  60. float tempC = sensors.getTempC(deviceAddress);
  61. TempF = DallasTemperature::toFahrenheit(tempC);
  62. if (tempC == -127.00)
  63. {
  64. Serial.print("Error getting temperature");
  65. }
  66.  
  67. else
  68. {
  69. Serial.print("C: ");
  70. Serial.print(tempC);
  71. Serial.print(" F: ");
  72. Serial.print(DallasTemperature::toFahrenheit(tempC));
  73. }
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81. void loop()
  82. {
  83. //Reading State of Button, pushed or not.
  84. buttonstate = digitalRead(Button);
  85.  
  86. //Temperature Sensor printing Temperatures
  87. delay(100);
  88. Serial.print("Getting temperatures...\n\r");
  89. sensors.requestTemperatures();
  90. Serial.print("The Bottle Temperature is: ");
  91. printTemperature(insideThermometer);
  92. Serial.print("\n\r");
  93.  
  94. //Ultrasonic Sensor
  95. long duration, distance;
  96. digitalWrite(trigPin, LOW);
  97. delayMicroseconds(2);
  98. digitalWrite(trigPin, HIGH);
  99. delayMicroseconds(10);
  100. digitalWrite(trigPin, LOW);
  101. duration = pulseIn(echoPin, HIGH);
  102. distance = (((duration/2) / 29.1)*0.393701);
  103.  
  104.  
  105.  
  106.  
  107. while (buttonstate == HIGH && tempF <= 90 && distance <= 4)
  108. {
  109. digitalWrite(Pump,HIGH);
  110. digitalWrite(Solenoid,HIGH);
  111. }
  112.  
  113. while (buttonstate == LOW || tempF > 90 || distance > 4)
  114. {
  115. digitalWrite(Pump,LOW);
  116. digitalWrite(Solenoid,HIGH);
  117. }
  118.  
  119. //How do I get the turn table to turn once the bottle has been filled?
  120. if (tempF > 90) //Bottle is full, sensing liquid
  121. {
  122. digitalWrite(Motor,HIGH); //turn the motor on so the turn table changes position
  123. delay(1000); //delay for 1 second so the ultrasonic sensor is not instantly tripped
  124. if (distance < 4) //when the ultrasonic sees the next sensor turn the motor off
  125. {
  126. digitalWrite(Motor,LOW);
  127. }
  128. }
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement