Skip to main content

How to use BH1750 Ambient light sensor with Arduino

 


Hey,

In today's blog we are going to use BH1750 ambient light sensor with Arduino.


WHAT YOU NEED :

Arduino Uno

16×2 LCD display

10k potentiometer

BH1705 Light sensor

Breadboard

Jumper wires


CODE :

#include<Wire.h>
#include<LiquidCrystal.h>
 
int BH1750address = 0x23;
byte buff[2];
LiquidCrystal lcd (7,6,5,4,3,2); //RS, E, D4, D5, D6, D7

void setup()
{
  Wire.begin();
  //Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print("  BH1750 Light  ");
  lcd.setCursor(0,1);
  lcd.print("Intensity Sensor");
  delay(2000);
}
 
void loop()
{
  int i;
  uint16_t value=0;
  BH1750_Init(BH1750address);
  delay(200);
 
  if(2==BH1750_Read(BH1750address))
  {
    value=((buff[0]<<8)|buff[1])/1.2;
    lcd.clear();
    lcd.print("Intensity in LUX");
    lcd.setCursor(6,1);
    lcd.print(value);
    
    //Serial.print(val);     
    //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();
    i++;
  }
  Wire.endTransmission();  
  return i;
}
 
void BH1750_Init(int address) 
{
  Wire.beginTransmission(address);
  Wire.write(0x10);
  Wire.endTransmission();
}

Making electronics project is too pretty simple with Us.



Join and Make with Us.

Comments

Popular posts from this blog

Controlling A Servo Motor Using MPU 6050 Sensor .

Hello guys, In this post we are going to tell you that how you can control servo motor using MPU Sensor. Please subscribe to our blog, so that you can't miss any update from us.Join us @Microelectronics. Code and circuit diagram is given post. Material required- 1-MPU Sensor 2-An Arduino 3-Servo motor  4-Some jumper wires Circuit diagram- Source code- // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files // for both classes must be in the include path of your project #include "I2Cdev.h" #include "MPU6050_6Axis_MotionApps20.h" //#include "MPU6050.h" // not necessary if using MotionApps include file // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation // is used in I2Cdev.h #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE     #include "Wire.h" #endif #include <Servo.h> Servo myservo;  // create servo object to control a servo   // class default I2C address is 0x...

How to make smartphone control robot car using Nodemcu

  Hey, In today's blog we are going to build a robot car using Nodemcu. REQUIRED STUFF: Nodemcu Bluetooth module Motor driver ic BO motor BO motor wheel Chassis 3.7 v battery SCHEMATIC:   CODE IT: Making electronics is too pretty simple with Us. Join and Make with Us.

How To Make A Real Time GPS Location Tracker Using NodeMcu ?

Hello Guys , Welcome Back To Another Post From Microelectronics , In This Post We Will Learn That How To Make A Real Time GPS Location Tracker Using NodeMcu Module. For Further Details You Can Aks Your Question In Message Bar. Material Required - Nodemcu ESP8266 Ublox NEO 6M GPS Jumpers Connections:-  VCC  -  3.3V GND  -  GND RX  -  D1 TX  -  D2 Code - #include <TinyGPS++.h> #include <SoftwareSerial.h> #define BLYNK_PRINT Serial #include <ESP8266WiFi.h> #include <BlynkSimpleEsp8266.h> static const int RXPin = 4, TXPin = 5;   // GPIO 4=D2(conneect Tx of GPS) and GPIO 5=D1(Connect Rx of GPS static const uint32_t GPSBaud = 9600; //if Baud rate 9600 didn't work in your case then use 4800 TinyGPSPlus gps; // The TinyGPS++ object WidgetMap myMap(V0);  // V0 for virtual pin of Map Widget SoftwareSerial ss(RXPin, TXPin);  // The serial connection to the GPS device BlynkTimer timer; f...