lot of cleanups

This commit is contained in:
Johannes Findeisen 2015-08-26 01:39:01 +02:00
commit a3571ceb42
3 changed files with 22 additions and 57 deletions

View file

@ -1,68 +1,21 @@
// Written 2015 by Johannes Findeisen <you@hanez.org>
/*
This is a simple code to test BH1750FVI Light senosr
communicate using I2C Protocol
this library enable 2 slave device address
Main address 0x23
secondary address 0x5C
connect this sensor as following :
VCC >>> 3.3V
SDA >>> A4
SCL >>> A5
addr >> A3
Gnd >>>Gnd
Written By : Mohannad Rawashdeh
*/
// First define the library :
#include <Wire.h> #include <Wire.h>
#include <BH1750FVI.h> #include <BH1750FVI.h>
BH1750FVI LightSensor; BH1750FVI LightSensor;
void setup() {
void setup() { // put your setup code here, to run once: Serial.begin(9600);
Serial.begin(9600);
LightSensor.begin(); LightSensor.begin();
/* LightSensor.SetAddress(Device_Address_L);
Set the address for this sensor
you can use 2 different address
Device_Address_H "0x5C"
Device_Address_L "0x23"
you must connect Addr pin to A3 .
*/
LightSensor.SetAddress(Device_Address_L);//Address 0x5C
// To adjust the slave on other address , uncomment this line
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
//-----------------------------------------------
/*
set the Working Mode for this sensor
Select the following Mode:
Continuous_H_resolution_Mode
Continuous_H_resolution_Mode2
Continuous_L_resolution_Mode
OneTime_H_resolution_Mode
OneTime_H_resolution_Mode2
OneTime_L_resolution_Mode
The data sheet recommanded To use Continuous_H_resolution_Mode
*/
LightSensor.SetMode(Continuous_H_resolution_Mode); LightSensor.SetMode(Continuous_H_resolution_Mode);
Serial.println("Running...");
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: uint16_t lux = LightSensor.GetLightIntensity(); // Get Lux value
uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value Serial.print("Light: ");
Serial.print("LightX: ");
Serial.print(lux); Serial.print(lux);
Serial.println(" lux"); Serial.println(" lux");
delay(250); delay(1000);
} }

View file

@ -1,3 +1,4 @@
// Written 2015 by Johannes Findeisen <you@hanez.org>
#include <Wire.h> #include <Wire.h>

View file

@ -39,19 +39,25 @@ void setup()
LightSensor.begin(); LightSensor.begin();
LightSensor.SetAddress(Device_Address_L); // Address 0x23 LightSensor.SetAddress(Device_Address_L); // Address 0x23
LightSensor.SetMode(Continuous_H_resolution_Mode); LightSensor.SetMode(Continuous_H_resolution_Mode);
lcd.init(); lcd.init();
lcd.backlight(); lcd.backlight();
// Get data for the first time. // Get data for the first time.
// Read this to understand the temperature calculation: // Read this to understand the temperature calculation:
// http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/ // http://www.danielandrade.net/2008/07/05/temperature-sensor-arduino/
tempC = (5.0 * analogRead(tempPin) * 100.0) / 1024.0; tempC = (5.0 * analogRead(tempPin) * 100.0) / 1024.0;
tempClast = tempC; tempClast = tempC;
// Celsius to Fahrenheit conversion // Celsius to Fahrenheit conversion
tempF = (tempC * 9) / 5 + 32; tempF = (tempC * 9) / 5 + 32;
// Get light sensor data // Get light sensor data
lux = LightSensor.GetLightIntensity(); lux = LightSensor.GetLightIntensity();
// Get data from other Arduino on 0x07 // Get data from other Arduino on 0x07
read_wire(); read_wire();
// Refresh the LCD output // Refresh the LCD output
lcd_refresh(); lcd_refresh();
} }
@ -69,14 +75,19 @@ void loop()
} }
// Calculate temperature // Calculate temperature
tempC = tempC / (float)samples; tempC = tempC / (float)samples;
// Celsius to Fahrenheit conversion. // Celsius to Fahrenheit conversion.
tempF = (tempC * 9) / 5 + 32; tempF = (tempC * 9) / 5 + 32;
// Get light sensor data // Get light sensor data
lux = LightSensor.GetLightIntensity(); lux = LightSensor.GetLightIntensity();
// Get data from I2C attached Arduino // Get data from I2C attached Arduino
read_wire(); read_wire();
// Print results to the display. // Print results to the display.
lcd_refresh(); lcd_refresh();
// Remember current temperature for next run. // Remember current temperature for next run.
tempClast = tempC; tempClast = tempC;
} }
@ -86,9 +97,9 @@ void lcd_refresh() {
lcd.clear(); lcd.clear();
lcd.setCursor(0, 0); lcd.setCursor(0, 0);
lcd.print(lux); lcd.print(lux);
lcd.print(" Lux / "); lcd.print("Lux/");
lcd.print(photo); lcd.print(photo);
lcd.print(" Pr"); lcd.print((char)0b11110100); // Thats the sign for Ohm but the value is not Ohm. I use this sign to represent the photo resister value
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
lcd.print(tempC); lcd.print(tempC);
lcd.print((char)223); // ASCII code 223 = "°" lcd.print((char)223); // ASCII code 223 = "°"