X
Home > Blog > HOW to Make an Automatic Lighting System with Kidspico

HOW to Make an Automatic Lighting System with Kidspico

By r September 27th, 2024 86 views
Herein, we combine the photoresistor and LED module to design an automatic lighting system.

Flow

4201

Assembly

line1

Required:

42_00

line1

Step 1

42_01

line1

Step 2

42_02

line1

Step 3

42_03

line1

Step 4

42_04

line1

Step 5

42_05

line1

Step 6

42_06

line1

Step 7

42_07

line1

Step 8

42_08

line1

Step 9

42_09

line1

Completed!

42_10

line1

Wiring Diagram

4202

Test Code

Open 4.2Automatic_lighting.py and click 1407.

'''
 * Filename    : Automatic_lighting
 * Thonny      : Thonny 4.1.4
 * Auther      : http//www.keyestudio.com
'''
from machine import Pin,ADC
import time

led = Pin(11,Pin.OUT)
Photores = ADC(27)  

while True:
    Photores_Value = Photores.read_u16()
    print('ADC Value:',Photores_Value)
    if (Photores_Value < 10000):
        led.on()
    else:
        led.off()
    time.sleep(0.1)

Explanation

5top

Conceive:

  1. Initialization: set the pins of LED module and the photoresistor.

  2. Loop:

    ① read the value of photoresistor and print it on Shell.

    ② Determine whether the value id less than 10000(the threshold can be changed according to needs).

    • If the value is less than 10000, LED will be on.

    • If the value equals or is greater than 10000, LED will go off.

5bottom

Test Result
4top
Upload code and the photoresistor starts to detect the ambient light intensity.
In room, when the light is sufficient (the value is greater than 10000), the LED is off.
When the ambient light is weak (the value is less than 10000), the LED is on.
In the code, the threshold value 10000 can be modified according to your needs.
4203
4bottom
HOW to Make an Automatic Lighting System with Kidspico
Previous
HOW to Make an Automatic Lighting System with Kidspico
Read More
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Next
Comprehension! HOW to Monitor Smart Home Environment with ESP32
Read More
Message Us