0% found this document useful (0 votes)
13 views4 pages

Infrared Arduino Prk4

The document contains code for two infrared sensor projects using Arduino. The first project detects obstacles and prints messages to the serial monitor based on sensor readings. The second project controls LED indicators based on the sensor's status while also providing obstacle detection feedback.

Uploaded by

sandya.43123120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

Infrared Arduino Prk4

The document contains code for two infrared sensor projects using Arduino. The first project detects obstacles and prints messages to the serial monitor based on sensor readings. The second project controls LED indicators based on the sensor's status while also providing obstacle detection feedback.

Uploaded by

sandya.43123120
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Infrared

Rangkaian 1

Code program:

const int InfraRedSensor = 8;

void setup()
{
Serial.begin(9600);
pinMode(InfraRedSensor,INPUT);
}

void loop()
{
int hasil = digitalRead(InfraRedSensor);
if(hasil == LOW)
{
Serial.println("Ada Halangan");
}
if(hasil == HIGH)
{
Serial.println("Aman, Tidak Ada Halangan");
}
delay(250);
}
Hasil proyek1

Rangkaian2

Code program

const int InfraRedSensor = 4;


const int LedGreen = 12;
const int LedRed = 11;
void setup()
{
Serial.begin(9600);
pinMode(InfraRedSensor,INPUT);
pinMode(LedGreen,OUTPUT);
pinMode(LedRed,OUTPUT);

void loop()
{
int dataSensor = digitalRead(InfraRedSensor);
if (dataSensor == HIGH)
{
digitalWrite(LedGreen,LOW);
digitalWrite(LedRed,HIGH);

}
else
{
digitalWrite(LedGreen,HIGH);
digitalWrite(LedRed,LOW);

}
{
int dataSensor = digitalRead(InfraRedSensor);
if(dataSensor == LOW)
{
Serial.println("Ada Halangan");
}
if(dataSensor == HIGH)
{
Serial.println("Aman, Tidak Ada Halangan");
}
delay(500);
}
}

You might also like