Tuesday, 7 October 2025

Experiment : 11 : Capture Images from Web Camera using Raspberry Pi and Apply Filters to Increase Image Quality

import cv2

import numpy as np

cap = cv2.VideoCapture(0, cv2.CAP_V4L2)

if not cap.isOpened():

    print("Error: Could not open web camera.")

    exit()

ret, frame = cap.read()

if not ret:

   print("Error: Could not capture image.")

     exit()

cap.release()

image_path = "captured_image.jpg"

cv2.imwrite(image_path, frame)

image = cv2.imread(image_path)

blurred_image = cv2.GaussianBlur(image, (5, 5), 0)

kernel = np.array([[0,-1, 0], [-1, 5,-1], [0,-1, 0]])

sharpened_image = cv2.filter2D(blurred_image,-1, kernel)

gray_image = cv2.cvtColor(sharpened_image, cv2.COLOR_BGR2GRAY)

equalized_image = cv2.equalizeHist(gray_image)

cv2.imwrite("blurred_image.jpg", blurred_image)

cv2.imwrite("sharpened_image.jpg", sharpened_image)

cv2.imwrite("equalized_image.jpg", equalized_image)

cv2.imshow("Original Image", image)

cv2.imshow("Blurred Image", blurred_image)

cv2.imshow("Sharpened Image", sharpened_image)

cv2.imshow("Equalized Image", equalized_image)

cv2.waitKey(0)

cv2.destroyAllWindows()

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);
    }
  }
}

Tuesday, 29 July 2025

Testbench Code 2

 `timescale 1ns / 1ps


module traffic_light_tb();


reg clk;

reg reset;


wire red;

wire yellow;

wire green;


traffic_light_controller dut( .clk(clk), .reset(reset), .red(red), .yellow(yellow),

  .green(green) );


always #5 clk = ~clk; 


initial begin

  clk = 0;

  reset = 1;

  #10 reset = 0;


  #100 $finish;

end


always @(posedge clk) begin

  $display("RED=%b YELLOW=%b GREEN=%b", red, yellow, green);

end


endmodule. 

Design Code 2

 `timescale 1ns / 1ps


module traffic_light_controller(

  input clk, reset, 

  output reg red, yellow, green );


localparam RED = 3'b001; 

localparam YELLOW = 3'b010;

localparam GREEN = 3'b100;


reg [2:0] state; 


always @(posedge clk)

begin

  if (reset) 

    state <= RED;

  else

    case (state)

      RED: begin

        red <= 1'b1;

        yellow <= 1'b0;

        green <= 1'b0;

        state <= YELLOW;

      end


      YELLOW: begin

        red <= 1'b0;

        yellow <= 1'b1; 

        green <= 1'b0;

        state <= GREEN;

      end


      GREEN: begin

        red <= 1'b0;

        yellow <= 1'b0;

        green <= 1'b1;

        state <= RED;

      end

    endcase

end


endmodule. 

Testbench Code 1

 `timescale 1ns / 1ps


module vending_machine_tb;

    // Inputs

    reg clk, reset, cancel;

    reg [1:0] coin, sel;

    

    // Outputs

    wire PrA, PrB, PrC, change;


    // Instantiate the vending machine module

    vending_machine uut (

        .clk(clk),

        .reset(reset),

        .cancel(cancel),

        .coin(coin),

        .sel(sel),

        .PrA(PrA),

        .PrB(PrB),

        .PrC(PrC),

        .change(change)

    );


    // Clock Generation: 10ns period (50MHz clock)

    always #5 clk = ~clk; 


    // Test Procedure

    initial begin

        // Initialize Inputs

        clk = 0;

        reset = 1;

        cancel = 0;

        coin = 2'b00;

        sel = 2'b00;

        

        // Hold reset for 20 ns

        #20 reset = 0;


        // Test Case 1: Insert Rs. 5 and Buy Product A

        #10 coin = 2'b01;   // Insert Rs. 5

        #10 sel = 2'b00;    // Select Product A

        #10 coin = 2'b00;   // Stop inserting coins

        #20;


        // Test Case 2: Insert Rs. 10 and Buy Product B

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 sel = 2'b01;    // Select Product B

        #20;


        // Test Case 3: Insert Rs. 5 twice (Total Rs. 10) and Buy Product A (Expect Rs. 5 change)

        #10 coin = 2'b01;   // Insert Rs. 5

        #10 coin = 2'b01;   // Insert Rs. 5 again (Total Rs. 10)

        #10 sel = 2'b00;    // Select Product A

        #20;


        // Test Case 4: Insert Rs. 20 and Buy Product C

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 coin = 2'b10;   // Insert Rs. 10 again (Total Rs. 20)

        #10 sel = 2'b10;    // Select Product C

        #20;


        // Test Case 5: Insert Rs. 10 and Cancel Transaction

        #10 coin = 2'b10;   // Insert Rs. 10

        #10 cancel = 1;     // Press Cancel

        #10 cancel = 0;     // Release Cancel

        #20;


        // End Simulation

        #50 $finish;

    end


    // Monitor the signals

    initial begin

        $monitor("Time = %d, Coin = %b, Sel = %b, Cancel = %b, PrA = %b, PrB = %b, PrC = %b, Change = %b",

                  $time, coin, sel, cancel, PrA, PrB, PrC, change);

    end


endmodule


Design Code 1

 Design Code:

`timescale 1ns / 1ps


module vending_machine(

    input clk, reset, cancel,

    input [1:0] coin, sel,

    output reg PrA, PrB, PrC, change

);


    // State encoding using parameter 

    parameter S0 = 3'b000, S5 = 3'b001, S10 = 3'b010, S15 = 3'b011, S20 = 3'b100;


    reg [2:0] current_state, next_state;


    // Sequential logic for state transition

    always @(posedge clk or posedge reset) begin

        if (reset)

            current_state <= S0; // Reset to initial state

        else

            current_state <= next_state;

    end


    // Next State Logic (Combinational)

    always @(*) begin

        case (current_state)

            S0: begin

                if (coin == 2'b01) next_state = S5;

                else if (coin == 2'b10) next_state = S10;

                else next_state = S0;

            end


            S5: begin

                if (coin == 2'b01) next_state = S10;

                else if (coin == 2'b10) next_state = S15;

                else if (cancel) next_state = S0;

                else next_state = S5;

            end


            S10: begin

                if (coin == 2'b01) next_state = S15;

                else if (coin == 2'b10) next_state = S20;

                else if (cancel) next_state = S0;

                else next_state = S10;

            end


            S15: begin

                if (coin == 2'b01) next_state = S20;

                else if (cancel) next_state = S0;

                else next_state = S15;

            end


            S20: begin

                if (cancel) next_state = S0;

                else next_state = S20;

            end


            default: next_state = S0; // Default state

        endcase

    end


    // Output Logic

    always @(posedge clk or posedge reset) begin

        if (reset) begin

            PrA <= 0;

            PrB <= 0;

            PrC <= 0;

            change <= 0;

        end 

        else begin

            // Default values (avoid latches)

            PrA <= 0;

            PrB <= 0;

            PrC <= 0;

            change <= 0;


            case (current_state)

                S5: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;  // Product A (Rs. 5)

                        change <= 0; // No change needed

                    end

                end

                

                S10: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;  // Product A (Rs. 5)

                        change <= 1; // Rs. 5 change

                    end

                    else if (sel == 2'b01) begin

                        PrB <= 1; // Product B (Rs. 10)

                        change <= 0; // No change needed

                    end

                end

                

                S15: begin

                    if (sel == 2'b01) begin

                        PrB <= 1;  // Product B (Rs. 10)

                        change <= 1; // Rs. 5 change

                    end

                end

                

                S20: begin

                    if (sel == 2'b00) begin

                        PrA <= 1;

                        change <= 1; // Rs. 15 change

                    end

                    else if (sel == 2'b01) begin

                        PrB <= 1;

                        change <= 1; // Rs. 10 change

                    end

                    else if (sel == 2'b10) begin

                        PrC <= 1; // Product C (Rs. 20)

                        change <= 0; // No change needed

                    end

                end

            endcase

            

            // Handle cancellation (return money)

            if (cancel) 

                change <= 1;

        end

    end

endmodule


Sunday, 13 July 2025

IOT LAB EXP 4.2 PROGRAM

 #include <ESP8266WiFi.h>

 #include "Adafruit_MQTT.h"
 #include "Adafruit_MQTT_Client.h"
 #define WLAN_SSID "ECE_STAFF_ROOM"
  #define WLAN_PASS "specnet@23"
 #define AIO_SERVER "io.adafruit.com"
 #define AIO_SERVERPORT 1883
 #define AIO_USERNAME "ChanduPrasanth"
 #define AIO_KEY "aio_WIaH72ooBeG8RlOfFJxF3a1DRGXV"
 // Create an ESP8266 WiFiClient class to connect to the MQTT server.
 WiFiClient client;
 // Setup the MQTT client class by passing in the WiFi client and
 // MQTT server and login details.
 Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
 // Setup a feed called iot-lab-exp04-attendance for publishing.
 Adafruit_MQTT_Publish attendanceFeed = Adafruit_MQTT_Publish(&mqtt,
 "ChanduPrasanth/feeds/iot attendance");
 void connectMQTT() {
 Serial.print("Connecting to Adafruit IO...");
 while (mqtt.connected() == false) {
 if (mqtt.connect()) {
 Serial.println("Connected to Adafruit IO !");
 } else {
 Serial.println("Failed to connect to Adafruit IO, retrying in 5s...");
 delay(5000);
 }
 }
 }
 void setup() {
 Serial.begin(115200);
 delay(10);
 Serial.println("Adafruit MQTT demo");
 // Connect to WiFi access point.
 Serial.println(); Serial.println();
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);
 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }
 Serial.println();
 Serial.println("WiFi connected");
 Serial.print("IP address: "); Serial.println(WiFi.localIP());
 connectMQTT();
 }
 
 void loop() {
 // Now we can publish stuff!
 Serial.print("Sending Attendance ");
 Serial.print("...");
 if (mqtt.connected()){
 // Replace your 10-Digit roll number here
 if (! attendanceFeed.publish("22261A0400")) {
 Serial.println("Failed");
 } else {
 Serial.println("OK!");
 }
 }
 delay(5000);
 }

IOT LAB EXP 4.1 PROGRAM

 #include <ESP8266WiFi.h>
 #include <ESP8266HTTPClient.h>
 const char* ssid = "ECE_STAFF_ROOM";
 const char* password = "specnet@23";
 String server = "http://api.thingspeak.com/update";
 String apiKey = "65AZ09LAJJKJQ0D3";
 WiFiClient client;
 #include <DHT.h>
 #define DHTPIN 4
 #define DHTTYPE DHT11
 DHT dht(DHTPIN,DHTTYPE);
 float h;
 float t;
  void setup() {
 Serial.begin(115200);
 WiFi.begin(ssid, password);
 Serial.print("Connecting.");
 while(WiFi.status() != WL_CONNECTED){
 delay(1000);
 Serial.print(".");
 }
 Serial.println(": Connected to WiFi!");
 dht.begin();
 }
 void loop() {
 h = dht.readHumidity();
 t = dht.readTemperature();
 HTTPClient http;
 // Place your 10-digit roll number in the string below
 String url = server + "?api_key=" + apiKey + "&field1=22261A0400" +
 "&field2="+String(h) + "&field3="+ String(t);
 http.begin(client,url);
 int httpCode = http.GET();
 if(httpCode > 0){
 Serial.println("Data Sent Successfully");
 }else{
 Serial.println("Error sending data");
 }
 http.end();
 delay(5000);

 } 

Sunday, 6 July 2025

IOT LAB EXP3 PROGRAM


 #include <ESP8266WiFi.h>

 #include <ThingSpeak.h>
 #include <DHT.h>
 #define DHTPIN 4
 #define DHTTYPE DHT11
 const char* ssid = "PLACEMENTDRIVE";
 // Replace with your Wi-Fi SSID
 const char* password = "specplacements"; // Replace with your Wi-Fi password
 unsigned long ch_id = 2995467; // Replace with your ThingSpeak Channel ID
 const char* apiKey = "EW2AWHPQ8QW31G1V"; // Replace with your ThingSpeak API Key
 DHT dht(DHTPIN, DHTTYPE);
 WiFiClient client;

 
 void setup() {
 Serial.begin(9600);
 dht.begin();
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
 delay(500);
 Serial.print(".");
 }
 Serial.println("WiFi connected");
 ThingSpeak.begin(client);
 }
 void loop() {
 
 float h = dht.readHumidity();
 float t = dht.readTemperature();
 if (isnan(h) || isnan(t)) {
 Serial.println("Failed to read from DHT sensor!");
 return;
 }
 int httpCode = ThingSpeak.writeField(ch_id, 1, "Chandu:"+String(h)+","+String(t), apiKey);
 
 if(httpCode == 200){
 Serial.println("Channel write successful.");
 }else{
 Serial.println("Problem writing to channel. HTTP error code " + String(httpCode) );
 }
 delay(20000); // Wait 20 seconds before next reading
 }

Install NodeMCU Board Support Package

  1. Open the Arduino IDE.

 2. Go to File Preferences.

 3. In the Additional Boards Manager URLs eld, add the following URL for NodeMCU support:

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

 4. Click OK. 5. Go to Tools Board Boards Manager. 

 6. Search for esp8266 and install the package

IOT Architectures and Protocols Laboratory

CLIK HERE :   IOT LAB HANDOUTS