Rain in Jungle [VL53l0X]
Connecting the VL53l0X
VIN to [+ / VCC / 5V]
GND to [- / GND]
SDA to [A4]
SCL to [A5]
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].
Connecting the Relay
VIN to [+ / VCC / 5V]
GND to [- / GND]
Signal to [P3]
Refer to diagram in connecting the relay!!
Connecting the Relay
Follow the diagram in connecting the circuit in a normally open state.
The Arduino Code
The arduino code has been included in the file. Or provided below.
You will also need the Adafruit VL53l0X Library.
#include "Adafruit_VL53L0X.h" #include "SerialMP3Player.h" #define TX 11 #define RX 10 Adafruit_VL53L0X lox = Adafruit_VL53L0X(); int switchy = 0; SerialMP3Player mp3(RX,TX); // constants won't change const int RELAY_PIN = 3; // the Arduino pin, which connects to the IN pin of void setup() { delay(50); Serial.begin(9600); 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 //Relay humidifier combo pinMode(RELAY_PIN, OUTPUT); pinMode(switchy, OUTPUT); // digitalWrite(switchy, LOW); // digitalWrite(switchy, HIGH); // wait until serial port opens for native USB devices while (! Serial) { delay(1); } Serial.println("Adafruit VL53L0X test"); if (!lox.begin()) { Serial.println(F("Failed to boot VL53L0X")); while(1); } // power Serial.println(F("VL53L0X API Simple Ranging example\n\n")); } void loop() { VL53L0X_RangingMeasurementData_t measure; digitalWrite(RELAY_PIN, HIGH); // digitalWrite(15, LOW); Serial.print("Reading a measurement... "); lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout! if (measure.RangeStatus != 4) { // phase failures have incorrect data Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter); if(measure.RangeMilliMeter < 50){ Serial.println("Very close huh"); digitalWrite(RELAY_PIN, LOW); // digitalWrite(14, HIGH); Serial.println("Switched On"); mp3.play(); // Play "hello.mp3". You must hear "Hello World" delay(3000); // wait 3 seconds } if(measure.RangeMilliMeter > 51){ Serial.println("Bye"); digitalWrite(RELAY_PIN, HIGH); // digitalWrite(14, LOW); Serial.println("Switched Off"); mp3.reset(); // Play "hello.mp3". You must hear "Hello World" delay(3000); // wait 3 seconds } } else { Serial.println(" out of range "); digitalWrite(RELAY_PIN, HIGH); } delay(100); }