Devices & Components
Arduino Uno Rev3
Breadboard (generic)
5V One Channel Relay Module
Jumper wires (generic)
Resistor 221 ohm
LED (generic)
BH1750 Light Intensity Illumination Module
Project description
Code
relay_module_BHV1750_test.ino
arduino
1/* 2 *arduino realy controlled by light sensing. 3 *Sense surrounding light intensity with BHV1750. 4 *Relay module: 5 * if Logic Low: NC--Com connected 6 * if Logic High: NO--Com connected 7 *If it is dark, connect power source A (Normally Closed), eg. AC power adapter. 8 *If is is bright, connect power source B (Normally Open).eg, Solar panel generation. 9 */ 10 11#include <Wire.h> 12#include <BH1750.h> 13BH1750 lightMeter; 14 15// constants won't change 16const int RELAY_PIN = 3; // the Arduino pin, which connects to the IN pin of relay 17const float LIGHT_THRESHOLD = 250.; //Threshhold for power source selection 18 19// the setup function runs once when you press reset or power the board 20void setup() { 21 Serial.begin(9600); 22 23 // initialize digital pin as an output. 24 pinMode(RELAY_PIN, OUTPUT); 25 // start with relay pin low - source A 26 digitalWrite(RELAY_PIN, LOW); 27 delay(3000); 28 29 Serial.begin(9600); 30 Wire.begin(); 31 lightMeter.begin(); 32 Serial.println(F("BH1750 Test")); 33 34} 35 36// the loop function runs over and over again forever 37void loop() { 38 float lux = lightMeter.readLightLevel(); 39 Serial.print("Light: "); 40 Serial.print(lux); 41 Serial.println(" lx"); 42 43 if (lux < LIGHT_THRESHOLD) { 44 digitalWrite(RELAY_PIN, LOW); 45 } 46 else { 47 digitalWrite(RELAY_PIN, HIGH); 48 } 49delay(3000); 50 51} 52
relay_module_BHV1750_test.ino
arduino
1/* 2 *arduino realy controlled by light sensing. 3 *Sense surrounding light intensity with BHV1750. 4 *Relay module: 5 * if Logic Low: NC--Com connected 6 * if Logic High: NO--Com connected 7 *If it is dark, connect power source A (Normally Closed), eg. AC power adapter. 8 *If is is bright, connect power source B (Normally Open).eg, Solar panel generation. 9 */ 10 11#include <Wire.h> 12#include <BH1750.h> 13BH1750 lightMeter; 14 15// constants won't change 16const int RELAY_PIN = 3; // the Arduino pin, which connects to the IN pin of relay 17const float LIGHT_THRESHOLD = 250.; //Threshhold for power source selection 18 19// the setup function runs once when you press reset or power the board 20void setup() { 21 Serial.begin(9600); 22 23 // initialize digital pin as an output. 24 pinMode(RELAY_PIN, OUTPUT); 25 // start with relay pin low - source A 26 digitalWrite(RELAY_PIN, LOW); 27 delay(3000); 28 29 Serial.begin(9600); 30 Wire.begin(); 31 lightMeter.begin(); 32 Serial.println(F("BH1750 Test")); 33 34} 35 36// the loop function runs over and over again forever 37void loop() { 38 float lux = lightMeter.readLightLevel(); 39 Serial.print("Light: "); 40 Serial.print(lux); 41 Serial.println(" lx"); 42 43 if (lux < LIGHT_THRESHOLD) { 44 digitalWrite(RELAY_PIN, LOW); 45 } 46 else { 47 digitalWrite(RELAY_PIN, HIGH); 48 } 49delay(3000); 50 51} 52
Downloadable files
Bench Demo Schematic
Bench Demo Schematic

Bench Demo Schematic
Bench Demo Schematic

Outside Appliation Demo Schematic
Outside Appliation Demo Schematic

Comments
Only logged in users can leave comments