Вы находитесь на странице: 1из 24

Advanced technologies for smarter and secured life (ATSSL)

 IOT PROGRAMS

1) blink led

int a = 5;
void setup() {
// put your setup code here, to run once:
pinMode(a, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// for(int i=0;i<=6;i++)
digitalWrite(a, HIGH);
delay(1000);
digitalWrite(a, LOW);
delay(1000);
}

2) pot

int a = A0;
void setup() {
pinMode(a, INPUT);
Serial.begin(9600);
}
void loop() {
int b = analogRead(a);
Serial.println("THE POT VALUE IS: ");
float c = ((b/1023)*5);
Serial.println(c);
}

3)ultra sonic sensor

#define trigPin 7
#define echoPin 5
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
long duration,distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance =(duration / 2)/29.1;
float distmm = (duration / 2)/2.9154519;
Serial.print(distance);
Serial.println("cm");
Serial.print(distmm);
Serial.println("mm");
delay(1000);
}

4)Ultra sonic sensors using two leds

#define trigPin 7
#define echoPin 5
int x = 3;
int y = 2;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(x, OUTPUT);
pinMode(y, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
long duration,distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance =(duration / 2)/29.1;
float distmm = (duration / 2)/2.9154519;
Serial.print(distance);
Serial.println("cm");
if(distance > 20)
{
digitalWrite(x, LOW);
delay(150);
}
else
{
digitalWrite(x, HIGH);
delay(150);
}
Serial.print(distmm);
Serial.println("mm");
delay(1000);
if(distmm <= 200)
{
digitalWrite(y, HIGH);
delay(150);
}
else
{
digitalWrite(y, LOW);
delay(150);
}
}
5)Buletooth control led using app

int h = 13;
char c = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(h, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0)
{
c = Serial.read();
Serial.println(c);
}
if(c == '1')
{
digitalWrite(h, HIGH);
}
else if(c == '0')
{
digitalWrite(h, LOW);
}
}

6)lcd display
#include <LiquidCrystal.h>
int i = 0;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("WELCOME TO AMC");
lcd.setCursor(5,1);
lcd.print("ATTSL Internship");
}

void loop() {
lcd.clear();

7) Fire sensor

int a = A0;
void setup() {
pinMode(a, INPUT);
Serial.begin(9600);
}

void loop() {
int b = analogRead(a);
Serial.println("The value is");
Serial.println(b);
}

8) Water senssor

int a = 5;
int c = 6;
void setup() {
pinMode(a, INPUT);
pinMode(c, OUTPUT);
Serial.begin(9600);
}

void loop() {
int b = digitalRead(a);
Serial.println("The value is");
Serial.println(b);
if (b == 0)
{
digitalWrite(c, HIGH);
}
else
{
digitalWrite(c, LOW);
}
}

9) Mositure Sensors

int a = A0;
void setup() {
pinMode(a, INPUT);
Serial.begin(9600);
}

void loop() {
int b = analogRead(a);
Serial.println("The value is");
Serial.println(b);
delay(1000);
}

10) Laser sensor

int a = 5;

void setup() {
// put your setup code here, to run once:
pinMode(a, OUTPUT);

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(a, HIGH);
delay(100);
digitalWrite(a, LOW);
delay(100);
}

11) Temperature sensor

int a = A0;
void setup() {
pinMode(a, INPUT);
Serial.begin(9600);
}

void loop() {
int b = analogRead(a);
Serial.println("The value in degree ");
float c = ((b*5*100)/1023);
Serial.println(c);
delay(1000);
}

for (i=50; i>=0; i--)


{
delay(150);
lcd.setCursor(0,0);
lcd.print("The counter is");
lcd.setCursor(1,1);
lcd.print(i);
}
}

12) Reading led value

int a = 5;
int b = 0;
int c = 13;

void setup() {
// put your setup code here, to run once:
pinMode(a, INPUT);
pinMode(c, OUTPUT);
Serial.begin(9600);

void loop() {
// put your main code here, to run repeatedly:
b = digitalRead(a);
Serial.println(b);
if(b==HIGH)
{
digitalWrite(c, HIGH);
}
else
{
digitalWrite(c, LOW);
}
}

13) LCD display

#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("WELCOME TO AMC");
lcd.setCursor(5,1);
lcd.print("ATTSL");
}

void loop() {

3) LCD display using counter

#include <LiquidCrystal.h>
int i = 0;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("WELCOME TO AMC");
lcd.setCursor(5,1);
lcd.print("ATTSL Internship");
}

void loop() {
lcd.clear();
for (i=0; i<=50; i++)
{
delay(150);
lcd.setCursor(0,0);
lcd.print("The counter is");
lcd.setCursor(1,1);
lcd.print(i);
}
}
14) JOYSTICK

int a = A0;
int b = A1;
int c = 8;
int d = 0;
int e = 0;
int f = 0;
void setup() {
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
Serial.begin(9600);
}

void loop() {
d = analogRead(a);
e = analogRead(b);
f = digitalRead(c);
Serial.println("THE x values are : ");
Serial.println(d);
delay(1000);
Serial.println("THE y values are : ");
Serial.println(e);
delay(1000);
Serial.println("THE switch status is : ");
Serial.println(f);
delay(1000);
}
15) Joystick using lcd

#include <LiquidCrystal.h>
int i = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int a = A0;
int b = A1;
int c = 8;
int d = 0;
int e = 0;
int f = 0;
void setup() {
lcd.begin(16, 2);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
Serial.begin(9600);
}

void loop() {
d = analogRead(a);
e = analogRead(b);
f = digitalRead(c);
Serial.println("THE x values are : ");
Serial.println(d);
delay(100);
Serial.println("THE y values are : ");
Serial.println(e);
delay(100);
Serial.println("THE switch status is : ");
Serial.println(f);
delay(100);
lcd.setCursor(0,0);
lcd.print("X_value");
lcd.print(d);
lcd.setCursor(1,1);
lcd.print("Y_value");
lcd.print(e);
}

16) Joystick using lcd and buzzer

#include <LiquidCrystal.h>
int buz = 10;
int i = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int a = A0;
int b = A1;
int c = 8;
int d = 0;
int e = 0;
int f = 0;
void setup() {
lcd.begin(16, 2);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
pinMode(buz, OUTPUT);
Serial.begin(9600);
}

void loop() {
d = analogRead(a);
e = analogRead(b);
f = digitalRead(c);
Serial.println("THE x values are : ");
Serial.println(d);
delay(100);
Serial.println("THE y values are : ");
Serial.println(e);
delay(100);
Serial.println("THE switch status is : ");
Serial.println(f);
delay(100);
lcd.setCursor(0,0);
lcd.print("X_value");
lcd.print(d);
if (d>1000)
{
digitalWrite(buz, HIGH);
delay(100);
}
else
{
digitalWrite(buz, LOW);
delay(100);
}
lcd.setCursor(1,1);
lcd.print("Y_value");
lcd.print(e);

17) Transfering data using serial montior

int h = 13;
char c = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(h, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0)
{
c = Serial.read();
Serial.println(c);
}
if(c == 'a')
{
digitalWrite(h, HIGH);
}
else if(c == 'b')
{
digitalWrite(h, LOW);
}
}

18) Reading led value

int a = 5;
int b = 0;
int c = 13;

void setup() {
// put your setup code here, to run once:
pinMode(a, INPUT);
pinMode(c, OUTPUT);
Serial.begin(9600);

void loop() {
// put your main code here, to run repeatedly:
b = digitalRead(a);
Serial.println(b);
if(b==HIGH)
{
digitalWrite(c, HIGH);
}
else
{
digitalWrite(c, LOW);
}
}

19) LCD display using counter

#include <LiquidCrystal.h>
int i = 0;
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.setCursor(0,0);
lcd.print("WELCOME TO AMC");
lcd.setCursor(5,1);
lcd.print("ATTSL Internship");
}

void loop() {
lcd.clear();
for (i=0; i<=50; i++)
{
delay(150);
lcd.setCursor(0,0);
lcd.print("The counter is");
lcd.setCursor(1,1);
lcd.print(i);
}
}

20) Joystick using lcd

#include <LiquidCrystal.h>
int i = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int a = A0;
int b = A1;
int c = 8;
int d = 0;
int e = 0;
int f = 0;
void setup() {
lcd.begin(16, 2);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
Serial.begin(9600);
}

void loop() {
d = analogRead(a);
e = analogRead(b);
f = digitalRead(c);
Serial.println("THE x values are : ");
Serial.println(d);
delay(100);
Serial.println("THE y values are : ");
Serial.println(e);
delay(100);
Serial.println("THE switch status is : ");
Serial.println(f);
delay(100);
lcd.setCursor(0,0);
lcd.print("X_value");
lcd.print(d);
lcd.setCursor(1,1);
lcd.print("Y_value");
lcd.print(e);
}

21) Joystick using lcd and buzzer

#include <LiquidCrystal.h>
int buz = 10;
int i = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int a = A0;
int b = A1;
int c = 8;
int d = 0;
int e = 0;
int f = 0;
void setup() {
lcd.begin(16, 2);
pinMode(a, INPUT);
pinMode(b, INPUT);
pinMode(c, INPUT);
pinMode(buz, OUTPUT);
Serial.begin(9600);
}

void loop() {
d = analogRead(a);
e = analogRead(b);
f = digitalRead(c);
Serial.println("THE x values are : ");
Serial.println(d);
delay(100);
Serial.println("THE y values are : ");
Serial.println(e);
delay(100);
Serial.println("THE switch status is : ");
Serial.println(f);
delay(100);
lcd.setCursor(0,0);
lcd.print("X_value");
lcd.print(d);
if (d>1000)
{
digitalWrite(buz, HIGH);
delay(100);
}
else
{
digitalWrite(buz, LOW);
delay(100);
}
lcd.setCursor(1,1);
lcd.print("Y_value");
lcd.print(e);

22) Transfering data using serial montior

int h = 13;
char c = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(h, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
if (Serial.available()>0)
{
c = Serial.read();
Serial.println(c);
}
if(c == 'a')
{
digitalWrite(h, HIGH);
}
else if(c == 'b')
{
digitalWrite(h, LOW);
}
}

Вам также может понравиться