Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
walkingnewbieteddyyoonie
Published © GPL3+

Power source switching between two power sources

Switches between two power sources depending on the surrounding light intensity.

BeginnerFull instructions provided3,136
Power source switching between two power sources

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
5V One Channel Relay Module
×1
BH1750 Light Intensity Illumination Module
×1
LED (generic)
LED (generic)
×3
Breadboard (generic)
Breadboard (generic)
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

Bench Demo Schematic

Outside Appliation Demo Schematic

Code

relay_module_BHV1750_test.ino

Arduino
/*
 *arduino realy controlled by light sensing.
 *Sense surrounding light intensity with BHV1750. 
 *Relay module:
 *  if Logic Low: NC--Com connected
 *  if Logic High: NO--Com connected
 *If it is dark, connect power source A (Normally Closed), eg. AC power adapter. 
 *If is is bright, connect power source B (Normally Open).eg, Solar panel generation.
 */

#include <Wire.h>
#include <BH1750.h>
BH1750 lightMeter;

// constants won't change
const int RELAY_PIN = 3;  // the Arduino pin, which connects to the IN pin of relay
const float LIGHT_THRESHOLD = 250.;  //Threshhold for power source selection

// the setup function runs once when you press reset or power the board
void setup() {
  Serial.begin(9600);
  
  // initialize digital pin as an output.
  pinMode(RELAY_PIN, OUTPUT);
  // start with relay pin low - source A
  digitalWrite(RELAY_PIN, LOW);
  delay(3000);
  
  Serial.begin(9600);
  Wire.begin();
  lightMeter.begin();
  Serial.println(F("BH1750 Test"));
  
}

// the loop function runs over and over again forever
void loop() {
  float lux = lightMeter.readLightLevel();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lx");

  if (lux < LIGHT_THRESHOLD) {
    digitalWrite(RELAY_PIN, LOW);    
  }
  else {
    digitalWrite(RELAY_PIN, HIGH);
  }
delay(3000);

}

Credits

walkingnewbie
2 projects • 2 followers
Contact
teddyyoonie
3 projects • 1 follower
Contact

Comments

Please log in or sign up to comment.