Smart Lights
Smart Lights
Smart Lights
1. Introduction
1.1 What am I learning here and why?
One of the most important pillars of the smart home is saving energy. This reason is mentioned time
and again when it comes to why people opt for smart home technologies. After all, saving energy not
only has an ecological advantage, but above all a cost advantage.
Intelligent lights ensure that they are only switched on when a person is in the room
Intelligent heating ensures that the heating is lowered at a certain time
A smart washing machine can be installed in a way that it washes your clothes at the time
it is the cheapest to do so
In this tutorial we will focus on smart lighting and show how you can implement it in your
SmartHome4Seniors house model.
As in the other advanced tutorials you need to have downloaded the Thonny programming
environment on your device. Also, you need to have installed the firmware of MicroPython on your
Raspberry Pi Pico. The extended modifications (see p 42 in manual) including the extra components
and their connectivity must also be made on the breadboard.
Electrical Hardware
• 1x Raspberry Pi Pico
• 1x Full size breadboard
• 1x Micro-USB cable
• 14x male-to-male jumper wires
• 4x LEDs (any colours)
• 1x PIR motion sensor
• 1x Potentiometer
• 1x 220 Ohm resistor
• 1x LDR photoresistor
Components of SmartHome4Seniors house model
2x Bolts
2x Nuts
Ability
As regards physical skills you should be able to count off holes on the breadboard, check and apply
the connections and insert components to it.
2 Learning content
2.3 Theoretical background
To understand the content of this tutorial well, you will now get an introduction to the most
important terms and contexts.
Definitions
- A PIR motion sensor have a so-called PIR sensor (passive infrared sensor) and uses thermal
radiation of living beings for detection. As a result, they detect even the smallest movements.
(source: Hager Vertriebsgesellschaft mbH & Co. KG: Bewegungs- und Präsenzmelder. Die
Helfer im Dunkeln. Online available at: https://hager.com/de/wissen/e-volution/fachwissen-
elektrotechnik/bewegungs--und-praesenzmelder (called at 19 Nov 2023))
- With the help of a potentiometer you can specify several settings. For example, how long the
light should stay on when a person is detected or that the light should only come on at a
certain ambient brightness (i.e. at night).
At least three installation steps are required for installing and controlling an LED with a PIR motion
sensor. These are:
In our case we also will set up a photoresistor. It will add some functionality of detecting light in order
to control the LEDs.
The installations shown include connecting the electronic materials in the house model and writing
the program. The steps come with instructional videos showing how it should be executed. If you are
not sure about the components used in this tutorial, please advise the SmartHome Kit Manual (link).
NOTE: Since the experiments involved are all circuit experiments, a wrong connection or short circuit
may damage your RaspberryPi Pico development board. Please, always check the circuit again before
connecting the power supply.
LED
The second LED light (green) needs to be inserted in the right-side piece in the mounting hole and
friction will keep it in place.
LED
The third LED (yellow) needs to be mounted in the front-side of the house model. Insert the LED in
the mounting hole and friction will keep it in place. The fourth red LED is serving as status indicator
(Light outside on or off) and stays connected directly to the breadboard. Also the photoresistor stays
connected to the breadboard.
LED
To insert it in the SmartHome4Seniors house model you two bolt and two nuts. Mount the sensor
through the top left and bottom right mounting holes.
PIR Motion
sensor
2.2.2 Connect the electronics
Connect the cables as described and shown in the diagram.
LEDs
– connect the resistors to GPIO10 (red), GPIO11 (blue), GPIO12 (yellow), GPIO13 (green)
– connect the shorter end (-) of the LEDs to the GND(-) rail
Potentiometer
– connect the black cable to the GND rail (-)
Photoresistor
– connect the right leg of the photoresistor to a 220 Ohm resistor
– connect the other side of the resistor to the GND rail (-)
– connect the right leg of the photoresistor to the GPIO26 ADC pin
Open Thonny from your device. Then go to File -> Save as…, choose Raspberry Pi Pico, and save your
file under the name lighting.py.
led_1.freq(1000)
led_2.freq(1000)
led_3.freq(1000)
led_4.freq(1000)
led_1.duty_u16(MIN)
led_2.duty_u16(MIN)
led_3.duty_u16(MIN)
led_4.duty_u16(MIN)
sleep(5)
while True:
POT_value = POT.read_u16()
#print(POT_value)
led_1.duty_u16(POT_value)
led_2.duty_u16(POT_value)
led_3.duty_u16(POT_value)
led_4.duty_u16(POT_value)
sleep(0.1)
if PIR.value():
led_1.duty_u16(MAX)
led_2.duty_u16(MAX)
led_3.duty_u16(MAX)
led_4.duty_u16(MAX)
sleep(3)
LDR_value = LDR.read_u16()
print (LDR_value)
if LDR_value > LDR_THRESHOLD:
led_1.duty_u16(MAX)
led_2.duty_u16(MAX)
led_3.duty_u16(MAX)
led_4.duty_u16(MAX)
sleep(0.1)
The code initializes the pins and creates objects for the components such as the PIR sensor, the LEDs
and the LDR photoresistor. Some global variables for the PWM (pulse width modulation) are also set.
More concrete, it checks if the PIR sensor detects a movement (the PIR value is TRUE). If it is, the
brightness of the LEDs is set to the maximum (MAX) and then pauses for 3 seconds.
The "while True" loop is executed and reads the value of the POT potentiometer. This value is used to
set the brightness of the LEDs via the "duty_u16()" method of the PWM objects. The "sleep()"
method is used to insert a short pause.
It then reads the value of the LDR sensor (LDR_value) and prints it. If the LDR value is higher than the
LDR_THRESHOLD, the brightness of the LEDs is set to maximum again and there is a short pause for
0.1 seconds.
Save the program by clicking the Save icon on the top left-hand side, or by pressing Ctrl+S on your
keyboard.
Thonny will ask you where you want your program to be saved. Choose the Raspberry Pi Pico. Save the
file as lighting.py and click OK. You always need to add the .py extension so that Thonny recognises the
file as a Python file.
2.2.4 Application
Now that you have connected everything in a sufficiently bright room with the potentiometer turned
all the way to the left, you should see the LEDs blinking. The Potentiometer controls the base
brightness, so if you start turning it to the right, the blinking should become less visible and turn into a
more constant bright shining – you are dimming the light
If the room is dark (or something covers the photoresistor) the blinking stops and only the base
brightness controlled by the potentiometer is used. However, it at any time, motion is detected by the
Motion sensor, the LEDs are being turned to full brightness for a short amount of time.
3 Summary
In this tutorial you have learned one option how to control your lightning using the method of motion
detection. The setup of this scenario included the installation of foure sensors, namely:
LED lights
PIR motion sensor
Potentiometer to define the duration of lighting
Photoresistor
4 Self-Assessment
1. A PIR motion sensor uses the thermal radiation of living beings for detection. (TRUE)
2. With the help of intelligent lightning you can
a. Save energy (true)
b. Contribute to the climate (true)
c. Monitor power consumption (false)
5 References
Hager Vertriebsgesellschaft mbH & Co. KG: Bewegungs- und Präsenzmelder. Die Helfer im Dunkeln.
Online available at: https://hager.com/de/wissen/e-volution/fachwissen-elektrotechnik/bewegungs--
und-praesenzmelder (called at 19 Nov 2023)