Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //PINS
- int r = 9;
- int g = 10;
- int b = 11;
- int speaker = 4;
- int button = 7;
- //ANALOG PINS
- int photoResistor = 0;
- int moisture = 1;
- int temperature = 2;
- //SENSOR INFO
- int currentLight;
- int currentTemp;
- int currentWater;
- //PRIME PLANT INFO
- int waterGood;
- int lightGood;
- int tempGood;
- //LOOKING FOR ANY PROBLEMS
- bool lightProb = false;
- bool tempProb = false;
- bool moisProb = false;
- void setup() {
- //Initializing pins
- pinMode(r, OUTPUT);
- pinMode(g, OUTPUT);
- pinMode(b, OUTPUT);
- pinMode(speaker, OUTPUT);
- Serial.begin(9600);
- //wait for the person to move away from all sensors
- delay(1000);
- //set the current values as the optimum.
- tempGood = analogRead(temperature);
- lightGood = analogRead(photoResistor);
- waterGood = analogRead(moisture);
- }
- void loop() {
- if (digitalRead(button) == 1) { //if the user presses the button the set the current values as the optimum values
- tempGood = analogRead(temperature);
- lightGood = analogRead(photoResistor);
- waterGood = analogRead(moisture);
- }
- currentTemp = analogRead(temperature); //read the temp and set to a variable
- if (currentTemp > (tempGood + 5)) { //to hot
- orange(); //orange light with delay and alarm
- noTone(speaker); //stop the speaker and wait
- delay(300);
- red(); //red light with delay and alarm
- noTone(speaker);
- delay(300);
- tempProb = true; //Let the program know there is a problem
- }
- else if (currentTemp < (tempGood - 5)) { //if its too cold
- orange(); //orange light with delay and alarm
- noTone(speaker); //stop the speaker and wait
- delay(300);
- blue(); //blue light with delay and alarm
- noTone(speaker); //stop the speaker and wait
- delay(300);
- tempProb = true; //let the program know there is a problem
- }
- else { //if it's not too hot, nor too cold
- tempProb = false; //then there is no problem
- }
- currentLight = analogRead(photoResistor); //read the photoresistor and set it to a bariable
- if (currentLight > (lightGood + 100)) { //too bright
- yellow(); //yellow light
- noTone(speaker); //stop speaker
- delay(300);
- red(); //red light
- noTone(speaker); //stop speaker
- delay(300);
- lightProb = true; //problem
- }
- else if (currentLight < (lightGood - 100)) { //too dark
- yellow(); //yellow light
- noTone(speaker); //stop speaker
- delay(300);
- green(); //green light
- noTone(speaker); //stop speaker
- delay(300);
- lightProb = true; //problem
- }
- else { //good light level
- lightProb = false; //no problem
- }
- currentWater = analogRead(moisture); //read the moisture sensor
- if (currentWater > (waterGood + 100)) { //too much water
- blue(); //blue light
- noTone(speaker); //stop speaker
- delay(300);
- red(); //red light
- noTone(speaker); //stop speaker
- delay(300);
- moisProb = true; //problem
- }
- else if (currentWater < (waterGood - 100)) { //too little water
- blue(); //blue light
- noTone(speaker); //stop speaker
- delay(300);
- green(); //green light
- noTone(speaker); //stop speaker
- delay(300);
- moisProb = true; //problem
- }
- else { //if the water level is good
- moisProb = false; //no problem
- }
- if (!moisProb && !lightProb && !tempProb) { //if there are no problems and everthing is dandy
- //turn on the green light
- analogWrite(r, 255);
- analogWrite(g, 0);
- analogWrite(b, 255);
- }
- }
- void red() { //set up red light
- tone(speaker, 523); //turn the speaker on
- analogWrite(r, 0); //turn the red led on
- analogWrite(g, 255);
- analogWrite(b, 255);
- delay(750); //wait 750 milliseconds
- }
- void green() { //set up green light
- tone(speaker, 523); //turn on the speaker
- analogWrite(r, 255);
- analogWrite(g, 0); //turn on green light
- analogWrite(b, 255);
- delay(750); //wait 750 milliseconds
- }
- void blue() { //set up blue light
- tone(speaker, 523); //turn on the speaker
- analogWrite(r, 255);
- analogWrite(g, 255);
- analogWrite(b, 0); //turn on the blue light
- delay(750); //wait 750 milliseconds
- }
- void orange() { //set up the orange light
- tone(speaker, 523); //turn on the speaker
- analogWrite(r, 0); //turn on the red light
- analogWrite(g, 200); //slightly turn on the green to blend to orange
- analogWrite(b, 255);
- delay(750); //wait 750 milliseconds
- }
- void yellow() { //set up the yellow light
- tone(speaker, 523); //turn on the speaker
- analogWrite(r, 0); //turn the the red light
- analogWrite(g, 0); //turn on the green light and they will blend into yellow
- analogWrite(b, 255);
- delay(750); //wait 750 milliseconds
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement