icon

Automatic air purifier using UNIHIKER

To keep the air inside my room clean, I use an air purifier at thrust mode but in thrust mode it makes a lot of noise which is no issue for me during the day because I wear my headphones all day. But when it comes to sleep I want my surrounding to be as silent as possible and the button for air purifier is away for me or  I am lazy enough not to shut it down manually😁.But I do turn off my room lights before going to bed. So, I decided to use UNIHIKER to automate the switching of air purifier in my room. During the day time, it will turn ON the air purifier and when it's night it will turn it OFF. Easy peezy. Let's see how I made it.

STEP 1
Required Hardware
HARDWARE LIST
1 UNIHIKER Board
1 Relay module
STEP 2
Connection diagram

There are four 3-pin gravity connector on the board and you can use any of them and I'm using the one marked as below or pin number 21 ( see the number written next to the gravity connector that's the pin number you will use while writing the code). Use the provided gravity wire in the box to connect a relay module on this pin.

STEP 3
Coding Time

The code for this project is very simple. I'm just reading the values from in-built Ambient light sensor and then analyzing it and turn it on if light intensity is higher than or equal to the threshold (a value which we use to compare) and turn it off if it is lower than the threshold.

CODE
# -*- coding: UTF-8 -*-
import time
from pinpong.board import *
from pinpong.extension.unihiker import *
from pinpong.board import Board, Pin

Board().begin()  # Initialize the UNIHIKER
led = Pin(Pin.P21, Pin.OUT)  # Initialize the pin as an output pin
Threshold= 15   # change this as per your need

while True:
    light_value = light.read()  # Read the ambient light intensity
    print("Ambient light intensity: %d" % (light_value))  # Print the ambient light intensity to the terminal
    time.sleep(5)  # Wait for 5 seconds to maintain the state and avoid the reading due to noise
    
    # This if block checks whether the light_value is actually lower than threshold or it's due to noise
    if light_value <=Threshold: 
        time.sleep(10)
        if light_value <=Threshold:
            led.write_digital(1)
    else:
        led.write_digital(0)
STEP 4
Working and explanation

1. UNIHIKER Boots up

2. Program runs automatically (because auto boot is turned on )

3. When program runs, it checks whether the light_value is less than threshold or not and here it is greater than threshold as a result relay as well as Air purifier turns on

4. I turned off the lights, UNIHIKER knows that the light_value is dropped below the threshold and it waits for 10 seconds and check again whether it's still below the threshold or not and in this case it's still less than threshold. As, a result relay and air purifier turned off. If you notice the readings on the screen carefully, last two readings are below 15 (which is my threshold value)

STEP 5
Get your 3D printable UNIHIKER case for FREE!!
License
All Rights
Reserved
licensBg
0