PIR Sensor Input Testing:
LED On/Off depends on PIR sensor's analog input
int ultraSoundSignal = 2; int val = 0;
int ultrasoundValue = 0;
int timecount = 0; int ledPin = 13;
void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
}
void loop() {
timecount = 0;
val = 0;
pinMode(ultraSoundSignal, OUTPUT);
int ultrasoundValue = 0;
int timecount = 0; int ledPin = 13;
void setup() {
Serial.begin(9600); // Sets the baud rate to 9600
pinMode(ledPin, OUTPUT); // Sets the digital pin as output
}
void loop() {
timecount = 0;
val = 0;
pinMode(ultraSoundSignal, OUTPUT);
digitalWrite(ultraSoundSignal, LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignal, HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignal, LOW); // Holdoff
pinMode(ultraSoundSignal, INPUT); // Switch signalpin to input
val = digitalRead(ultraSoundSignal); // Append signal value to val
while(val == LOW) { // Loop until pin reads a high value
val = digitalRead(ultraSoundSignal);
}
while(val == HIGH) { // Loop until pin reads a low value
val = digitalRead(ultraSoundSignal);
timecount = timecount +1; // Count echo pulse time
}
ultrasoundValue = timecount; // Append echo pulse time to ultrasoundValue
if(timecount > 0){
digitalWrite(ledPin, HIGH);
}
delay(100);
}
No comments:
Post a Comment