NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

Write a program to interface IR Sensor with Arduino using IoT cloud application. (week-6)
-----------------------------------------------------------------------------------
Pin connection Irsensor:
Vcc- vin
GND-GND
Data-D5

#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h"

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int keyIndex = 0;
WiFiClient client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;

int number = 0;
const int irPin=D5;

void setup() {
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}

WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}

void loop() {


if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass);
Serial.print(".");
delay(5000);
}
Serial.println("nConnected.");
}

int x = ThingSpeak.writeField(myChannelNumber, 1, number, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}

number++;
if(number > 99){
number = 0;
}
delay(20000);
}


#define SECRET_SSID "Redmi Note 11 Pro+ 5G"
#define SECRET_PASS "mani@123"
#define SECRET_CH_ID 2038959
#define SECRET_WRITE_APIKEY "7W61L6N4VY7ZFBZP"

---------------------------------------------------------------------------------------------

Write a program Upload temperature and humidity data to the cloud using Arduino or Raspberry Pi. (week-7)

#include <ESP8266WiFi.h>
#include "secrets.h"
#include "ThingSpeak.h"
#include "DHT.h"
#define DHTTYPE DHT11
#define DHTPIN D3

char ssid[] = SECRET_SSID;
char pass[] = SECRET_PASS;
int keyIndex = 0;
DHT dht(DHTPIN, DHTTYPE);
WiFiClient client;

unsigned long myChannelNumber = SECRET_CH_ID;
const char * myWriteAPIKey = SECRET_WRITE_APIKEY;


int number1 = 0;
int number2 = random(0,100);
int number3 = random(0,100);
int number4 = random(0,100);
String myStatus = "";

void setup() {
dht.begin();
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo native USB port only
}

WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}

void loop() {


if(WiFi.status() != WL_CONNECTED){
Serial.print("Attempting to connect to SSID: ");
Serial.println(SECRET_SSID);
while(WiFi.status() != WL_CONNECTED){
WiFi.begin(ssid, pass);
Serial.print(".");
delay(5000);
}
Serial.println("nConnected.");
}

// set the fields with the values
ThingSpeak.setField(1, number1);
ThingSpeak.setField(2, number2);
ThingSpeak.setField(3, number3);
ThingSpeak.setField(4, number4);

// figure out the status message
if(number1 > number2){
myStatus = String("field1 is greater than field2");
}
else if(number1 < number2){
myStatus = String("field1 is less than field2");
}
else{
myStatus = String("field1 equals field2");
}

// set the status
ThingSpeak.setStatus(myStatus);

// write to the ThingSpeak channel
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if(x == 200){
Serial.println("Channel update successful.");
}
else{
Serial.println("Problem updating channel. HTTP error code " + String(x));
}

// change the values
number1++;
if(number1 > 99){
number1 = 0;
}
number2 = random(0,100);
number3 = random(0,100);
number4 = random(0,100);

delay(20000); // Wait 20 seconds to update the channel again
}

Secret.h
// Use this file to store all of the private credentials
// and connection details

#define SECRET_SSID "samsung on7 pro"
#define SECRET_PASS "Venkata123#"

#define SECRET_CH_ID 2040479
#define SECRET_WRITE_APIKEY "0RNY24517GJ9LRWD"


------------------------------------------------------------------------------------------------
Write a program on Arduino or Raspberry Pi to retrieve temperature and humidity data from the Cloud. (week-8)

#include "ThingSpeak.h"
#include <ESP8266WiFi.h>
const char ssid[] = "Redmi Note 11 Pro+ 5G"; // your network SSID (name)
const char pass[] = "mani@123"; // your network password
int statusCode = 0;
WiFiClient client;

//---------Channel Details---------//
unsigned long counterChannelNumber = 2062499; // Channel ID
const char * myCounterReadAPIKey = "W5564YQ3MJPU0S7V"; // Read API Key
const int FieldNumber1 = 1; // The field you wish to read
const int FieldNumber2 = 2; // The field you wish to read
//-------------------------------//

void setup()
{
Serial.begin(115200);
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}

void loop()
{
//----------------- Network -----------------//
if (WiFi.status() != WL_CONNECTED)
{
Serial.print("Connecting to ");
Serial.print(ssid);
Serial.println(" ....");
while (WiFi.status() != WL_CONNECTED)
{
WiFi.begin(ssid, pass);
delay(5000);
}
Serial.println("Connected to Wi-Fi Succesfully.");
}
//--------- End of Network connection--------//

//---------------- Channel 1 ----------------//
long temp = ThingSpeak.readLongField(counterChannelNumber, FieldNumber1, myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Temperature: ");
Serial.println(temp);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
delay(100);
//-------------- End of Channel 1 -------------//

//---------------- Channel 2 ----------------//
long humidity = ThingSpeak.readLongField(counterChannelNumber, FieldNumber2, myCounterReadAPIKey);
statusCode = ThingSpeak.getLastReadStatus();
if (statusCode == 200)
{
Serial.print("Humidity: ");
Serial.println(humidity);
}
else
{
Serial.println("Unable to read channel / No internet connection");
}
delay(100);
//-------------- End of Channel 2 -------------//
}


--------------------------------------------------------------------------------------------------------

Write a program to create TCP Server on cloud using Arduino and Respond with humidity data to TCP Client when requested. (week-9)

Pin connection :
DHT11 sensor
GND-GND
DATA PIN-D4
VCC-Vin

#include "ESP8266WiFi.h"
#include "DHT.h"
#define DHTTYPE DHT11
const char* ssid = "Redmi Note 11 Pro+ 5G";
const char* password = "mani@123";
WiFiServer wifiServer(9000);
DHT dht(D4, DHT11);
void setup() {
Serial.begin(115200);
delay(1000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting..");
}
Serial.print("Connected to WiFi. IP:");
Serial.println(WiFi.localIP());
wifiServer.begin();
dht.begin();
}

void loop() {
WiFiClient client = wifiServer.available();
if (client) {
while (client.connected()) {
while (client.available()>0) {
int h = dht.readHumidity();
client.print("humidity :");
client.println(h);
//Serial.println(sensor_value);
delay(2000);
}
}
client.stop();
Serial.println("Client disconnected");
}
}


----------------------------------------------------------------------------------------------------------

Write a program to create UDP Server on cloud using Arduino and Respond with humidity data to UDP Client when requested.(week-10)
Pin connection:
GND-GND
DATA- D5
VCC-VIN


#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include "DHT.h"
#define DHTTYPE DHT11
// Set WiFi credentials
#define WIFI_SSID "333-3"
#define WIFI_PASS "123456789"
#define UDP_PORT 4210
DHT dht(D5, DHT11);

// UDP
WiFiUDP UDP;
char packet[255];
char reply[] = "Packet received!";

void setup() {
// Setup serial port
Serial.begin(115200);
Serial.println();
Serial.println(F("DHTxx test!"));
dht.begin();


// Begin WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);

// Connecting to WiFi...
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
// Loop continuously while WiFi is not connected
while (WiFi.status() != WL_CONNECTED)
{
delay(2000);
Serial.print(".");
}

// Connected to WiFi
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());

// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);

}

void loop() {
int h = dht.readHumidity();
//float h = dht.readHumidity();
delay(2000);
// Send return packet
UDP.beginPacket(UDP.remoteIP(), UDP.remotePort());
UDP.write(reply);

// client.print("humidity :");
// client.println(h);
UDP.println(h);
UDP.endPacket();
Serial.println(F("Humidity:n "));
Serial.println(h);

}



     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.