Thursday, 18 September 2025

rr

 import adafruit_dht

import board

import requests

import time


# DHT11 sensor configuration

dhtDevice = adafruit_dht.DHT11(board.D4)


# ThingSpeak configuration

THINGSPEAK_API_KEY = "218PQ4GZVW9P3NDS"  # Replace with your API key

THINGSPEAK_URL = "https://api.thingspeak.com/update"


def read_sensor_data():

    temperature = dhtDevice.temperature

    humidity = dhtDevice.humidity


    if humidity is not None and temperature is not None:

        return temperature, humidity

    else:

        print("Failed to retrieve data from DHT11 sensor.")

        return None, None


def send_to_thingspeak(temperature, humidity):

    payload = {

        "api_key": THINGSPEAK_API_KEY,

        "field1": temperature,

        "field2": humidity

    }

    response = requests.get(THINGSPEAK_URL, params=payload)


    if response.status_code == 200:

        print("Data sent to ThingSpeak successfully.")

    else:

        print("Failed to send data to ThingSpeak.")


def main():

    try:

        while True:

            temperature, humidity = read_sensor_data()

            if temperature is not None and humidity is not None:

                print(f"Temperature: {temperature} C, Humidity: {humidity}%")

                send_to_thingspeak(temperature, humidity)


            time.sleep(10)  # Wait 10 seconds before next reading

    finally:

        dhtDevice.exit()


if __name__ == "__main__":

    main()


RSP1

import adafruit_dht

import board

import requests

import time


# DHT11 sensor configuration

dhtDevice = adafruit_dht.DHT11(board.D4)


# ThingSpeak configuration

THINGSPEAK_API_KEY = "218PQ4GZVW9P3NDS"  # Replace with your API key

THINGSPEAK_URL = "https://api.thingspeak.com/update"


def read_sensor_data():

    temperature = dhtDevice.temperature

    humidity = dhtDevice.humidity


    if humidity is not None and temperature is not None:

        return temperature, humidity

    else:

        print("Failed to retrieve data from DHT11 sensor.")

        return None, None


def send_to_thingspeak(temperature, humidity):

    payload = {

        "api_key": THINGSPEAK_API_KEY,

        "field1": temperature,

        "field2": humidity

    }

    response = requests.get(THINGSPEAK_URL, params=payload)


    if response.status_code == 200:

        print("Data sent to ThingSpeak successfully.")

    else:

        print("Failed to send data to ThingSpeak.")


def main():

    try:

        while True:

            temperature, humidity = read_sensor_data()

            if temperature is not None and humidity is not None:

                print(f"Temperature: {temperature} C, Humidity: {humidity}%")

                send_to_thingspeak(temperature, humidity)


            time.sleep(10)  # Wait 10 seconds before next reading

    finally:

        dhtDevice.exit()


if __name__ == "__main__":

    main()


Monday, 8 September 2025

Exoeriment 9 (EM 18 Reader Module)

 //#include <SPI.h>

//#include <MFRC522.h>
#define RST_PIN 9
#define SS_PIN 10
//MFRC522 rfid(SS_PIN, RST_PIN);

// Map each card UID to a name and add more cards as needed
String cardUIDs[] = { "1D000552D19B", "1D000858E7AA", "1D0006B8BD1E"}; // Replace with actual UIDs from EM-18
String cardNames[] = { "mahesh", "Charan","manikanta"};   // Replace with actual names

// Function to get the name associated with the UID
String getCardName(String uid) {
  for (int i = 0; i < sizeof(cardUIDs) / sizeof(cardUIDs[0]); i++) {
    if (uid == cardUIDs[i]) {
      return cardNames[i];
    }
  }
  return "Unknown";
}

void setup () {
  Serial.begin(9600); // Initialize serial communication with EM-18 (default 9600 baud)
  Serial.println("Scan your RFID card...");
}

void loop () {
  // Check if EM-18 sent data
  if (Serial.available() > 0) {
    String uid = Serial.readStringUntil('\n'); // Read UID until newline (EM-18 sends 12 chars + CR/LF)
    uid.trim();  // Remove spaces/newline characters

    String name = getCardName(uid);

    if (name != "Unknown") {
      Serial.print("Attendance Marked for: ");
      Serial.println(name);
    } else {
      Serial.print("Card not recognized: ");
      Serial.println(uid);
    }
  }
}