A place users can post their projects. If you have a small project and would like your own dedicated place to post and have others chat about it then this is your spot.

User avatar
By JIrka Boss
#58809 Hi. I need use sensor Bh1750 for sending data to app Blynk.. But i dont have a code...
Here is only cody what me working but this code send data to serial port.. thanks
#include <Wire.h>
#include <math.h>
int BH1750address = 0x23; //i2c address

byte buff[2];
void setup()
{
Wire.begin();
Serial.begin(57600);
}

void loop()
{
int i;
uint16_t val=0;
BH1750_Init(BH1750address);
delay(200);

if(2==BH1750_Read(BH1750address))
{
val=((buff[0]<<8)|buff[1])/1.2;
Serial.print(val,DEC);
Serial.println("lux");
}
delay(150);
}

int BH1750_Read(int address) //
{
int i=0;
Wire.beginTransmission(address);
Wire.requestFrom(address, 2);
while(Wire.available()) //
{
buff[i] = Wire.read(); // receive one byte
i++;
}
Wire.endTransmission();
return i;
}

void BH1750_Init(int address)
{
Wire.beginTransmission(address);
Wire.write(0x10);//1lx reolution 120ms
Wire.endTransmission();
}
User avatar
By JIrka Boss
#58828 SO i find it.

```

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>

#include <Wire.h>
#include <BH1750.h> // https://github.com/claws/BH1750
BH1750 lightMeter;

#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22 // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "75a3e91cbdf1457c9498b35eea63e9c1"; // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

void setup()
{
Serial.begin(9600); // See the connection status in Serial Monitor
Blynk.begin(auth, "ASUS", "Jersin72"); //insert here your SSID and password

lightMeter.begin();

// Setup a function to be called every second
timer.setInterval(10000L, sendUptime);
}

void sendUptime()
{

uint16_t lux = lightMeter.readLightLevel();
Blynk.virtualWrite(4, lux);

// You can send any value at any time.
// Please don't send more that 10 values per second.
//Read the Temp and Humidity from DHT
float h = dht.readHumidity();
float t = dht.readTemperature();

Blynk.virtualWrite(12, t); // virtual pin
Blynk.virtualWrite(13, h); // virtual pin
}

void loop()
{

uint16_t lux = lightMeter.readLightLevel();
Serial.print("Light: ");
Serial.print(lux);
Serial.println(" lx");
delay(1000);

Blynk.run();
timer.run();
}



```