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

Iot Lab Code

The document contains 3 programs for Arduino: 1) A program to blink an LED connected to the built-in LED pin by turning it on for 1 second then off for 1 second repeatedly. 2) A program to monitor temperature and humidity using a DHT11 sensor connected to analog pin A0 by reading values every 5 seconds and printing them to the serial monitor. 3) A program to control an RGB LED by setting the color (red, green, blue combinations) every 1 second using a function to set the analog values on each pin.

Uploaded by

Kaleeswari
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)
46 views5 pages

Iot Lab Code

The document contains 3 programs for Arduino: 1) A program to blink an LED connected to the built-in LED pin by turning it on for 1 second then off for 1 second repeatedly. 2) A program to monitor temperature and humidity using a DHT11 sensor connected to analog pin A0 by reading values every 5 seconds and printing them to the serial monitor. 3) A program to control an RGB LED by setting the color (red, green, blue combinations) every 1 second using a function to set the analog values on each pin.

Uploaded by

Kaleeswari
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/ 5

7.Program using arduino IDE for blink LED.

// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever


void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the
voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the
voltage LOW
delay(1000); // wait for a second
}
6. Write a program for monitor temperature using arduino.:

#include <dht.h> //define the pin that the DHT sensor is connected
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT; (DHT IS Digital Temperature And Humidity Sensor)
void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print("Current humidity = ");


Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop(

8. Program for RGB LED using Arduino:


int red_light_pin= 11;
int green_light_pin = 10;
int blue_light_pin = 9;
void setup() {
pinMode(red_light_pin, OUTPUT);
pinMode(green_light_pin, OUTPUT);
pinMode(blue_light_pin, OUTPUT);
}
void loop() {
RGB_color(255, 0, 0); // Red
delay(1000);
RGB_color(0, 255, 0); // Green
delay(1000);
RGB_color(0, 0, 255); // Blue
delay(1000);
RGB_color(255, 255, 125); // Raspberry
delay(1000);
RGB_color(0, 255, 255); // Cyan
delay(1000);
RGB_color(255, 0, 255); // Magenta
delay(1000);
RGB_color(255, 255, 0); // Yellow
delay(1000);
RGB_color(255, 255, 255); // White
delay(1000);
}
void RGB_color(int red_light_value, int green_light_value, int
blue_light_value)
{
analogWrite(red_light_pin, red_light_value);
analogWrite(green_light_pin, green_light_value);
analogWrite(blue_light_pin, blue_light_value);
}

You might also like