Sunday, December 21, 2014

Weather station code (not Working) 2.1Experimental

Here is the code:
 Version 2.1Experimental:

/*


 Uses an 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.


  The circuit:
 * LCD RS pin to digital pin 27
 * LCD Enable pin to digital pin 26
 * LCD D4 pin to digital pin 25
 * LCD D5 pin to digital pin 24
 * LCD D6 pin to digital pin 23
 * LCD D7 pin to digital pin 22
 * LCD R/W pin to ground
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)




  */

// include the library code:
#include <LiquidCrystal.h>
//define the aref voltage
#define aref_voltage 5.0
//define if the level lights should be on
#define levelLightsOne 1
#define levelLightsTwo 1
//define if the temperature should be shown in farenheit or celcius
#define Farenheit 0
#define Celcius 1
//setup the level lights
int greenOne = 36;
int greenTwo = 37;
int yellowOne = 34;
int yellowTwo = 35;
int redOne = 32;
int redTwo = 33;
//setup the sensor pins
int tempOne = A0;
int lightOne = A1;
int lightTwo = A2;
//setup the reading variables
int lightReadingOne;
int lightReadingTwo;
int tempReadingOne;
//set the reference voltage of the board
const float referenceVolts = 5;



// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  //set the level light pins to outputs
  pinMode(greenOne, OUTPUT);
  pinMode(greenTwo, OUTPUT);
  pinMode(yellowOne, OUTPUT);
  pinMode(yellowOne, OUTPUT);
  pinMode(redOne, OUTPUT);
  pinMode(redTwo, OUTPUT);
  //set the sensor pins to inputs
  pinMode(tempOne, INPUT);
  pinMode(lightOne, INPUT);
  pinMode(lightTwo, INPUT);
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
}


void loop() {
    //set the cursor to column 0, line 1
    // (note: line 1 is the second row, since counting begins with 0):
    lcd.setCursor(0, 0);
    lcd.print("..Initializing..");
   while (millis() < 5000) {
      lightReadingOne = analogRead(lightOne);
      lightReadingTwo = analogRead(lightTwo);
   }
          //declare how the arduino should read the sensors
            lightReadingOne = analogRead(lightOne);
            lightReadingTwo = analogRead(lightTwo);
            tempReadingOne = analogRead(tempOne);
                delay(2000);
                lcd.clear();
                lcd.setCursor(0, 0);
                // Print the current settings to the LCD.
                lcd.print("Your Settings:");
                lcd.setCursor(0, 1);
                   if (Farenheit == 1)
                   {
                     lcd.print("Temperature: F");
                   }
                       #if Celcius
                          lcd.print("Temperature: C");
                       #endif
                          delay(3000);
                          lcd.clear();
                          lcd.setCursor(0, 0);
                              #if Celcius
                                analogRead(lightTwo);
                                analogRead(lightOne);
                                analogRead(tempOne);
                                lightReadingOne = analogRead(lightOne);
                                lightReadingTwo = analogRead(lightTwo);
                                tempReadingOne = analogRead(tempOne);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                delay(100);
                                start:
                                delay(500);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Temperature");
                                lcd.setCursor(0, 1);
                                analogRead(tempOne);
                                float voltage = tempReadingOne * aref_voltage / 1024; 
                                float temperatureC = (voltage - 0.5) * 100 ;
                                float temperatureF = (temperatureC * 9 / 5) + 32;
                                lcd.print(temperatureC);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Outside");
                                lcd.setCursor(0, 1);
                                analogRead(lightOne);
                                lightReadingOne = analogRead(lightOne);
                                lcd.print(lightOne);
                                delay(2000);
                                lcd.clear();
                                lcd.setCursor(0, 0);
                                lcd.print("Light Indoors");
                                lcd.setCursor(0, 1);
                                analogRead(lightTwo);
                                lightReadingTwo = analogRead(lightTwo);
                                lcd.print(lightTwo);
                                delay(2000);
                                goto start;
                             #endif   
                                #if Farenheit
                                    lcd.clear();
                                    delay(100);
                                    start2:
                                    lcd.clear();
                                    lcd.setCursor(0, 0);
                                    lcd.print("Temperature");
                                    lcd.setCursor(0, 1);
                                    lcd.print(temperatureF);
                                    delay(5000);
                                    lcd.clear();
                                    lcd.setCursor(0, 0);
                                    lcd.print("Light Outside");
                                    lcd.setCursor(0, 1);
                                    lcd.print(lightReadingOne);
                                    delay(5000);
                                    lcd.clear();
                                    lcd.setCursor(0, 0);
                                    lcd.print("Light Indoors");
                                    lcd.setCursor(0, 1);
                                    lcd.print(lightReadingTwo);
                                    delay(5000);
                                    goto start2;
                                #endif

}



No comments:

Post a Comment