Hi,
This is the coding, i have a dht11 sensor with humidity and temperature showing on my 16x2 lcd screen, and im trying to get my lux sensor to do the same, it shows up, but only says -2 lux, no matter the light level, so my question is. Can someone see a fault in my coding, or is my souder not good enough to have a connection to the sensor.
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <BH1750.h>
#include "DHT.h"
#define DHTPIN 5 //digital pin sensor
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
BH1750 lightMeter;
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
// Initialize the I2C bus (BH1750 library doesn't do this automatically)
// On esp8266 devices you can select SCL and SDA pins using Wire.begin(D4, D3);
Wire.begin();
lightMeter.begin();
Serial.println(F("BH1750 Test"));
lcd.begin(16, 2);
dht.begin();
}
void loop() {
float lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);
delay(1000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
lcd.print("No connection");
return;
}
lcd.setCursor(0, 0);
lcd.print(h);
lcd.print(" % ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(3,1);
lcd.print(lux);
lcd.print(" lux");
}
Thanks in advance!
Did You try using an example code for reading the lux sensor before integrating it to Your project?
The first thing that I do when I have a problem with an I2C device is to run the I2C scanner to confirm the device I2C address and if it will communicate with the bus.
// I2C scanner by Nick Gammon. Thanks Nick.
#include <Wire.h>
void setup() {
Serial.begin (115200); //***** make sure serial monitor baud matches *****
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 1; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
What does the i2C scanner return?
this is what i get running the code in the serial monitor
Nice picture but impossible to draw any conclusions from it.
That is the same picture in your other post on this subject. Like Railroader said, it is not very helpful. It would be better if you would hand draw a schematic and post a photo of that*. Also post the output from the I2C scanner. Please do not post a screenshot. Copy and paste the actual text from the serial monitor.
Im not trying to be rude, i dont understand all this arduino slang. I actually thought i posted what the i2c scanner said. As for a schematic of my project ive uploaded it in this post. I will gladly take a picture of what the i2c scanner said, but where is the text from the i2c scanner
What is "Arduino slang" in Your opinion? I find the words used as being standard terminology.
Thanks for the picture but a drawing, schematics is a lot more readable. There is no information telling which pin the colored lines connect to.
1 color is a specific signal
Blue line is the a5
green line is a4
Red is ground
black is 5v
purple is just a line to number 5 on the arduino.
For the arduino slang. If i told you, use the i2c scanner and tell me the addres, and your receiver of the message (me) know nothing about arduino, or the arduino programming app. How do you expect your receiver to understand what he is being told. In your bio it says seek education, thats what im trying to do, and right now you are not at good teacher to understand
Okey, thats the power supply lines. What kind of signal is connected to which input is what we would like to se.
It's a hard balance approaching new members. Some people have some knowledge, other members have very little knowledge, It looks like You are assumed to have "some knowledge".
Check the documentation for the I2C address and use that address if it clearly told.
If not, there are sketches scanning the I2C addresses and tell when there is a match.I did that once but I don't remember where I found it. Search for I2C address scanner if You need to.
If You know absolutly nothing about Arduino a starter kit and its exercises is a good way to get started. Else the step is huge to get accustomed.
Ive used this i2c scanner Find I2C Addresses on Arduino (I2C Scanner) - YouTube its made to find multiple i2c units and their address, when i used it in my circuit. The only address that showes was my lcdd 16x2 screen with the address 0x27. So with my knowledge i see 2 possibilities.
-
The lux sensor do not use i2c
-
The lux sensor is simply not connected, due to my poor souder job
is this safe to assume?
Can You provide data or a link to that LUX sensor? Either it uses single line digital comms or analog.
Most of the site are in danish. But some of the description is english:
Original BH1750FVI chip using ROHM
Power supply: DC3-5v
Illumination range :0-65535 lx
Sensors built 16bitAD converter
Direct digital output, omitting complex calculations, calibration is omitted
Does not distinguish between ambient light
Spectral characteristics close to visual sensitivity
A wide range of brightness can be measured with high precision 1 lux
Standard NXP IIC communication protocol
Module contains an internal communications level converter,
Directly connected with 5v microcontroller io
Well done!
The sensor sends serial digital digital data.
I don't know what "Standard NXP IIC communication protocol" means. Maybe some other helper does?
Could You Google on "Arduino + BH1750FVI"? Surely there is a communiction sketch that interfaces the sensor.
andreas4955:
For the arduino slang. If i told you, use the i2c scanner and tell me the addres, and your receiver of the message (me) know nothing about arduino, or the arduino programming app. How do you expect your receiver to understand what he is being told.
In such situations, what I do is Google the term, in this case "i2c scanner" or "i2c scanner arduino". I just googled "BH1750FVI" and quickly found the complete data sheet, in English not Danish.