Wednesday, June 8, 2022

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

#define RED    8

#define GREEN  9

#define YELLOW 10

#define BLUE   11


// Define integer to remember toggle state

int redState = 0;

int greenState = 0;

int yellowState = 0;

int blueState = 0;


// Define IR Receiver and Results Objects

IRrecv irrecv(RECV_PIN);

decode_results results;


void setup() {

  // Enable the IR Receiver

  irrecv.enableIRIn();

  // Set LED pins as Outputs

  pinMode(RED, OUTPUT);

  pinMode(GREEN, OUTPUT);

  pinMode(YELLOW, OUTPUT);

  pinMode(BLUE, OUTPUT);

}



void loop() {

  if (irrecv.decode(&results)) {


    switch (results.value) {


      case  0x6785E38A:


        if (redState == 0) {

          digitalWrite(RED, HIGH);

          redState = 1;

        }

        else {

          digitalWrite(RED, LOW);

          redState = 0;


        }

        break;


      case  0x823E3FB6:


        if (greenState == 0) {

          digitalWrite(GREEN, HIGH);

          greenState = 1;

        }

        else {

          digitalWrite(GREEN, LOW);

          greenState = 0;


        }

        break;


      case  0xBDF598EE:


        if (yellowState == 0) {

          digitalWrite(YELLOW, HIGH);

          yellowState = 1;

        }

        else {

          digitalWrite(YELLOW, LOW);

          yellowState = 0;


        }

        break;


      case  0x783D9008:


        if (blueState == 0) {

          digitalWrite(BLUE, HIGH);

          blueState = 1;

        }

        else {

          digitalWrite(BLUE, LOW);

          blueState = 0;


        }

        break;



    }

    irrecv.resume();

  }


}


esp8266 telegram

 #include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

#include <UniversalTelegramBot.h>

#include <ArduinoJson.h>


// Replace with your network credentials

const char* ssid = "rkk";

const char* password = "rkk@1234";


// Initialize Telegram BOT

#define BOTtoken "5527844175:AAEh2wPs0BtABXxfJSTjN_1wC-rr1JFu_oo"  // your Bot Token (Get from Botfather)


// Use @myidbot to find out the chat ID of an individual or a group

// Also note that you need to click "start" on a bot before it can

// message you

#define CHAT_ID "911786722"


X509List cert(TELEGRAM_CERTIFICATE_ROOT);

WiFiClientSecure client;

UniversalTelegramBot bot(BOTtoken, client);


const int motionSensor = 14; // PIR Motion Sensor

bool motionDetected = false;


// Indicates when motion is detected

void ICACHE_RAM_ATTR detectsMovement() {

  //Serial.println("MOTION DETECTED!!!");

  motionDetected = true;

}


void setup() {

  Serial.begin(115200);

  configTime(0, 0, "pool.ntp.org");      // get UTC time via NTP

  client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org


  // PIR Motion Sensor mode INPUT_PULLUP

  pinMode(motionSensor, INPUT_PULLUP);

  // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode

  attachInterrupt(digitalPinToInterrupt(motionSensor), detectsMovement, RISING);


  // Attempt to connect to Wifi network:

  Serial.print("Connecting Wifi: ");

  Serial.println(ssid);


  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);


  while (WiFi.status() != WL_CONNECTED) {

    Serial.print(".");

    delay(500);

  }


  Serial.println("");

  Serial.println("WiFi connected");

  Serial.print("IP address: ");

  Serial.println(WiFi.localIP());


  bot.sendMessage(CHAT_ID, "Bot started up", "");

}


void loop() {

  if(motionDetected){

    bot.sendMessage(CHAT_ID, "Motion detected!!", "");

    Serial.println("Motion Detected");

    motionDetected = false;

  }

}

Tuesday, June 7, 2022

LIBRARY FOR ESP 8266 AND ESP32

 http://arduino.esp8266.com/stable/package_esp8266com_index.json

https://dl.espressif.com/dl/package_esp32_index.json

IoT Project ESP8266 with Telegram Messenger with PIR

 #include <Wire.h>

#include <LiquidCrystal_I2C.h>

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

#include <UniversalTelegramBot.h>



LiquidCrystal_I2C lcd (0x27, 16, 2);

const char* ssid = "rkk";

const char* password = "rkk@1234";



#define BOTtoken "5527844175:AAEh2wPs0BtABXxfJSTjN_1wC-rr1JFu_oo"

#define CHAT_ID "Lyallbot"


#define Sensor D0

#define LEDR D3

#define LEDG D4

#define Buzzer D5


X509List cert(TELEGRAM_CERTIFICATE_ROOT);

WiFiClientSecure client;

UniversalTelegramBot bot(BOTtoken, client);



void setup() {

  Serial.begin(115200);

  lcd.init();

  lcd.backlight();

  Wire.begin(D2, D1);

  configTime(0, 0, "pool.ntp.org");      // get UTC time via NTP

  client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org


  pinMode(Sensor, INPUT);

  pinMode(LEDR, OUTPUT);

  pinMode(LEDG, OUTPUT);

  pinMode(Buzzer, OUTPUT);


  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);


  int a = 0;

  while (WiFi.status() != WL_CONNECTED) {

    Serial.print(".");

    lcd.setCursor(a, 0);

    lcd.print(".");

    delay(500);

    a++;

  }


  Serial.println("");

  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print("WiFi connected");

  Serial.println("WiFi connected");

  Serial.print("IP address: ");

  lcd.setCursor(0, 1);

  lcd.print(WiFi.localIP());

  Serial.println(WiFi.localIP());

  delay(500);


  bot.sendMessage(CHAT_ID, "System started", "");

  lcd.clear();

  lcd.setCursor(0, 0);

  lcd.print("System started");

  delay(1000);

  lcd.clear();

}

void loop() {

  bool value = digitalRead(Sensor);

  Serial.println(value);

  if (value == 1) {

    Serial.println("Motion Detected");

    digitalWrite(LEDR, HIGH);

    digitalWrite(Buzzer, HIGH);

    digitalWrite(LEDG, LOW);

    lcd.setCursor(0, 0);

    lcd.print("Motion Detected");

    bot.sendMessage(CHAT_ID, "Motion detected!!", "");

  } else if (value == 0) {

    digitalWrite(LEDR, LOW);

    digitalWrite(Buzzer, LOW);

    digitalWrite(LEDG, HIGH);

    lcd.setCursor(0, 0);

    lcd.print("No Motion      ");

  }

}

Wednesday, May 25, 2022

How to install Library of 8266 in Arduino IDE











 

Step 1: Open Arduino IDE

Open ArduinoIDE, 


Open file 
 


Goto- the preferencesand then click Preferences and then paste http://arduino.esp8266.com/stable/package_esp8266com_index.json




in the Additional Boards Manager URLs option, click ok.

go to Tools menu

                                      

got to board - Board Manager















                               















Tuesday, May 24, 2022

EXP 5. Control and monitor the temperature of the elements using temperature sensor with NODEMCU






#include "DHT.h"
#define DHTPIN 4 // what digital pin the DHT22 is conected to
#define DHTTYPE DHT22 // there are multiple kinds of DHT sensors
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.setTimeout(2000);
// Wait for serial to initialize.
while(!Serial) { }
dht.begin();
Serial.println("Device Started");
Serial.println("-------------------------------------");
Serial.println("Running DHT!");
Serial.println("-------------------------------------");
}
int timeSinceLastRead = 0;
void loop() {
// Report every 2 seconds.
if(timeSinceLastRead > 2000) {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println("Failed to read from DHT sensor!");
timeSinceLastRead = 0;
return;
}
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
Serial.print("Humidity: ");
Serial.print(h);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" *C ");
Serial.print(f);
Serial.print(" *F\t");
Serial.print("Heat index: ");
Serial.print(hic);
Serial.print(" *C ");
Serial.print(hif);
Serial.println(" *F");
timeSinceLastRead = 0;
}
delay(100);
timeSinceLastRead += 100;
}


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...