toy project #2 light & temp configurator

// include the library code:

#include <LiquidCrystal.h>
#include <Wire.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8,9,4, 5, 6,7);


//TMP36 Pin Variables
int temperaturePin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to the resolution is 10 mV / degree centigrade(500 mV offset) to make negative temperatures an option
//PhotoResistor Pin
int lightPin = 1; //the analog pin the photoresistor is connected to the photoresistor is not calibrated to any units so this is simply a raw sensor value (relative light)
//led for light sensor
int lcdRed = 3;   //the pin the LED is connected to
int lcdBlue = 5;   //the pin the LED is connected to
//pir sensor
const int PIR=10; 



void setup()

{

  // set up the LCD's number of columns and rows:

lcd.begin(16,2);
Serial.begin(9600);  //Start the serial connection with the copmuter

                       //to view the result open the serial monitor

                       //last button beneath the file bar (looks like a box with an antena

pinMode(lcdRed, INPUT); //sets the led pin to input
pinMode(lcdBlue, INPUT); //sets the led pin to input
Wire.begin();

}





void loop()

                 {

Serial.println(PIR);
float temperature = (temperaturePin/1024.0)*5;  //getting the voltage reading from the temperature sensor
temperature = ((temperature - .5) * 100);//*1.8+32;          //converting from 10 mv per degree wit500 mV offset

                                                  //to degrees ((volatge - 500mV) times 100)

 Serial.println(temperature);                     //printing the result
delay(500);                                     //waiting a second



int lightLevel = analogRead(lightPin); //Read the
lightLevel = map(lightLevel, 0, 900, 0, 150);  //adjust the value 0 to 900 to span 0 to 255
lightLevel = constrain(lightLevel, 0, 150);   //make sure the value is betwween 0 and 255


int tempLevel = analogRead(temperaturePin)*100; //Read the
tempLevel = map(tempLevel, 66, 82, 0, 150);  //adjust the value 0 to 900 to span 0 to 255
tempLevel = constrain(tempLevel, 0, 150);   //make sure the value is betwween 0 and 255
analogWrite(lcdBlue, lightLevel);  //write the value
analogWrite(lcdRed, tempLevel);  //write the value


  lcd.setCursor(0, 0);
   lcd.print(temperature);
   lcd.setCursor(0, 1);
   lcd.print(lightLevel);
   lcd.setCursor(8, 0);
   lcd.print("Temp");   //display temp on the lcd
   lcd.setCursor(8, 1);
   lcd.print("Light");   //display light on the lcd
   delay(500);



 //lightLevel = constrain(lightLevel, 0, 255);//make sure the
        float temperaturePin;

 (analogRead(temperaturePin) * .004882814); //converting from a 0 to 1023 digital range
                  }

Comments

Popular posts from this blog

pointers code no lb

real time & EEPROM lab

interrup and sound lab