Devices & Components
Arduino Uno Rev3
Resistor 100 ohm
Linear Regulator (7805)
PIR Motion Sensor (generic)
Gravity: Analog LM35 Temperature Sensor For Arduino
Custom PCB
IRF 530 N
Axial Fan, 12 VDC
Hardware & Tools
Hot glue gun (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Soldering iron (generic)
Scissor, Electrician
Solder Wire, Lead Free
Project description
Code
Code
arduino
1#include <avr/io.h> 2 3//the time when the sensor outputs a low impulse 4long unsigned int lowIn; 5 6//the amount of milliseconds the sensor has to be low 7//before we assume all motion has stopped 8long unsigned int pause = 500; 9 10boolean lockLow = true; 11boolean takeLowTime; 12 13const int pSuhu = A0; //inisialisasi pin to control LM35 pin A0 14float suhu, outputlm, adc; //tipe data yang memungkinkan memuat angka desimal 15int pirPin = 12; //digital pin connected to the PIR's output 16int pirPos = 13; //connects to the PIR's 5V pin 17int kipas = 3; 18 19void setup(){ 20 Serial.begin(9600); //begins serial communication 21 pinMode(pirPin, INPUT); 22 pinMode(pirPos, OUTPUT); 23 pinMode(kipas,OUTPUT); 24 digitalWrite(pirPos, HIGH); 25 pinMode(pSuhu, INPUT); // set pSuhu(LM35) to be INPUT 26 27 while (digitalRead(pirPin) == HIGH) { 28 delay(500); 29 Serial.print("."); 30 } 31 Serial.println("SENSOR ACTIVE"); 32} 33void lm35(){ 34 adc = analogRead(pSuhu); //save nilai from LM35 to variabel nilaiLM35 35 suhu = adc / 2.0479; 36 outputlm=adc*4.883; 37 if (suhu >= 25) 38 { 39 analogWrite(kipas,50); 40 Serial.println("Kecepatan=50"); 41 } 42 if (suhu >= 30) 43 { 44 analogWrite(kipas,100); 45 Serial.println("Kecepatan=100"); 46 } 47 if (suhu >= 35) 48 { 49 analogWrite(kipas,150); 50 Serial.println("Kecepatan=150"); 51 } 52 if (suhu >= 40) 53 { 54 analogWrite(kipas,200); 55 Serial.println("Kecepatan=200"); 56 } 57 if (suhu >= 45) 58 { 59 analogWrite(kipas,255); 60 Serial.println("Kecepatan=255"); 61 } 62 } 63void loop(){ 64 if(digitalRead(pirPin) == HIGH){ //if the PIR output is HIGH, turn servo 65 lm35(); 66 if(lockLow){ 67 //makes sure we wait for a transition to LOW before further output is made 68 lockLow = false; 69 Serial.println("---"); 70 Serial.print("motion detected at "); 71 Serial.print(millis()/1000); 72 Serial.println(" sec"); 73 delay(50); 74 } 75 takeLowTime = true; 76 } 77 78 if(digitalRead(pirPin) == LOW){ 79 digitalWrite(kipas,LOW); 80 if(takeLowTime){ 81 lowIn = millis(); //save the time of the transition from HIGH to LOW 82 takeLowTime = false; //make sure this is only done at the start of a LOW phase 83 } 84 85 //if the sensor is low for more than the given pause, 86 //we can assume the motion has stopped 87 if(!lockLow && millis() - lowIn > pause){ 88 //makes sure this block of code is only executed again after 89 //a new motion sequence has been detected 90 lockLow = true; 91 Serial.print("motion ended at "); //output 92 Serial.print((millis() - pause)/1000); 93 Serial.println(" sec"); 94 delay(50); 95 } 96 } 97 delay(1000); 98 Serial.print(", Suhu: "); 99 Serial.print(suhu); 100 Serial.println(); //send data ASCII + CR,LF (kode enter) 101 delay(1000); 102 Serial.print(", ADC: "); 103 Serial.print(adc); 104 Serial.println(); //send data ASCII + CR,LF (kode enter) 105 delay(1000); 106} 107
Downloadable files
Automatic Fan with PIR Sensor and Arduino Sensor
Automatic Fan with PIR Sensor and Arduino Sensor
Automatic Fan with PIR Sensor and Arduino Sensor
Automatic Fan with PIR Sensor and Arduino Sensor
Documentation
Design with software Sketch Up
Design with software Sketch Up

Design with software Sketch Up
Design with software Sketch Up

Comments
Only logged in users can leave comments