HELLO THERE!!!!
How are you guys doing lately? I hope everyone is fine always. This week, I have been tinkering around with my motion sensor and I am going to share a simple experiment about it with you guys. The objective of this experiment is to use the motion sensor to turn on and off an LED. When, there is a motion detected, the LED turns on and vice versa. Let's start with the items needed:
HARDWARE:
1. ARDUINO UNO
Simple right? Now, let's go to the coding part of this experiment. The code basically digital read the motion sensor values and turns on LED on and off based on the values. The code is shown below:
const int ledPin= 13;//led pin
const int inputPin= 2;//motionsensor pin
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);//input and output pin declaration
}
void loop(){
int value= digitalRead(inputPin);//read the motion sensor pin
digitalWrite(ledPin, LOW);//led off originally*optional*
if (value == HIGH)// if motion sensor high
{
Serial.println("HIGH");
digitalWrite(ledPin, HIGH);//led turn on
//better put delay here: delay(1000);
}
if (value == LOW)
{
Serial.println("LOW");
digitalWrite(ledPin, LOW);
}
}
Upload the code to the arduino and test it!!! You might want to adjust the time delay and sensitivity to obtain some different results. Anyways, have fun tinkering, See you guys next week!!!!
How are you guys doing lately? I hope everyone is fine always. This week, I have been tinkering around with my motion sensor and I am going to share a simple experiment about it with you guys. The objective of this experiment is to use the motion sensor to turn on and off an LED. When, there is a motion detected, the LED turns on and vice versa. Let's start with the items needed:
HARDWARE:
1. ARDUINO UNO
2.A LED
3.PIR Motion Sensor
SOFTWARE:
1.Arduino IDE
Ok, Now that the items are obtained, let's see on how to assemble the circuit. The assembly of the circuit is fairly simple. The connection from motion sensor to Arduino is shown in the image below:
Connection from motion sensor to Arduino
The full complete assembly of the circuit is shown below:
|
The assembly of the circuit |
const int ledPin= 13;//led pin
const int inputPin= 2;//motionsensor pin
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);//input and output pin declaration
}
void loop(){
int value= digitalRead(inputPin);//read the motion sensor pin
digitalWrite(ledPin, LOW);//led off originally*optional*
if (value == HIGH)// if motion sensor high
{
Serial.println("HIGH");
digitalWrite(ledPin, HIGH);//led turn on
//better put delay here: delay(1000);
}
if (value == LOW)
{
Serial.println("LOW");
digitalWrite(ledPin, LOW);
}
}
Upload the code to the arduino and test it!!! You might want to adjust the time delay and sensitivity to obtain some different results. Anyways, have fun tinkering, See you guys next week!!!!
Comments
Post a Comment