Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Mechanical Analysis and Design II
- Capstone Project - Home Brew Automation
- */
- //Temp Sensor Setup
- #include <OneWire.h>
- #include <DallasTemperature.h>
- #define ONE_WIRE_BUS 40
- OneWire oneWire(ONE_WIRE_BUS);
- DallasTemperature sensors(&oneWire);
- DeviceAddress insideThermometer = { 0x28, 0x6F, 0xC3, 0xA6, 0x07, 0x00, 0x00, 0x4F };
- float tempF;
- //Pump and Motor I/O
- int Pump = 48;
- int Button = 22;
- int Pumpstate = LOW;
- int Motor = 52;
- int buttonstate = LOW;
- //Ultrasonic Setup
- #define trigPin 13
- #define echoPin 12
- #define Red 11
- #define Green 10
- void setup()
- {
- //Motor and Pump
- pinMode(Motor,OUTPUT);
- pinMode(Pump,OUTPUT);
- pinMode(Button,INPUT);
- pinMode(Solenoid,OUTPUT);
- //Ultrasonic Sensor
- Serial.begin(9600);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- pinMode(Red, OUTPUT);
- pinMode(Green, OUTPUT);
- //Temp Sensor
- sensors.begin();
- sensors.setResolution(insideThermometer, 10);
- }
- //Temp Sensor Conversions
- void printTemperature(DeviceAddress deviceAddress)
- {
- float TempF;
- float tempC = sensors.getTempC(deviceAddress);
- TempF = DallasTemperature::toFahrenheit(tempC);
- if (tempC == -127.00)
- {
- Serial.print("Error getting temperature");
- }
- else
- {
- Serial.print("C: ");
- Serial.print(tempC);
- Serial.print(" F: ");
- Serial.print(DallasTemperature::toFahrenheit(tempC));
- }
- }
- void loop()
- {
- //Reading State of Button, pushed or not.
- buttonstate = digitalRead(Button);
- //Temperature Sensor printing Temperatures
- delay(100);
- Serial.print("Getting temperatures...\n\r");
- sensors.requestTemperatures();
- Serial.print("The Bottle Temperature is: ");
- printTemperature(insideThermometer);
- Serial.print("\n\r");
- //Ultrasonic Sensor
- long duration, distance;
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- duration = pulseIn(echoPin, HIGH);
- distance = (((duration/2) / 29.1)*0.393701);
- while (buttonstate == HIGH && tempF <= 90 && distance <= 4)
- {
- digitalWrite(Pump,HIGH);
- digitalWrite(Solenoid,HIGH);
- }
- while (buttonstate == LOW || tempF > 90 || distance > 4)
- {
- digitalWrite(Pump,LOW);
- digitalWrite(Solenoid,HIGH);
- }
- //How do I get the turn table to turn once the bottle has been filled?
- if (tempF > 90) //Bottle is full, sensing liquid
- {
- digitalWrite(Motor,HIGH); //turn the motor on so the turn table changes position
- delay(1000); //delay for 1 second so the ultrasonic sensor is not instantly tripped
- if (distance < 4) //when the ultrasonic sees the next sensor turn the motor off
- {
- digitalWrite(Motor,LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement