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

PAUKM

The document contains code snippets for various sensors and a servo motor using Arduino. It includes implementations for a light sensor, sound sensor, temperature sensor, and a servo motor that moves between specified angles. Each section initializes the respective sensor or motor and continuously reads values or adjusts positions while printing the results to the Serial Monitor.

Uploaded by

2400014009
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)
19 views3 pages

PAUKM

The document contains code snippets for various sensors and a servo motor using Arduino. It includes implementations for a light sensor, sound sensor, temperature sensor, and a servo motor that moves between specified angles. Each section initializes the respective sensor or motor and continuously reads values or adjusts positions while printing the results to the Serial Monitor.

Uploaded by

2400014009
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
You are on page 1/ 3

Sensor cahaya

const int ldrPin = A0; //Pin anaqlog untuk LDR


const int ledPin = 7; // Pin digital untuk LED
const int threshold = 7; // Ambang batas untuk menyalakan LED

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
int ldrValue = analogRead(ldrPin);
Serial.println(ldrValue);

if (ldrValue < threshold) {


digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}

delay(1000);

sensor suara

const int pinSensor = A0;


int nilaiSuara;

void setup() {
Serial.begin(9600);
Serial.println("Mengukur Nilai Suara...");
}

void loop() {
nilaiSuara = analogRead(pinSensor);
Serial.println(nilaiSuara);
delay(100);
}
Sensor suhu

const int sensorsuhu= A0;


int temperatur;
float tegangankeluar;
float adc;

void setup() {
Serial.begin(9600);
pinMode(sensorsuhu, INPUT);
delay(100);
}

void loop(){
adc= analogRead(sensorsuhu);
tegangankeluar= adc/1023*5;
temperatur= tegangankeluar*100;
Serial.print("Suhu = ");
Serial.println(temperatur);
delay(500);
}

Motor servo

#include <Servo.h>

Servo myservo; // create Servo object to control a servo


// twelve Servo objects can be created on most boards

int pos = 30; // variable to store the servo position

void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the Servo object
}

void loop() {
for (pos = 30; pos <= 180; pos += 1) { // goes from 0 degrees to 180
degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(100); // waits 15 ms for the servo to
reach the position
}
for (pos = 180; pos >= 30; pos -= 1) { // goes from 180 degrees to 0
degrees
myservo.write(pos); // tell servo to go to position in
variable 'pos'
delay(100); // waits 15 ms for the servo to
reach the position
}
}

You might also like