Advertisement
safwan092

Untitled

Nov 23rd, 2021
944
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.18 KB | None | 0 0
  1. #include "DHT.h"
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. #include <Adafruit_INA219.h>
  5.  
  6.  
  7. #define DHTPIN 2
  8. #define DHTTYPE DHT11
  9. #define VOLT A1
  10. #define LUX A3
  11.  
  12.  
  13. DHT dht(DHTPIN, DHTTYPE);
  14. LiquidCrystal_I2C lcd(0x27, 20, 4);
  15. Adafruit_INA219 ina219;
  16.  
  17. //       ok         ok    ok    ok
  18. float Temperature, volt, volts, lux;
  19. //   ok     ok
  20. int temp1, value;
  21.  
  22. byte degree[8] =
  23. {
  24.   0b00011,
  25.   0b00011,
  26.   0b00000,
  27.   0b00000,
  28.   0b00000,
  29.   0b00000,
  30.   0b00000,
  31.   0b00000
  32. };
  33.  
  34. void setup()
  35. {
  36.   Serial.begin(9600);
  37.   dht.begin();
  38.   ina219.begin();
  39.   ina219.setCalibration_32V_1A();
  40.   lcd.init();
  41.   lcd.init();
  42.   lcd.backlight();
  43.   lcd.createChar(1, degree);
  44.   lcd.setCursor(0, 0);
  45.   lcd.print("  Soler Energy  ");
  46.   lcd.setCursor(0, 1);
  47.   lcd.print("  Measurement   ");
  48.   delay(2000);
  49.   lcd.clear();
  50. }
  51.  
  52. void loop()
  53. {
  54.  
  55.   /*-----------Current---------*/
  56.   float shuntvoltage = 0;
  57.   float busvoltage = 0;
  58.   float current_mA = 0;
  59.   float loadvoltage = 0;
  60.   float power_mW = 0;
  61.   shuntvoltage = ina219.getShuntVoltage_mV();
  62.   busvoltage = ina219.getBusVoltage_V();
  63.   current_mA = ina219.getCurrent_mA();
  64.   power_mW = ina219.getPower_mW();
  65.   loadvoltage = busvoltage + (shuntvoltage / 1000);
  66.   delay(10);
  67.  
  68.   /*---------Temperature-------*/
  69.   float t = dht.readTemperature();
  70.   Temperature = t;
  71.   delay(10);
  72.  
  73.   /*---------Voltage----------*/
  74.   temp1 = analogRead(VOLT);
  75.   volts = (temp1 / 255.0) * 5.0;
  76.   delay(10);
  77.  
  78.   /*-----Light Intensity------*/
  79.   value = analogRead(LUX);
  80.   volt = (value / 1023.0) * 5;
  81.   lux = ((2500 / volt) - 500) / 3.3;
  82.   delay(10);
  83.  
  84.   /*------Display Result------*/
  85.   lcd.clear();
  86.   lcd.setCursor(0, 0);
  87.   lcd.print("T:");
  88.   lcd.print((int)Temperature);
  89.   lcd.write(1);
  90.   lcd.print("C");
  91.  
  92.   lcd.setCursor(8, 0);
  93.   lcd.print("V:");
  94.   lcd.print(volts);
  95.  
  96.   lcd.setCursor(0, 1);
  97.   lcd.print("L:");
  98.   lcd.print((int)lux);
  99.   //lcd.print("Lux");
  100.  
  101.   lcd.setCursor(8, 1);
  102.   lcd.print("I:");
  103.   lcd.print(int(current_mA));
  104.   lcd.print("mA");
  105.  
  106.   Serial.print((int)Temperature);
  107.   Serial.print("\t");
  108.   Serial.print(volts);
  109.   Serial.print("\t");
  110.   Serial.print(current_mA);
  111.   Serial.println((int)lux);
  112.   delay(1500);
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement