IoT Workshop Handout Programs
IoT Workshop Handout Programs
Pin Diagram:
Code:
int led = 9; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by
Pin Diagram:
// defines variables
long duration; // variable for the duration of sound wave
travel
int distance; // variable for the distance measurement
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an OUTPUT
pinMode(echoPin, INPUT); // Sets the echoPin as an INPUT
Serial.begin(9600); // // Serial Communication is starting
with 9600 of baudrate speed
Serial.println("Ultrasonic Sensor HC-SR04 Test"); // print
some text in Serial Monitor
Serial.println("with Arduino UNO R3");
}
void loop() {
// Clears the trigPin condition
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in
microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // Speed of sound wave
divided by 2 (go and back)
// Displays the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
}
Pin Diagram:
Pin Diagram:
Before you can use the DHT11 on the Arduino, you’ll need to install the DHTLib
library. It has all the functions needed to get the humidity and temperature
readings from the sensor. It’s easy to install, just download the DHTLib.zip file
below and open up the Arduino IDE. Then go to Sketch>Include Library>Add .ZIP
Library and select the DHTLib.zip file.
Library Link: https://www.circuitbasics.com/how-to-set-up-the-dht11-
humidity-sensor-on-an-arduino/
lockLow = true;
Serial.print("motion ended at ");
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
Pin Diagram:
void loop() {
val = digitalRead(8);
if(val == LOW)
{
digitalWrite(13,LOW); //if soil moisture sensor provides LOW
value send LOW value to relay
}
else
{
digitalWrite(13,HIGH); //if soil moisture sensor provides
HIGH value send HIGH value to relay
}
delay(400);
}
Pin Diagram: