Fis Lab Exam
Fis Lab Exam
Fis Lab Exam
Code:-
Pins : D0 : 0
AO : 2
int gasSensor = A0; // Assuming the gas sensor is connected to
analog pin A0
int threshold_LED = 2;
void setup()
{
pinMode(gasSensor, INPUT);
pinMode(threshold_LED, OUTPUT);
digitalWrite(threshold_LED, HIGH);
Serial.begin(9600);
}
void loop()
{
int gasIn = analogRead(gasSensor);
Serial.print("gas= ");
Serial.println(gasIn);
delay(1000);
}
PUSH BUTTON:-
CODE:-
const int ledpin =13;
const int buttonpin=2;
int buttonstate=0;
void setup()
{
Serial.begin(9600);
pinMode(ledpin,OUTPUT);
pinMode(buttonpin,INPUT);
}
void loop ()
{
buttonstate=digitalRead(buttonpin);
if ( buttonstate==HIGH){
digitalWrite(ledpin, HIGH);
Serial.println("led is on");
delay(1000);
}
else
digitalWrite(ledpin,LOW);
Serial.println("led is off");
delay(1000);
}
POTENTIOMETER:-
CODE:-
#define LED_PIN 11
#define POTENTIOMETER_PIN A0
void setup()
{
pinMode(LED_PIN, OUTPUT);
}
void loop()
{
int potentiometerValue = analogRead(POTENTIOMETER_PIN);
int brightness = potentiometerValue / 4;
analogWrite(LED_PIN, brightness);
}
TEMPERATURE SENSOR:-
CODE:-
#define sensorPin A0
void setup() {
Serial.begin(9600);
}
void loop() {
int reading = analogRead(sensorPin);
float voltage = reading * (5000 / 1024.0);
float temperature = voltage / 10;
float f=1.8*temperature+32;
Serial.println("temperature in fahernheit");
Serial.println(f);
delay(1000);
}
CODE:-
void setup()
{
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
}
void loop()
{
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(13, LOW);
delay(1000);
digitalWrite(12, HIGH);
delay(1000);
digitalWrite(12, LOW);
delay(1000);
digitalWrite(11, HIGH);
delay(1000);
digitalWrite(11, LOW);
delay(1000);
}
PIR
Ultrasonic sensor
#define echoPin 2
#define trigPin 3
long duration;
int distance;
void setup()
{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
Serial.println("Distance measurement using Arduino Uno.");
delay(500);
}
void loop()
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite( trigPin,HIGH); // turn on the Trigger to generate
pulse
delayMicroseconds(10);
digitalWrite(trigPin,LOW);
// If pulse reached the receiver echoPin
// become high Then pulseIn() returns the
// time taken by the pulse to reach the
// receiver
duration = pulseIn(echoPin, HIGH);
distance = duration * 0.0344 / 2;
Serial.print("Distance: ");
Serial.print( distance); // Print the output in serial monitor
Serial.println(" cm");
delay(100);
}
IR SENSOR
OUT =2
void setup() {
pinMode(irSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
int sensorValue = digitalRead(irSensorPin);
if (sensorValue == LOW) {
Serial.println("IR Sensor activated!");
digitalWrite(ledPin, HIGH); // Turn on the LED
// You can add additional actions here when
the sensor is activated
} else {
digitalWrite(ledPin, LOW); // Turn off the LED
}