0% found this document useful (0 votes)
42 views3 pages

Arduino LED and Buzzer Control Code

The document describes an Arduino sketch that uses an LED and buzzer. It defines LED and buzzer pins, sets them to output in setup, and blinks the LED and beeps the buzzer 10 times in a loop if the light level read by a sensor is below 970, otherwise it turns them off.

Uploaded by

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

Arduino LED and Buzzer Control Code

The document describes an Arduino sketch that uses an LED and buzzer. It defines LED and buzzer pins, sets them to output in setup, and blinks the LED and beeps the buzzer 10 times in a loop if the light level read by a sensor is below 970, otherwise it turns them off.

Uploaded by

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

int led = 2;

void setup()

pinMode(led,OUTPUT);

void loop()

digitalWrite(led,1);

int led = 2;

int buzzer = 3;

void setup()

pinMode(led,OUTPUT);

pinMode(buzzer,OUTPUT);

void loop()

digitalWrite(led,1);

tone(buzzer,0);

}
int hasilSensorLDR; // Variable untuk sensor LDR

void setup() {

Serial.begin(9600); // Serial Monitor

pinMode(2,OUTPUT); // Set pin 6 sebagai Output

pinMode(3,OUTPUT); // Set pin 9 sebagai Output

void loop() {

int bunyi = 1;

// LED merah

Serial.println(hasilSensorLDR); // Print hasil LDR ke Serial Monitor

hasilSensorLDR=analogRead(0); // Hasil LDR = Hasil input pada pin A0

if (hasilSensorLDR <=970 ) // Jika hasil LDR kurang dari 970 (Kurang Cahaya)

while (bunyi <= 10)


{

digitalWrite(2,HIGH); // Aktifkan LED

delay(200);

digitalWrite(3,HIGH); // Aktifkan BUZZER

delay(200);

digitalWrite(2,LOW);

delay(100);

digitalWrite(3,LOW);

delay(100);

bunyi++;

else

digitalWrite(2,LOW); // Jika tidak, LED

digitalWrite(3,LOW); // Jika tidak, Matikan BUZZER

You might also like