Security Sensor Through Human Body Detection Sensor and Wi-Fi Communication

by 강우진 in Workshop > Tools

262 Views, 1 Favorites, 0 Comments

Security Sensor Through Human Body Detection Sensor and Wi-Fi Communication

KakaoTalk_Photo_2019-12-09-22-50-37.jpeg
KakaoTalk_Photo_2019-12-09-22-50-34.jpeg
KakaoTalk_Photo_2019-12-09-22-50-26.jpeg
KakaoTalk_Photo_2019-12-09-22-50-30.jpeg
KakaoTalk_Photo_2019-12-09-22-50-23.jpeg
KakaoTalk_Photo_2019-12-09-22-50-19.jpeg

Security sensor through human body detection sensor and Wi-Fi communication

Takuaz uses human body sensors and Wi-Fi communication to install at key points from the entrance to the trash discharge area, informing the outside of the house in real time to induce safe trash discharge.

First, we used the LOLIN D32 board, which supports Wi-Fi communication, to code the presence and absence of people in the human body sensor.

Here is the CODE :

import processing.net.*;

Server myServer; PImage myMap; color fill1, fill2, fill3; color sensed, unsensed; int s1time, s2time, s3time; int interval = 5000;

void setup() { size(800, 600); // Starts a myServer on port 5204 myServer = new Server(this, 1234); println(Server.ip()); myMap = loadImage("map.jpg"); sensed = color(255, 0, 0); unsensed = color(0, 0, 0); } void serverEvent(Server myServer, Client someClient) { println("We have a new client: " + someClient.ip()); }

void draw() { // Get the next available client Client thisClient = myServer.available(); // If the client is not null, and says something, display what it said if (thisClient != null) { String whatClientSaid = thisClient.readString(); if (whatClientSaid != null) { String ip = thisClient.ip(); println(ip + "\t" + whatClientSaid); if (ip.equals("172.16.20.63")) { fill1 = sensed; s1time = millis(); } if (ip.equals("172.16.20.216")) { fill2 = sensed; s2time = millis(); } if (ip.equals("172.16.20.131")) { fill3 = sensed; s3time = millis(); } } } ////////////////// // 화면에 지도 표시 // 화면에 센서의 위치/작동상태 표시 //////////////////

image(myMap, 0, 0, width, height); if (s1time + interval < millis()) { fill1 = unsensed; } if (s2time + interval < millis()) { fill2 = unsensed; } if (s3time + interval < millis()) { fill3 = unsensed; }

fill(fill1); ellipse(179, 269, 15, 15);

fill(fill2); ellipse(146, 462, 15, 15);

fill(fill3); ellipse(654, 222, 15, 15); //println(mouseX, mouseY); }

Then we ran the processing inside the Raspberry Pi, and we designed the Raspberry itself to collect the signals from the D32 board.

Here is the CODE :

/*
* This sketch sends a message to a TCP server * */

#include #include

WiFiMulti WiFiMulti; #define SENSOR_PIN 27

bool sensor_val; bool old_sensor_val; bool flag_event;

void setup() { pinMode(LED_BUILTIN, OUTPUT); pinMode(SENSOR_PIN, INPUT); Serial.begin(115200); delay(10);

// We start by connecting to a WiFi network WiFiMulti.addAP("SSID", "password");

Serial.println(); Serial.println(); Serial.print("Waiting for WiFi... ");

while(WiFiMulti.run() != WL_CONNECTED) { Serial.print("."); delay(500); }

Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP());

delay(500);

sensor_val = digitalRead(SENSOR_PIN); old_sensor_val = sensor_val; flag_event=false; }

void loop() { sensor_val = digitalRead(SENSOR_PIN); if (sensor_val != old_sensor_val) { flag_event = true; old_sensor_val = sensor_val; digitalWrite(LED_BUILTIN, !sensor_val); Serial.print("LED control : "); Serial.println(sensor_val); }

if ((flag_event == true)&&(sensor_val==true)){ // detected event

flag_event = false; const uint16_t port = 80; const char * host = "192.168.1.155"; // ip or dns Serial.print("Connecting to "); Serial.println(host); // Use WiFiClient class to create TCP connections WiFiClient client; if (!client.connect(host, port)) { Serial.println("Connection failed."); Serial.println("Waiting 5 seconds before retrying..."); delay(5000); return; } client.print("moving object detected"); int maxloops = 0; //wait for the server's reply to become available while (!client.available() && maxloops < 1000) { maxloops++; delay(1); //delay 1 msec } if (client.available() > 0) { //read back one line from the server String line = client.readStringUntil('\r'); Serial.println(line); } else { Serial.println("client.available() timed out "); } Serial.println("Closing connection."); client.stop(); Serial.println("Waiting 5 seconds before restarting..."); delay(5000); } else { flag_event = false; } }