더 재밌게 놀기 연구소
※ Motion Seosor (HC-SR501)
Data sheet :
Motion sensor will work without Arduino
When the sensor detects motion, the output pin will go "high"
* Using Arduino
Circuit
Source Code
//www.elegoo.com
//2016.06.13
/*
* PIR sensor tester
*/
int ledPin = 13; // choose the pin for the LED
int inputPin = 7; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
Result
※ Water Level Sensor
Circuit
Source Code
//www.elegoo.com
//2016.06.13
int adc_id = 0;
int HistoryValue = 0;
char printBuffer[128];
void setup()
{
Serial.begin(9600);
}
void loop()
{
int value = analogRead(adc_id); // get adc value
if(((HistoryValue>=value) && ((HistoryValue - value) > 10)) || ((HistoryValue<value) && ((value - HistoryValue) > 10)))
{
sprintf(printBuffer,"ADC%d level is %d\n",adc_id, value);
Serial.print(printBuffer);
HistoryValue = value;
}
}
Result
'IoT > Arduino' 카테고리의 다른 글
[Arduino Project 2] LED Light stand for 3D Crystal laser cube Ver. 0.4 (0) | 2017.05.08 |
---|---|
[I don't like you] practice project for the project 'I like you' (0) | 2017.05.07 |
MIT App Inventor - Android App - Mega Millions Jackpot number generator (0) | 2017.01.30 |
Updated Source Code - Automated Mung Bean Sprouts Growing Machine (0) | 2017.01.27 |
Arduino Project 1 - Automated Mung Bean Sprouts Growing Machine (0) | 2017.01.23 |
[Arduino] Joystick, LED Dot Matrix and ADXL335 Module (0) | 2017.01.17 |
[Arduino] Ultrasonic, Keypad and Temperature and Humidity Sensor (0) | 2017.01.15 |
[Arduino] 7 Segment, Servo, LCD and Thermometer (0) | 2017.01.14 |
[Arduino] Using 74HC595 8-bit serial-in/serial or parallel-out shift register (0) | 2017.01.12 |
[Arduino] Library and RGB LED (0) | 2017.01.11 |