Module 4
Module 4
LM35
TMP36
//name variables
int switch = 9;
void setup()
Serial.begin(9600)
void loop()
serial.println("Temperature")
serial.print(voltage)
Serial.print(tempC);
if (tempC > 28)
digitalWrite(9, HIGH)
else
digitalWrite(9, LOW)
suppose if the temperature goes high (above 28 degree C) then switch on the AC.
Ultrasonic sensor
Task - Find the distance of any obstacle and print the distance in the serial monitor
HC-SR04
Pulse - HIGH/LOW
int trgpin = 8;
int echopin = 9;
void setup()
pinMode(trgpin, OUTPUT);
pinMode(echopin, INPUT);
Serial.begin(9600);
void loop()
digitalWrite(trgpin, LOW);
delay(25);
digitalWrite(trgpin, High);
delay(25);
digitalWrite(trgpin, LOW);
serial.print(distance)
Echo <-
Calculate the distance of the obstacle, if the distance is < 80cm produce a beep sound
DHT Sensors - DHT11/DHT22
Task - Read the humidity value and print in the serial monitor
#include <dht.h>
DHT22 dht(A0);
void setup()
Serial.begin(9600);
Serial.println("DHT activated")
dht.begin();
void loop()
val = dht.readHumidity();
valt = dht.readTemperature();
Serial.println("Humidity:")
Serial.print(val);
delay(3000);
Serial.println("Temperature:")
Serial.print(valt);
delay(3000);
Output
mechanical
coverting to a motion
#include <Servo.h>
int servopin = 12
Servo ser1;
void setup()
ser1.attach(servopin)
void loop()
ser1.write(0);
delay(1000);
ser1.write(90);
delay(1000);
ser1.write(180);
delay(1000);
potentionmeter = value based on that you are mapping to the servo motor and based on that you
are making an LED to glow.
#include <Servo.h>
int servopin = 12
Servo ser1;
int led = 6;
void setup()
ser1.attach(servopin)
pinMode(6, OUTPUT);
}
Void loop()
ser1.write(val);
if (val == 0)
digitalWrite(led, LOW);
if(val == 180)
digitalWrite(led, HIGH);
0 to 5V -> 0 to 1023