Ok, here we go.
Copied the format from the Wiki:
[size=18pt]Light (lux) Sensor[/size]
[size=14pt]Software[/size]
You will need to download the BH1750 library from github here: https://github.com/Genotronex/BH1750FVI_Master and include it in your Arduino IDE
Please find the Arduino sketch below.
The code is a compilation of the original light sensor from hek and BH1750FVI code from Mohannad Rawashdeh.
This sensor sleeps most of the time. You can change the sleep interval by updating SLEEP_TIME define at the top of the file.
[size=14pt]Wire things up[/size]
Follow the instructions in ConnectingRadioModule [url=http://code.mios.com/trac/mios_arduino-sensor/wiki/ConnectingRadioModule]ConnectingRadioModule[/url] – Arduino Sensor Plugin to connect radio module.
Connect the Light Sensor as follows:
[ul][li]Light Sensor VCC to 3.3V on the Arduino Board[/li]
[li]Light Sensor SDA to a 510 ohm resistor and from there to A4 (analog input) on the Arduino Board[/li]
[li]Light Sensor SCL to a 510 ohm resistor and from there to A5 (analog input) on the Arduino Board[/li]
[li]Light Sensor addr to a 510 ohm resistor and from there to A3 (analog input) on the Arduino Board[/li]
[li]Light Sensor GND to GND on the Arduino Board.[/li][/ul]
If you use a Arduino board with a I/OREF Pin you can connect SDA, SCL and addr directly to the pins on the Arduino board without the need for the resistor but you need to bridge the 3.3v and I/OREF Pin on the Arduino.
The I/OREF pin on the Arduino board provides the voltage reference with which the microcontroller operates. This should allow the selection of the appropriate power source or enable voltage translators on the outputs for working with 5V or 3.3V.
As I’m using a Arduino Nano, I have not tested whether this work though.
[size=14pt]Hardware - Purchase guide[/size]
To build this sensor you’ll need one arduino + radio specified in the base kit found here:
[url=http://code.mios.com/trac/mios_arduino-sensor/wiki/WikiStart#Buyingguide]Arduino Sensor Plugin
With the following additional parts:
1x BH1750 Digital Light Sensor
3x 510 ohm resistor
TOTAL SENSOR PRICE: $7.6 (arduino + radio) + $3.18 (digital light sensor) + $0.1 (resistors) = $10.88
[size=14pt]Code[/size]
/*
Vera Arduino BH1750FVI Light sensor
communicate using I2C Protocol
this library enable 2 slave device addresses
Main address 0x23
secondary address 0x5C
connect the sensor as follows :
VCC >>> 3.3V
SDA >>> 510 Ohm Resistor >>> A4
SCL >>> 510 Ohm Resistor >>> A5
addr >> 510 Ohm Resistor >>> A3
Gnd >>>Gnd
*/
#include <Sleep_n0m1.h>
#include <SPI.h>
#include <RF24.h>
#include <EEPROM.h>
#include <Sensor.h>
#include <BH1750FVI.h> // Sensor Library - download here: https://github.com/Genotronex/BH1750FVI_Master
#include <Wire.h> // I2C Library - download here: https://github.com/Genotronex/BH1750FVI_Master
// Set RADIO_ID to something unique in your sensor network (1-254)
// or set to AUTO if you want gw to assign a RADIO_ID for you.
#define RADIO_ID AUTO
#define CHILD_ID_LIGHT 0
#define LIGHT_SENSOR_ANALOG_PIN 0
BH1750FVI LightSensor;
unsigned long SLEEP_TIME = 30; // Sleep time between reads (in seconds)
Sensor gw(9,10);
int lastlux;
Sleep sleep;
void setup()
{
Serial.begin(BAUD_RATE); // Used to type in characters
gw.begin(RADIO_ID);
// Register all sensors to gateway (they will be created as child devices)
gw.sendSensorPresentation(CHILD_ID_LIGHT, S_LIGHT_LEVEL);
LightSensor.begin();
/*
Set the address for this sensor
you can use 2 different address
Device_Address_H "0x5C"
Device_Address_L "0x23"
you must connect Addr pin to A3 .
*/
LightSensor.SetAddress(Device_Address_H);//Address 0x5C
// To adjust the slave on other address , uncomment this line
// lightMeter.SetAddress(Device_Address_L); //Address 0x5C
//-----------------------------------------------
/*
set the Working Mode for this sensor
Select the following Mode:
Continuous_H_resolution_Mode
Continuous_H_resolution_Mode2
Continuous_L_resolution_Mode
OneTime_H_resolution_Mode
OneTime_H_resolution_Mode2
OneTime_L_resolution_Mode
The data sheet recommend to use Continuous_H_resolution_Mode
*/
LightSensor.SetMode(Continuous_H_resolution_Mode);
}
void loop()
{
gw.powerUp(); // Power up radio
uint16_t lux = LightSensor.GetLightIntensity();// Get Lux value
Serial.println(lux);
if (lux != lastlux) {
gw.sendVariable(CHILD_ID_LIGHT, V_LIGHT_LEVEL, lux);
lastlux = lux;
}
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(1000); //delay to allow serial to fully print before sleep
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
}
[size=14pt]Print it…[/size]
Below STL contains a small housing for the sensor which can be 3D printed.
The box allows the installation of the sensor board, arduino board and RF module.
It is all powered by external USB connector.
- Solder the lux sensor to the top of the Arduino mini and the RF sensor to the bottom.
- Keep the connection cables short for easy installation.
- Kept the cables long enough to loop them once so that they create a barrier between the boards. If you are worried of a short circuit simply sandwich a piece of thick paper in between.
The cover snaps into place at the end.
Print Settings: 2 shells, 20% infill 0.2mm layer height.