Light switching at the motion detection.
For this we’ll need additionally a relay module and a lamp (220 V).
1. A 12VDC or 05VDC relay is more often used. The numbers denote the constant voltage needed to be applied to the relay input.
2. Let’s examine the work of the widely used Arduino relay SRD-05VDC by Songle.
3. When power is applied to the Vcc pin and the ground pin is made dead, the green LED lights up.
4. Since we have a single-channel module, there’s only one signal pin In1. If the LOW voltage level is set on the In1, the red LED lights up on the relay module, and the relay clicks. On Arduino the digitalWrite (pin, LOW) command is responsible for the voltage level setting on the pin; the digitalWrite (pin, HIGH) command is used to return the relay to its previous state.
5. Let’s connect the relay module to the SB 4.0 board with the activated motion sensor.
5.1. Let’s connect the signal In1 pin of the relay module to the power pin of the external load.
5.2. In the Arduino Nano program code we find:
***********************************
// operation with the motion sensor – if motion is detected we record the fact for the time period timeout_SnSM
if (var_Tlm_SnSM == 1) { time_Move_detect = millis(); }
if (millis() — time_Move_detect < timeout_Move_detect) { Move_detect = 1; } else { Move_detect = 0; }
***********************************
We’ll add below those lines:
***********************************
if (Move_detect == 0) { _SetP(Cmd_LD1A_OFF, 1); var_Cmd_LD1A_OFF = 1; } else { _SetP(Cmd_LD1A_OFF, 0); var_Cmd_LD1A_OFF = 0; } //at motion detection we turn on the external load power supply (for the time period timeout_SnSM)
***********************************
6.3. We load a new firmware and turn on the SelfieBot.
Due to our algorithm, the LOW level is set on the power pin of the external load when motion is detected; the relay closes the circuit, and the lamp lights up.
Thus, when a person gets into the motion sensor coverage zone, the lamp lights up.