0% found this document useful (0 votes)
8 views5 pages

Uno HPL

Uploaded by

hokohad413
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)
8 views5 pages

Uno HPL

Uploaded by

hokohad413
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
You are on page 1/ 5

Ir sensor

const int IR_sensor = 7;


const int LED_pin = 13;

void setup() {
Serial.begin(9600);
pinMode(IR_sensor, INPUT);
pinMode(LED_pin, OUTPUT);
}

void loop() {
int sensorValue = digitalRead(IR_sensor);

if (sensorValue == HIGH) {
Serial.println("Motion Detected");
digitalWrite(LED_pin, HIGH);
} else {
Serial.println("No Motion");
digitalWrite(LED_pin, LOW);
}

delay(500);
}

LM 35 Temperature sensor
const int tempPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(tempPin);
float voltage = sensorValue * (5.0 / 1023.0);
float temperatureC = voltage * 100;

Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C");

delay(1000);
}
Ultrasonic sensor 28015
const int pingPin = 7;

void setup() {
Serial.begin(9600);
}

void loop() {
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
long duration = pulseIn(pingPin, HIGH);

float distance = duration / 29 / 2;

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(500);
}
HC-SR04 Ultrasonic Sensor

const int trigPin = 9;


const int echoPin = 10;
long duration;
float distance;

void setup() {
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);


distance = (duration * 0.034) / 2;

Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(500);
}
Light Dependent Resistor (LDR)
const int LDRPin = A0;

void setup() {
Serial.begin(9600);
}

void loop() {
int sensorValue = analogRead(LDRPin);
float voltage = sensorValue * (5.0 / 1023.0);

Serial.print("Light Intensity: ");


Serial.print(sensorValue);
Serial.print(" (Raw Value) | ");
Serial.print(voltage);
Serial.println(" V");

delay(1000);
}

Controlling LED with input switch


const int LEDPin = 8;
const int buttonPin = 7;
int buttonState = 0;

void setup() {
pinMode(LEDPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}

void loop() {
buttonState = digitalRead(buttonPin);

if (buttonState == LOW) {
digitalWrite(LEDPin, HIGH);
} else { // If button is not pressed
digitalWrite(LEDPin, LOW);
}
}
Servo motor
#include <Servo.h>

Servo myServo;

void setup() {
myServo.attach(9);
}

void loop() {
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos);
delay(15);
}
for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos);
delay(15);
}
}

LCD interfacing
#include <LiquidCrystal.h>

// Initialize the library with the numbers of the interface pins


LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
lcd.begin(16, 2); // Set up the LCD's number of columns and rows
lcd.print("Hello, world!"); // Print a message to the LCD
}

void loop() {
// Nothing here
}

You might also like