Ilham Hizbuloh
Published

Smart Package Reception Box

An IoT smart package reception box and getting notification on telegram app

IntermediateProtip5 hours939
Smart Package Reception Box

Things used in this project

Hardware components

FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
DFRobot FireBeetle ESP32 IOT Microcontroller (Supports Wi-Fi & Bluetooth)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
LED (generic)
LED (generic)
×2
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×7
Male/Male Jumper Wires
×9

Software apps and online services

Arduino IDE
Arduino IDE
Telegram

Hand tools and fabrication machines

Tape, Double Sided
Tape, Double Sided

Story

Read more

Schematics

screenshot_(102)_od0OMSpatx.png

Code

Untitled file

C/C++
// Device libraries (Arduino ESP32/ESP8266 Cores)
#include <Arduino.h>
    #include <WiFi.h>
    #include "CTBot.h"


#include <Servo.h>
static const int servoPin1 = 5; //pin servo
Servo servo1;

int trigPin = 23;          //pin triger ultrasonik
int echoPin = 22;           //pin echo ultrasonik
long distance;
long duration;
int OPEN = 120;             //open angle
int CLOSE = 0;              //close angle
#define sensor 15           //pin infrared
#define led 18              //pin led 1
#define led2 19             //pin led 2

CTBot myBot;
String ssid = "xxxx";      //ssid WiFi
String pass = "xxxx";      //password Wifi
String token = "xxxxx";      //token bot telegram
const int id = 123456;          //id telegram


void setup()
{
  
  Serial.begin(9600);

  servo1.attach(servoPin1); 
  pinMode(led, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(sensor, INPUT_PULLUP);
  digitalWrite(led, LOW);
  digitalWrite(led2, LOW);
  servo1.write(0);
  Serial.println("Starting TelegramBot...");
  myBot.wifiConnect(ssid, pass);
  myBot.setTelegramToken(token);

  if (myBot.testConnection()) {
    Serial.println("Good Connection");
  } else {
    Serial.println("Bad Connection");
  }

  myBot.sendMessage(id, "Hello, Welcome to Bot Prototype Package Receiving Box");
  Serial.println("Pesan Terkirim");
}


void loop()
{
  TBMessage msg;
  Serial.println(distance);
  //Opening Door
  digitalWrite(trigPin, LOW);
  delayMicroseconds(1);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(1);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration*0.017;
  if(distance <= 30 && distance !=0){
  myBot.sendMessage(id, "Punten Paket, Mau buka pintu? /bukapintu");
  }

  //Sinyal paket diterima
  if (digitalRead(sensor) == LOW){
    digitalWrite(led, HIGH);
    delay(500);
    myBot.sendMessage(id, "Paket Telah Diterima... Tutup Pintu? /tutupintu");
    digitalWrite(led, LOW);
    delay(500);
    
    }
  if (myBot.getNewMessage(msg, "/bukapintu")) {
    servo1.write(OPEN);
    delay(100);
    digitalWrite(led2, HIGH);
    myBot.sendMessage(id, "Pintu dibuka");
  }else if (myBot.getNewMessage(msg, "/tutupintu")) {
    servo1.write(CLOSE);
    delay(100);
    digitalWrite(led2, LOW);
    myBot.sendMessage(id, "Pintu Ditutup");
  }
  

}

Credits

Ilham Hizbuloh

Ilham Hizbuloh

1 project • 2 followers

Comments