Kamis, 29 Agustus 2024

COS REAPETER RADIO COMMUNICATION


 


Dasar dari rangkaian ini umumnya difungsikan untuk mengaktifkan switch PTT transmitter ketika receiver menerima signal dari pancaran dari transmitter pengguna lainnya (Reapeter) 😀

Sabtu, 29 Juni 2024


FAN RADIATOR TELEGWEMOS 2 WIFI


//*FAN RADIATOR TELEGWEMOS 2 WIFI*

//*IoT FAN PC - PROJECT ON JUNI 2024- Ide and Design Dunia_budi*

//*DATA TELEGRAM to GOOGLE SHEETS*

//*SETIAP 3 MENIT RELAY ON DAN OFF*

//*Per 15 menit notif to Telegram*

//*Version 1.2*LEBIH CEPAT

 

#include <ESP8266WiFi.h>

#include <WiFiClientSecure.h>

#include <UniversalTelegramBot.h>

#include <ArduinoJson.h>

 

// Wi-Fi settings

const char* ssid1 = "Indonesia1";

const char* password1 = "Rum4hku1";

const char* ssid2 = "MEDIA_BARU";

const char* password2 = "Tvri1234";

 

// Telegram settings

#define BOTtoken "12345678:XXxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

// isikan bot telegram groupmu

#define groupID "-100xxxxxxxxxxxxxxx"

 // isikan 

const char* googleScriptUrl = "https://script.google.com/macros/s/AKfxxxxxxxxxxxxxxx";

 

// Pin definitions for Lolin WeMos D1

const int relayPin = D1;  // GPIO5

const int ledPin = D2;    // GPIO2

 

// State variables

bool relayState = LOW;

bool ledState = HIGH;  // Start with LED off (active LOW)

unsigned long previousMillis = 0;

unsigned long previousLedMillis = 0;

unsigned long lastTelegramNotification = 0;

 

// Intervals

const unsigned long RELAY_INTERVAL = 3 * 60 * 1000; // 3 minutes

const unsigned long LED_INTERVAL = 1000; // 1 second

const unsigned long TELEGRAM_NOTIFICATION_INTERVAL = 15 * 60 * 1000; // 15 minutes

 

WiFiClientSecure client;

UniversalTelegramBot bot(BOTtoken, client);

 

void setup() {

  Serial.begin(115200);

  

  pinMode(relayPin, OUTPUT);

  pinMode(ledPin, OUTPUT);

  digitalWrite(relayPin, relayState);

  digitalWrite(ledPin, ledState);  // Turn off LED (it's active LOW)

 

  connectToWiFi();

 

  client.setInsecure(); // Use this for simplicity, but consider using a proper certificate in production

 

  sendTelegramMessage("Fan IoT PC active");

  sendToGoogleSheets("Fan IoT PC active");

}

 

void loop() {

  unsigned long currentMillis = millis();

 

  // Toggle relay every RELAY_INTERVAL

  if (currentMillis - previousMillis >= RELAY_INTERVAL) {

    previousMillis = currentMillis;

    toggleRelay();

  }

 

  // Blink LED

  if (currentMillis - previousLedMillis >= LED_INTERVAL) {

    previousLedMillis = currentMillis;

    blinkLed();

  }

 

  // Send periodic Telegram notification

  if (currentMillis - lastTelegramNotification >= TELEGRAM_NOTIFICATION_INTERVAL) {

    lastTelegramNotification = currentMillis;

    sendPeriodicTelegramNotification();

  }

}

 

void connectToWiFi() {

  WiFi.mode(WIFI_STA);

  WiFi.disconnect();

  delay(100);

 

  Serial.println("Scanning for Wi-Fi networks...");

  int numberOfNetworks = WiFi.scanNetworks();

 

  for (int i = 0; i < numberOfNetworks; i++) {

    String ssid = WiFi.SSID(i);

    if (ssid == ssid1) {

      WiFi.begin(ssid1, password1);

      Serial.println("Connecting to " + String(ssid1));

      if (waitForConnection()) return;

    } else if (ssid == ssid2) {

      WiFi.begin(ssid2, password2);

      Serial.println("Connecting to " + String(ssid2));

      if (waitForConnection()) return;

    }

  }

 

  Serial.println("Failed to connect to any Wi-Fi network");

}

 

bool waitForConnection() {

  int attempts = 0;

  while (WiFi.status() != WL_CONNECTED && attempts < 20) {

    delay(500);

    Serial.print(".");

    blinkLed(); // Blink LED while connecting

    attempts++;

  }

  if (WiFi.status() == WL_CONNECTED) {

    Serial.println("\nConnected to Wi-Fi");

    return true;

  }

  Serial.println("\nConnection failed");

  return false;

}

 

void toggleRelay() {

  relayState = !relayState;

  digitalWrite(relayPin, relayState);

  String status = relayState ? "Position Fan ON" : "Position Fan OFF";

  sendToGoogleSheets(status);

}

 

void blinkLed() {

  ledState = !ledState;

  digitalWrite(ledPin, ledState);

  Serial.println(ledState ? "LED ON" : "LED OFF"); // Debug output

}

 

void sendPeriodicTelegramNotification() {

  String status = relayState ? "Position Fan ON" : "Position Fan OFF";

  sendTelegramMessage(status);

}

 

void sendTelegramMessage(String message) {

  bot.sendMessage(groupID, message, "");

}

 

String urlEncode(const String &str) {

  String encodedString = "";

  char c;

  char code0;

  char code1;

  for (int i = 0; i < str.length(); i++) {

    c = str.charAt(i);

    if (c == ' ') {

      encodedString += '+';

    } else if (isalnum(c)) {

      encodedString += c;

    } else {

      code1 = (c & 0xf) + '0';

      if ((c & 0xf) > 9) {

        code1 = (c & 0xf) - 10 + 'A';

      }

      c = (c >> 4) & 0xf;

      code0 = c + '0';

      if (c > 9) {

        code0 = c - 10 + 'A';

      }

      encodedString += '%';

      encodedString += code0;

      encodedString += code1;

    }

  }

  return encodedString;

}

 

void sendToGoogleSheets(String status) {

  if (WiFi.status() == WL_CONNECTED) {

    String url = String(googleScriptUrl) + "?status=" + urlEncode(status);

    client.connect("script.google.com", 443);

    client.print(String("GET ") + url + " HTTP/1.1\r\n" +

                 "Host: script.google.com\r\n" +

                 "User-Agent: ESP8266\r\n" +

                 "Connection: close\r\n\r\n");

    while (client.connected()) {

      String line = client.readStringUntil('\n');

      if (line == "\r") {

        break;

      }

    }

    String response = client.readString();

    Serial.println(response);

  }

}

 


Jumat, 10 November 2023

4 PIR (motion sensor) with Arduino Uno

//Board   : Arduino Uno
//Design  : dunia_budi
//Test Report   : Ok-November 23-10


int pirPin1   = 2; // Pin sensor gerak
int relayPin1 = 7; // Pin relay
int pirPin2   = 3; // Pin sensor gerak
int relayPin2 = 8; // Pin relay
int pirPin3   = 4; // Pin sensor gerak
int relayPin3 = 9; // Pin relay
int pirPin4   = 5; // Pin sensor gerak
int relayPin4 = 10; // Pin relay
int relayState  = LOW;

void setup() {
  pinMode(pirPin1, INPUT);
  pinMode(relayPin1, OUTPUT);
  pinMode(pirPin2, INPUT);
  pinMode(relayPin2, OUTPUT);
  pinMode(pirPin3, INPUT);
  pinMode(relayPin3, OUTPUT);
  pinMode(pirPin4, INPUT);
  pinMode(relayPin4, OUTPUT);
  Serial.begin(9600);
}
void loop() {
  int motionState1 = digitalRead(pirPin1);
  int motionState2 = digitalRead(pirPin2);
  int motionState3 = digitalRead(pirPin3);
  int motionState4 = digitalRead(pirPin4);
  

if (motionState1 == HIGH) 
{
    Serial.println("Gerakan terdeteksi pada Sensor 1!");
    digitalWrite(relayPin1, HIGH);
    delay(5000);
    digitalWrite(relayPin1, LOW);

    
  }
  if (motionState2 == HIGH) {
    Serial.println("Gerakan terdeteksi pada Sensor 2!");
    digitalWrite(relayPin2, HIGH);
    delay(5000);
    digitalWrite(relayPin2, LOW);
   
  }
  if (motionState3 == HIGH) {
    Serial.println("Gerakan terdeteksi pada Sensor 3!");
    digitalWrite(relayPin3, HIGH);
    delay(5000);
    digitalWrite(relayPin3, LOW);
    
  }
  if (motionState4 == HIGH) {
    Serial.println("Gerakan terdeteksi pada Sensor 4!");
    digitalWrite(relayPin4, HIGH);
    delay(5000);
    digitalWrite(relayPin4, LOW);
    
  }
}

Rabu, 17 Mei 2023

MULTI SENSOR (DARK LIGHT & MOTION)





Rangkaian ini menggunakan 2 buah sensor yakni sensor cahaya dan sensor gerak. Cara kerja        rangkaian ini adalah; bila kondisi ruangan tempat modul multi sensor diletakkan dalam kondisi gelap atau kurang intensitas cahaya diruangan tersebut serta ada gerakan yang terdeteksi oleh PIR (Pasive Infra Red) maka rangkaian PIR akan memberikan perintah ke sensor cahaya untuk meng on relay dan  menyalakan lampu. Waktu on atau off delay nyala lampu dapat diatur pada trimpot di PIR motion sensor.

Dalam kondisi ruangan serta lingkungan dengan intesitas cahaya yang cukup mengenai modul terssebut serta ada gerakan yang terdeteksi oleh PIR sensor maka lampu tersebut tidak akan menyala, atau rangkaian LDR (sensor cahaya) tidak memberi perintah meng onkan relay/lampu.