Smart Corridor Light | IoT Cloud Kit for microbit-MakeCode-Tutorial

0 1364 Medium

Lesson 8. Smart Corridor Light

Objectives

1. Understand the principle of light sensor

2. Get to know the sound sensor

3. Learn to use if...else if...else....

4. Use formulas to calculate electricity consumption

Learning Process

Preparation

Teachers: A computer, good internet, IoT internet kits.

Students: A computer, good internet, IoT internet kits.

Contents

Introduction: Light source is a very important problem in corridors. In addition to the help of sunlight, we can also arrange lamps and lanterns to provide enough lights for corridors. And corridor light is a crucial point in architectural lighting systems. Usually, the corridor lamp in residential buildings and office buildings adopts sound and light control to realize the effect of lighting on when people come and turning off when people go, which saves energy and is convenient to use.

What Is a Light Sensor?

Light sensor, aka brightness sensor, exists on most modern tablets and cellphones. It automatically adjusts the screen brightness based on the current ambient brightness to achieve the optimal vision for the user. For example, when under a dark environment, the screen backlight will automatically darken to avoid dazzling. Light sensor is mostly used to control lights, such as Street lights, Corridor lights…etc. When used in corridors, it often combines with sound sensors to make sound & light-activated light.

Principles and Types of Light Sensors

Light sensor converts light signal into electric signal by using photosensitive elements. Its sensitive wavelength is near the wavelength of visible light, including infrared wavelength and ultraviolet wavelength. Linear light sensor is not only limited to the detection of light, but also can be used as detection elements to form other sensors to detect many non-electric quantities, as long as these non-electric elements are converted into changes in optical signals. Optical sensor is one of the most productive and widely used sensors. It plays a very important role in automatic control and non-electric measurement technology. There are many kinds of light sensors, such as phototube, photomultiplier tube, photoresistor, photosensitive triode, photocoupler, solar cell, infrared sensor, ultraviolet sensor, optical fiber photoelectric sensor, color sensor, CCD and CMOS image sensor.

We generally use photosensitive resistive sensors. Photoresistor is a kind of resistor made of photoelectric effect of semiconductor, whose resistance value varies with the intensity of incident light. The greater incidental light intensity, the less electric resistance. And when the incident light is weak, the electric resistance increases.

The "light sensor" on micro:bit

In this lesson, we use the "light sensor" of the micro:bit to build the project. The micro:bit itself does not have a light sensor fitted, but it can sense the surrounding light through its LED matrix. The technique for this relies on the fact that when an LED is reversed-biased, it can be filled with a small amount of charge. If you then let one of the pins for the LED act as an input and the other as low output, the charge on the LED will leak away until the digital input stops being High and becomes Low. The time taken for this to happen depends on the amount of light falling on the LED. The stronger the light, the larger the value.

Thinking: If you have a light sensor on your hand, try using it to collect light values in these three environments, and observe if there are any differences between it and the value collected by the micro:bit?

Project Practice—Smart Corridor Light

In daily life, if a corridor light is only controlled by sound, then here comes a problem: the light will be turned on as long as there is sound exceeding the threshold value regardless of the time of day or night, which is undesirable and non-eco-friendly. So the corridor light is often designed as “dual-controlled”, which integrates sound and light sensors to achieve that effect of lighting on only when it is dark and a sound is detected.

In this lesson, we will learn how to use the "light sensor" and analog sound sensor to make a smart corridor light. The tutorial mainly talks about detecting the ambient light intensity through the micro:bit LED dot matrix. If the light intensity is high, the light will not be turned on when a sound detected; if the light intensity is low, the light will be turned on when a sound detected, and increase the number of lighting on by 1 every time the corridor light is turned on, and then we can set the total number of lighting on to be sent to the ThingSpeak IoT platform at regular intervals, then we can conveniently analyze the power consumption of the corridor lights in a month or a year. The analysis method is shown in Task 2.

Task 1: Make corridor lights

Through learning, we all know that the corridor light will only turn on when the light is dark and when a sound is detected. So the picture below shows the working principle of corridor light:

Hardware Preparation

Prepare the hardware equipment as shown in the following diagram.

Hardware Connection

Insert a micro:bit V2 into a micro:IoT Board for Cloud.

Program Design

Function analysis

The function we need to achieve in this task is: when the value detected by the light sensor is less than 200 and the value detected by the sound sensor is greater than 150, the RGB light on the expansion board will be turned on for 3 seconds; otherwise, the RGB light will not be turned on.

Program Flowchart
Example program

Program website: https://makecode.microbit.org/_XsrUMRL9wHhH

Operating Effect

After the program is successfully burned, place the device in an appropriate environment (the light value is about 100), clap or blow into the microphone, and observe the change of the RGB light. When the light value is less than 200 and the sound value is greater than 150, the RGB light on the expansion board will be turned on for 3 seconds; if the conditions are not met, the RGB light will not be turned on. When the light value>200, no matter how loud the sound is, the RGB lights will not light up.

Conclusion

In this case, we used the light sensor and the sound sensor to restore the principle of the corridor light. After learning, we understand the characteristics of the light sensor: non-contact, fast response, and reliable performance. With the development of society, light sensors have been used in all aspects of life, such as the automatic adjustment of screen brightness on mobile phones; automatic flushing equipment in washrooms, and automatic operation of escalators.

Question: In addition to the above application scenarios, what else can you use a photosensitive sensor for?

Task 2:Get the number of times the light is turned on

In the last section, we have learned the working principle and production process of corridor lights. Then we will use the IoT platform to collect how many times this corridor light will be lit in a day/month. Calculate how much power is consumed in a day/month by the number of times of lighting. The working principle of the project is as follows:

Create Channel

First, we set up a "Intelligent Corridor Light" channel in ThingSpeak. Proceed as follows:

1. Click "Channels"->"New Channel"

2. Set the channel name as: Intelligent Corridor Light; channel description as: Intelligent Corridor Light; because we need to collect the frequency of the lighting up, you need to create two "Fields" to store the data, they are: Field1—The number of times the light turns on

3. Finally, pull the web page down to the bottom and click "Save Channel" to save the channel.

View Keys

Go to my channel "Intelligent Corridor Light" and click API Keys to view the key.

Hardware Preparation

You need to prepare the hardware devices as shown in the figure below.

Hardware Connection

Insert the micro:bit V2 and WIFI IoT SD into the corresponding positions of the micro:IoT Board for Cloud.

Program Design

Functional Analysis

The function we need to achieve in this task is: every time the RGB light turns on, we record the number of times the light turns on once. Then upload the recorded times to the ThingSpeak platform every once in a while.

Program Flowchart

In order to easily distinguish the role of each data, we need to create two variables, namely, "countdown" and "Number". Their roles are as follows:

Sample program

Program link: https://makecode.microbit.org/_K5wgF7XDWa1A

Operating Effect

Go to the https://thingspeak.com/ webpage, click to enter "My Channels", find the "Intelligent Corridor Light" channel, click to enter the channel to view the number of times the light is lit.

Note: According to the data collected by ThingSpeak, the maximum number of times of being lit up in a day is 20 times. If calculated according to this frequency, it may be lit 20×30=600 times a month.

Conclusion

1. In this case, we used the IoT platform to collect the frequency of lighting on. Based on these data, we can use the formula: W=Pt to calculate how much electric power this corridor light consumes in a month. W= work with a unit of Joules(J), P=Power with a unit of Watts(W), and t=time in seconds(s).

For example, the power of the bulb used in the corridor lamp is 50w. And the corridor light lights up for 10s when being activated. According to the data collected by the ThingSpeak IoT platform, last month, the corridor lights up 600 times. So the corridor light lit up for 600×10=6000 seconds last month and the power consumption of this 50w bulb in one month is W=Pt=50*6000=300000 (J).

2. Also we learned how to appropriately use if..., if...else..., if...else if...else.

Discussion

Summary

In this lesson, we learned how to use light sensor to corridor lamp. At the same time, we used the ThingSpeak IoT platform to help us record the number of times the corridor light turning on, so as to analyze how much electricity the corridor lights will consume in a period of time? For the next project, we are going to to use temperature sensors to help us analyze where mold is most likely to grow in our house.

License
All Rights
Reserved
licensBg
0