Spotted Wood Fowl [BH1750]
Connecting the BH1750 light sensor
This projects uses a BH1750 light sensor and is connected to the board in the following manner.
[VCC - +] [GND - -] [SCL - 21] [SDA - 20] [ADDR - -]
Connecting the MP3 Player
Power can be connected to the breadboard power rails if required. But for this setup, Power is connected directly to the VCC and Ground is connected directly to the GRD of MP3 Player. TX is connected to [P10] while RX is connect to [P11].
The Arduino Code
The arduino code has been included in the file. Or provided below.
You will also need the Serial MP3 and BH1750 library.
#include <Wire.h> #include <<b>BH1750</b>.h> #include "SerialMP3Player.h" #define TX 11 #define RX 10 <b>BH1750</b> lightMeter; <b>SerialMP3Player</b> mp3(RX,TX); void setup(){ <b>Serial</b>.begin(9600); // Initialize the I2C bus (BH1750 library doesn't do this automatically) // On esp8266 devices you can select SCL and SDA pins using Wire.begin(D4, D3); Wire.begin(); lightMeter.begin(); <b>Serial</b>.println(F("BH1750 Test")); mp3.begin(9600); // start mp3-communication delay(500); // wait for init mp3.sendCommand(CMD_SEL_DEV, 0, 2); //select sd-card delay(500); // wait for init } void loop() { float lux = lightMeter.readLightLevel(); <b>Serial</b>.print("Light: "); <b>Serial</b>.print(lux); <b>Serial</b>.println(" lx"); delay(1000); if(lux<50){ mp3.play(); // Play "hello.mp3". You must hear "Hello World" <b>Serial</b>.print("Playing: "); delay(3000); // wait 3 seconds } if(lux>51){ mp3.stop(); // Play "hello.mp3". You must hear "Hello World" <b>Serial</b>.print("Stop: "); delay(3000); } }