Guider‎ > ‎Hardware‎ > ‎Arduino‎ > ‎

Light and temperature monitor

Kit: Seeed Studio Electronic brick - Starter kit - http://www.seeedstudio.com/wiki/index.php?title=Electronic_Brick_Starter_Kit
Kode:


// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(10, 11, 12, 13, 14, 15, 16);

//PIN mappings
int Buzzer = 9;
int LED = 8;

void setup() {

  // setup serial
  Serial.begin(115200);
  // setup LED
  pinMode (Buzzer, OUTPUT);
  pinMode (LED, OUTPUT);
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // move cursor to colum 0 row 0
  lcd.setCursor(0,0);
  // print text
  lcd.print("Program starter");
  // move cursor to colum 0 row 1
  lcd.setCursor(0,1);
  // display text
  lcd.print("Vent venligst...");
  // 2000ms delay
  delay(1000); 
  // clear LCD screen
  lcd.clear();
}

void loop() {
  int potentimeter = 0;
  potentimeter = analogRead(3);
  int val = (potentimeter / 4 );
  float light = 0;
  light = analogRead(4);
  float temperature = 0;
  temperature = analogRead(5);
  temperature = temperature +252-500;
  temperature = temperature / 10;
  lcd.setCursor(0, 0);
  lcd.print("Lys: " );  // Write Light Text
  lcd.print(light);
  lcd.setCursor(0, 1);
  lcd.print("Temp: ");  // Write Light Text
  lcd.print(temperature);
  if (temperature >= 27) 
  {
    Serial.print("Temp :");
    Serial.print(temperature);
    Serial.println(" grader");
    Serial.println("Temperature Warning");
    analogWrite(Buzzer,val);
    lcd.setCursor(11,1);
    lcd.print(" WARN");
  }
  else 
  {
    Serial.print("Temp :");
    Serial.print(temperature);
    Serial.println(" grader");
    analogWrite(Buzzer,0);
    lcd.setCursor(11,1);
    lcd.print("     ");
  }
  if (light <= 250) 
  {
    Serial.print("Lys :");
    Serial.println(light);
    Serial.println("Light Warning");
    digitalWrite(LED,HIGH);
    lcd.setCursor(11,0);
    lcd.print(" WARN");
  }
  else 
  {
    Serial.print("Lys :");
    Serial.println(light);
    digitalWrite(LED,LOW);
    lcd.setCursor(11,0);
    lcd.print("     ");
  }
}
Comments