Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Seeed
Published © GPL3+

Infrared sensing automatic fan

Use Pico and Grove make an auto-sensing fan, when you wave your hand you can control the servo and the fan to turn at the same time.

BeginnerFull instructions provided30 minutes1,393

Things used in this project

Hardware components

Raspberry Pi Pico
Raspberry Pi Pico
×1
Seeed Studio Grove Shield for Pi Pico
×1
Seeed Studio Grove Servo
×1
Grove - Mini Fan v1.1
Seeed Studio Grove - Mini Fan v1.1
×1
Grove - mini PIR motion sensor
Seeed Studio Grove - mini PIR motion sensor
×1

Software apps and online services

Thonny

Story

Read more

Code

code

MicroPython
from machine import Pin,ADC,PWM
from time import sleep
import utime
 
miniFun = Pin(16, Pin.OUT)  
miniPir = Pin(18, Pin.IN)  
 
pwm_Servo=PWM(Pin(27))
pwm_Servo.freq(500)
Servo_Val =0  
 
while True:
 
    if  miniPir.value() == 1 :
        miniFun.value(1)
 
        while  Servo_Val<65535:
            Servo_Val=Servo_Val+50
            utime.sleep_ms(1)
            pwm_Servo.duty_u16(Servo_Val)
        while Servo_Val>0: 
            Servo_Val=Servo_Val-50
            utime.sleep_ms(1)
            pwm_Servo.duty_u16(Servo_Val)
 
    else :
        miniFun.value(0)
 
        pwm_Servo.duty_u16(0)    

Credits

Seeed

Seeed

102 projects • 169 followers
Seeed R&D Team

Comments