Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DRUCE C ASSIGNMENT 2
- //initializes/defines the output pin of the LM35 temperature sensor
- int outputpin= 0;
- //this sets the ground pin to LOW and the input voltage pin to high
- void setup()
- {
- Serial.begin(9600);
- // initialize digital pin 13,12,11,10,9,8 as an output.
- pinMode(13, OUTPUT);
- pinMode(12, OUTPUT);
- pinMode(11, OUTPUT);
- pinMode(10, OUTPUT);
- pinMode(9, OUTPUT);
- pinMode(8, OUTPUT);
- }
- // main loop
- void loop()
- {
- int rawvoltage= analogRead(A1);
- float millivolts= (rawvoltage/1024.0) * 5000;
- float celsius= millivolts/10;
- Serial.print(celsius);
- Serial.print(" degrees Celsius, ");
- Serial.print((celsius * 9)/5 + 32);
- Serial.println(" degrees Fahrenheit");
- delay(1000);
- //Condition 01 If the ambient temperature is between 0 and 5.5 degrees c .The program will turn on 1 led.
- if (celsius > 0 || celsius < 5.5)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- }
- //Condition 02 If temperature is between 5.5 and 15.5 degrees then 2 leds are switched on.
- if (celsius > 5.5 || celsius < 15.5)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- }
- //Condition 03 If temperature is between 15.5 and 20.5 degrees then 3 leds are switched on.
- if (celsius > 15.5 || celsius < 20.5)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- }
- //Condition 04 If the ldr is sensing lights are on and temperature is between 20.5 and 25.5 degrees then 4 leds are switched on and 1 fan is on.
- if (celsius > 20.5 || celsius < 25.5)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
- }
- /*if (light > 49)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
- }
- */
- //Condition 05 If lights are on and temperature is between 25.5 and 29.5 degrees then 5 leds are switched on and 1 fan is switched on.
- if (celsius > 25.5 || celsius < 29.5)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
- }
- /*if (light > 49)
- {
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(8, HIGH); // turn the FAN on (HIGH is the voltage level)
- }
- */
- //Condition 06 If temperature is between -5 and 0 then 5 leds are flashing at 5 hertz.
- if (celsius < 0)
- {
- digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
- delay (200);
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
- delay (200);
- }
- //Condition 07 If temperature is above 29.5 degrees 5 leds are flashing at 15 hertz.
- if (celsius > 29.5)
- {
- digitalWrite(13, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, LOW); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, LOW); // turn the LED on (HIGH is the voltage level)
- delay (66.6);
- digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(12, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(11, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
- digitalWrite(9, HIGH); // turn the LED on (HIGH is the voltage level)
- delay (66.6);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement