Tuesday, May 24, 2022

EXP 2. Find the obstacle distance using Arduino

 




 

int trigPin = 8; 

int echoPin =7; 

void setup()

{

Serial.begin(9600); 

pinMode(trigPin, OUTPUT);

 pinMode(echoPin, INPUT); 

}

 

void loop()

{

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; 

Serial.println(distance); 

}

EXP 3. Create simple security alarm system using Arduino

 

Program

#define trigPin 7 

#define echoPin 6 

#define LEDlampRed 10

#define LEDlampYellow 11

 

#define LEDlampGreen 12

 #define soundbuzzer 4

 

void setup() 

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

 pinMode(echoPin, INPUT); 

pinMode(LEDlampRed, OUTPUT); 

pinMode(LEDlampYellow, OUTPUT);

 pinMode(LEDlampGreen, OUTPUT); 

pinMode(soundbuzzer, OUTPUT);

}



void loop() {

digitalWrite(trigPin, LOW);

 delayMicroseconds(2);

 digitalWrite(trigPin, HIGH);

 delayMicroseconds(10); 

digitalWrite(trigPin, LOW);

 durationindigit=pulseIn(echoPin, HIGH);

 distanceincm= (durationindigit/5) /29.1;



digitalWrite(LEDlampGreen, HIGH); 

digitalWrite(LEDlampRed, LOW);

 digitalWrite(LEDlampYellow, LOW); 

noTone(soundbuzzer);

}

else {

digitalWrite(LEDlampGreen, LOW);

 

}



digitalWrite(LEDlampYellow, HIGH); 

digitalWrite(LEDlampGreen, LOW); 

digitalWrite(LEDlampRed, LOW);

}

else { digitalWrite(LEDlampYellow,LOW);



}

digitalWrite(LEDlampRed, HIGH); 

digitalWrite(LEDlampGreen, LOW); 

digitalWrite(LEDlampYellow, LOW); 

sound=1000; tone(soundbuzzer,sound);

}

}


Exp 4. Interface and control an LED with NODEMCU in online

 

Install ESP8266 Add-on in Arduino IDE

To install the ESP8266 board in your Arduino IDE, follow these next instructions:

 

1.  




In your Arduino IDE, go to File> Preferences

2.   Enter http://arduino.esp8266.com/stable/package_esp8266com_ind ex.json into the “Additional Boards Manager URLs” field as shown in the figure below. Then, click the “OK” button:


 

 



 

Note: if you already have the ESP32 boards URL, you can separate the URLs with a comma as follows:

https://dl.espressif.com/dl/package_esp32_index.json, http://arduino.esp8266.com/stable/package_esp8266com_index.json

 

3.   Open the Boards Manager. Go to Tools > Board > Boards Manager…


 

 



 

4.   Search for ESP8266 and press install button for the ESP8266 by ESP8266 Community“:



5.   That’s it. It should be installed after a few seconds.


 


 


 

1.   ESP8266 NodeMCU

2.   Breadboard

3.   LED

4.   Jumper Wires

5.   Arduino IDE

 

Step 3: Pin Connections


 


 

int pin =2;

 

voidsetup(){

// initialize GPIO 2 as an output. pinMode(pin, OUTPUT);

}

 

// the loop function runs over and over again forever voidloop(){

digitalWrite(pin, HIGH);// turn the LED on (HIGH is the voltage level) delay(1000);// wait for a second

digitalWrite(pin, LOW);// turn the LED off by making the voltage LOW delay(1000);// wait for a second

}

 

 

 

Having the right board name and COM port selected, follow these steps:

 

§  Hold-down the BOOT/FLASH button in your ESP8266 development board

§  Press the Upload button in the Arduino IDE to upload your sketch:


§  When you see the Connecting…. message in your Arduino IDE, release the finger from the “BOOT/FLASH button

§  After that, you should see the Done uploading message

Your ESP8266 should have the new sketch running. Press the ENABLE/RESET button to restart the ESP8266 and run the new uploaded sketch.

EXP 6 CREATE A SMARTLIGHT USING RASPBERRY PI AND ARDUINO UNO

 



const int ledpin = 13; // ledpin and lightpin are not changed throughout the process const int lightpin = A2; const int LIGHT = 10; // sets LIGHT value for light sensor void setup() { Serial.begin(9600); pinMode(ledpin, OUTPUT); pinMode(lightpin, INPUT); } void loop() { int lightsens = analogRead(lightpin); // reads analog data from light sensor if (lightsens < LIGHT) { digitalWrite(ledpin, HIGH); //turns led on delay(1500); } else { digitalWrite(ledpin, LOW); } }


EXP 1 simple LED Bar Graph using Arduino.





Coding:

void setup() { 

pinMode(13, OUTPUT);

 pinMode(12, OUTPUT); 

pinMode(11, OUTPUT);

 pinMode(10, OUTPUT); 

pinMode(9, OUTPUT); 

pinMode(8, OUTPUT);

}


void loop() 

digitalWrite(8, HIGH); 

delay(1000); 

digitalWrite(9, HIGH); 

delay(1000); 

digitalWrite(10, HIGH); 

delay(1000); 

digitalWrite(11, HIGH); 

delay(1000);

 digitalWrite(12, HIGH);

 delay(1000); 

digitalWrite(13, HIGH); 

delay(1000); 

digitalWrite(8, LOW); 

delay(1000); 

digitalWrite(9, LOW); 

delay(1000); 

digitalWrite(10, LOW); 

delay(1000); 

digitalWrite(11, LOW);

 delay(1000);

 

digitalWrite(12, LOW);

 delay(1000); 

digitalWrite(13,LOW); 

delay(1000);

}

Saturday, May 21, 2022

EXP NO 8 ESP 8266 Electric Appliances CONTROL USING WEB PAGE

 







#include <ESP8266WiFi.h>

 

const char* ssid = "rkk";

const char* password = "rkk@1234";

 

int relay_pin = 14;

WiFiServer server(80);

 

void setup() 

{

  Serial.begin(115200);

  pinMode(relay_pin, OUTPUT);

  digitalWrite(relay_pin, HIGH);

  

  Serial.print("Connecting to the WIFI Network\n");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) 

  {

    delay(500);

    Serial.print(" * ");

  }

  Serial.println("\nSuccessfully connected to "+String(ssid));

  server.begin();

  Serial.println("\nServer is Active");

  Serial.println("\nType below mentioned IP address in your browser\n"); 

  Serial.println(WiFi.localIP());

}

 

void loop() 

{

  WiFiClient client = server.available();

  if (!client)

  {

    return;

  }

  while(!client.available())

  {

    delay(1);

  }

  String request = client.readStringUntil('\r');

  client.flush();

 

  int value = HIGH;

  if (request.indexOf("/LAMP=ON") != -1)  

  {

    digitalWrite(relay_pin, LOW);

    value = LOW;

  }

  if (request.indexOf("/LAMP=OFF") != -1) 

  {

    digitalWrite(relay_pin, HIGH);

    value = HIGH;

  }

  client.println("HTTP/1.1 200 OK");

  client.println("Content-Type: text/html");

  client.println("");

  client.println("<!DOCTYPE HTML>");

  client.println("<html>");

  client.println("<style> body {background-color:#B2D1D5;}</style>");

  client.print("<center><h1>Table Lamp is now<h1></center>");

  if(value == LOW)

  {

    client.print("<center><h1><b>ON</b></h1></center>");

  } 

  else 

  {

    client.print("<center><h1><b>OFF</b></h1></center>");

  }

  client.println("<br><a href=\"/LAMP=ON\"\"><center><button>Switch ON </button></center></a><br><br>");

  client.println("<a href=\"/LAMP=OFF\"\"><center><button>Switch OFF </button></center></a><br/>");  

  client.println("</html>");

}

EXP NO 7 PUSH THE TEMPERATURE DATA TO BYLNK IoT


 


// Fill-in information from your Blynk Template here

#define BLYNK_TEMPLATE_ID           "TMPLD1CKpt9_"

#define BLYNK_DEVICE_NAME           "temp"


#define BLYNK_FIRMWARE_VERSION        "0.1.0"


#define BLYNK_PRINT Serial

//#define BLYNK_DEBUG


#define APP_DEBUG


// Uncomment your board, or configure a custom board in Settings.h

//#define USE_SPARKFUN_BLYNK_BOARD

#define USE_NODE_MCU_BOARD

//#define USE_WITTY_CLOUD_BOARD

//#define USE_WEMOS_D1_MINI


#include "BlynkEdgent.h"

#include "DHT.h"

#define DHTPIN D2

#define DHTTYPE DHT22


DHT dht(DHTPIN, DHT22);

float t, h;


void setup()

{

  Serial.begin(115200);

  delay(100);


  BlynkEdgent.begin();

  h = dht.readHumidity();

t = dht.readTemperature();

Blynk.virtualWrite(V0, h);

Blynk.virtualWrite(V1, t);

Serial.begin(9600);

dht.begin();

BlynkEdgent.begin();

delay(2000);


}


void loop() {

  BlynkEdgent.run();

}

Control led light using remote

 // Include IR Remote Library by Ken Shirriff #include <IRremote.h> // Define sensor pin const int RECV_PIN = 4; // Define LED pin #de...