Smart Lights

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Tutorial – 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.

There are multiple ways for saving energy:

 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.

1.2 Learning objectives


In this tutorial you will get to know one opportunity how to control your lightning using a motion
sensor combined with a potentiometer. The tutorial is based on the scenario that the presence of a
person is registered and the light turns on and off automatically based on predefined settings (i.e.
surrounding brightness).

After you have completed the tutorial you will

- be able to connect and control a LED light


- be able to connect and control the PIR motion sensor
- be able to set a potentiometer
- be able to set up a photoresistor

1.3 What do I need?


Software

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).

- A LDR Photoresistor (Light Dependent Resistor) photoresistor – also known as a photocell or


light sensor – is a type of resistor whose resistance changes based on the amount of light
incident on its surface. As the intensity of light increases, the resistance of the LDR decreases
and vice versa. This property makes LDRs useful for applications such as light control systems,
automatic street lights, burglar alarms, and cameras.
2.4 Step-by-step guide
Now let's move on to the implementation. To do this, take the SmartHome4Seniors house model or
just look at the instructions and recordings.

At least three installation steps are required for installing and controlling an LED with a PIR motion
sensor. These are:

1. Install and control of the LED lights


2. Install and control of the PIR motion sensor
3. Install and set the potentiometer

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.

2.2.1 Attach the components to the SmartHome4Seniors house model


1. Mount the LEDs
The first LED light needs to be mounted on the left-side piece of the SmartHome4Seniors house
model. Insert the LED to the mounting hole and friction will keep it in place.

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

2. PIR Motion Sensor

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 longer end (+) of the LED to 220Ohm resistors

– connect the resistors to GPIO10 (red), GPIO11 (blue), GPIO12 (yellow), GPIO13 (green)

– connect the shorter end (-) of the LEDs to the GND(-) rail

PIR Motion Sensor


– connect the red cable (VCC) to the 5V rail (+)

– connect the black cable (GND) to the GND rail (-)

– connect the yellow cable (OUT) to GPIO22 pin

Potentiometer
– connect the black cable to the GND rail (-)

– connect the orange cable to GPIO27 ADC pin

– connect the red cable to 3V3 power pin

– turn the potentiometer to the left so it’s off

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

– connect the left leg of the photoresistor to 3V3 (+) rail


2.2.3 Generate program code
Finally, we have to tell our Raspberry Pi, how to transform the information from the sensors into
action.

Open Thonny from your device. Then go to File -> Save as…, choose Raspberry Pi Pico, and save your
file under the name lighting.py.

Write the following code in the editor page of Thonny.


from machine import Pin, ADC, PWM
from time import sleep

#Define pins for each component


PIN_PIR = 22
PIN_LED_1 = 10
PIN_LED_2 = 11
PIN_LED_3 = 12
PIN_LED_4 = 13
PIN_LDR = 26
PIN_POT = 27

#Setup global variables for u16


MAX = 65535
MID = 32768
MIN = 0

#Setup PIR sensor


PIR = Pin(PIN_PIR, Pin.IN, Pin.PULL_UP)
#Setup LED lights
led_1 = PWM(Pin(PIN_LED_1))
led_2 = PWM(Pin(PIN_LED_2))
led_3 = PWM(Pin(PIN_LED_3))
led_4 = PWM(Pin(PIN_LED_4))

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)

#Setup LDR photoresistor


LDR = ADC(Pin(PIN_LDR))
LDR_MAX = 4000
LDR_MIN = 50
LDR_THRESHOLD = int((LDR_MAX + LDR_MIN)/2)

#Setup POT potentiometer


POT = ADC(Pin(PIN_POT))

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)

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy