Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Autor : Animum
- //Version : Beta 1
- //platform : Arduino Nano
- #include <math.h>
- #include <Wire.h>
- #include <BH1750.h>
- #include <DHT.h>
- #include <DallasTemperature.h>
- #include <OneWire.h>
- #include <LiquidCrystal.h>
- //define LCD pins
- LiquidCrystal lcd(6, 7, 9, 10, 11, 12);
- //define DS18B20 pin - use D4
- OneWire oneWire(4);
- DallasTemperature sensors(&oneWire);
- //define AM2302(DHT22) pin - use D5
- DHT SenDHT(5, DHT22);
- //define PH1750 sensors
- BH1750 lightMeter;
- //declaration of a LCD String
- String Row1, Row2;
- //declaration of a sensors variables
- float Temp1 = 0;
- float Hum = 0;
- float Temp2 = 0;
- word Lux = 0;
- //declaration of a mathematical variable
- double DewPo = 0;
- double Temppom = 0;
- double Mathpom = 0;
- //declare Menu position byte
- byte Menu = 0;
- void setup() {
- // put your setup code here, to run once:
- // lcd init
- lcd.begin(16, 2);
- sensors.begin();
- //LCD backlight pin
- pinMode(8, OUTPUT);
- digitalWrite(8, HIGH);
- //DHT sensor init
- SenDHT.begin();
- //BH1750 init
- lightMeter.begin();
- //button pin
- pinMode(2,INPUT_PULLUP); //button 1 - Incrase screen roll
- pinMode(3,INPUT_PULLUP); //button 2 - Decrase screen roll
- //default Led pin
- pinMode(LED_BUILTIN, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- //Incrase Menu position
- if (digitalRead(2) == false)
- {
- digitalWrite(LED_BUILTIN, HIGH);
- while (digitalRead(2) == false)
- {
- delay(1);
- }
- if (Menu < 2)
- {
- ++Menu;
- }
- else
- {
- Menu = 0;
- }
- }
- //Decrase Menu position
- if (digitalRead(3) == false)
- {
- digitalWrite(LED_BUILTIN, HIGH);
- while (digitalRead(3) == false)
- {
- delay(1);
- }
- if (Menu > 0)
- {
- --Menu;
- }
- else
- {
- Menu = 2;
- }
- }
- digitalWrite(LED_BUILTIN, LOW);
- //reading sensors
- Temp1 = SenDHT.readTemperature();
- Hum = SenDHT.readHumidity();
- sensors.requestTemperatures();
- Temp2 = sensors.getTempCByIndex(0);
- Lux = lightMeter.readLightLevel();
- //clearing Row1 and Row2
- Row1, Row2 = " ";
- //LCD screen create
- if (Menu == 0)
- {
- Row1 = "Temp : " + String(Temp1, 2) + char(223) + "C";
- Row2 = "Hum : " + String(Hum, 2) + "%";
- }
- else if (Menu == 1)
- {
- Row1 = "Temp : " + String(Temp2, 2) + char(223) + "C";
- Row2 = "Lux : " + String(Lux);
- }
- else if (Menu == 2)
- {
- Temppom = (17.67 * Temp1) / (243.5 + Temp1);
- Mathpom = (Hum/100) * (exp(Temppom));
- Mathpom = log(Mathpom);
- DewPo = (243.5 * Mathpom) / (17.67 - Mathpom);
- Row1 = "Dew point :";
- Row2 = String(DewPo,2) + char(223) + "C";
- }
- else
- {
- Row1 = "Error";
- Row2 = "Error";
- }
- //view LCD screen
- lcd.clear();
- lcd.print(Row1);
- lcd.setCursor(0, 1);
- lcd.print(Row2);
- //waiting 2s
- delay(2000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement