Hi everyone,
I am vigneshraja. here I presented the code for interfacing arduino UNO with IR Obstacle Sensor like shown in above video.
I am vigneshraja. here I presented the code for interfacing arduino UNO with IR Obstacle Sensor like shown in above video.
Code:
const int sensorPin = 2;
const int ledPin = 13;
int sensorState = 0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
}
void loop() {
sensorState = digitalRead(sensorPin);
Serial.println(sensorState);
if (sensorState == HIGH) {
// turn LED on:
digitalWrite(ledPin, LOW);
} else {
// turn LED off:
digitalWrite(ledPin, HIGH);
}
}
Thank you for reading
Comments
Post a Comment