ESP8266 12E BH1750 Blynk
Posted: Mon Nov 28, 2016 3:36 pm
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();
}
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();
}