Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "DHT.h"
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <Adafruit_INA219.h>
- #define DHTPIN 2
- #define DHTTYPE DHT11
- #define VOLT A1
- #define LUX A3
- DHT dht(DHTPIN, DHTTYPE);
- LiquidCrystal_I2C lcd(0x27, 20, 4);
- Adafruit_INA219 ina219;
- // ok ok ok ok
- float Temperature, volt, volts, lux;
- // ok ok
- int temp1, value;
- byte degree[8] =
- {
- 0b00011,
- 0b00011,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000,
- 0b00000
- };
- void setup()
- {
- Serial.begin(9600);
- dht.begin();
- ina219.begin();
- ina219.setCalibration_32V_1A();
- lcd.init();
- lcd.init();
- lcd.backlight();
- lcd.createChar(1, degree);
- lcd.setCursor(0, 0);
- lcd.print(" Soler Energy ");
- lcd.setCursor(0, 1);
- lcd.print(" Measurement ");
- delay(2000);
- lcd.clear();
- }
- void loop()
- {
- /*-----------Current---------*/
- float shuntvoltage = 0;
- float busvoltage = 0;
- float current_mA = 0;
- float loadvoltage = 0;
- float power_mW = 0;
- shuntvoltage = ina219.getShuntVoltage_mV();
- busvoltage = ina219.getBusVoltage_V();
- current_mA = ina219.getCurrent_mA();
- power_mW = ina219.getPower_mW();
- loadvoltage = busvoltage + (shuntvoltage / 1000);
- delay(10);
- /*---------Temperature-------*/
- float t = dht.readTemperature();
- Temperature = t;
- delay(10);
- /*---------Voltage----------*/
- temp1 = analogRead(VOLT);
- volts = (temp1 / 255.0) * 5.0;
- delay(10);
- /*-----Light Intensity------*/
- value = analogRead(LUX);
- volt = (value / 1023.0) * 5;
- lux = ((2500 / volt) - 500) / 3.3;
- delay(10);
- /*------Display Result------*/
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("T:");
- lcd.print((int)Temperature);
- lcd.write(1);
- lcd.print("C");
- lcd.setCursor(8, 0);
- lcd.print("V:");
- lcd.print(volts);
- lcd.setCursor(0, 1);
- lcd.print("L:");
- lcd.print((int)lux);
- //lcd.print("Lux");
- lcd.setCursor(8, 1);
- lcd.print("I:");
- lcd.print(int(current_mA));
- lcd.print("mA");
- Serial.print((int)Temperature);
- Serial.print("\t");
- Serial.print(volts);
- Serial.print("\t");
- Serial.print(current_mA);
- Serial.println((int)lux);
- delay(1500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement