ballas43alfonsus_1501ryokuuyfirmaulana
Published © GPL3+

NoRats 1.0

When rat enters the trap, there's no turning back

IntermediateShowcase (no instructions)1,558
NoRats 1.0

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Male/Male Jumper Wires
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
IR Obstacle Sensor
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 2.2k ohm
×1
Metal Mouse Trap
×1
Power Bank
×1

Software apps and online services

Arduino IDE
Arduino IDE
Blynk
Blynk

Story

Read more

Schematics

Schematic

This is the schematic of the project

Code

Code

C/C++
The code for the project
#define BLYNK_PRINT Serial
#define ESP8266_BAUD 9600

#include <Servo.h>
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>

//Credentials for logging in to Blynk
char auth[] = "<Auth from blynk app>";
char ssid[] = "<Wi-Fi SSID>";
char pass[] = "<Wi-Fi password if protected>";

Servo myservo;

//Assigning ESP based on the port
SoftwareSerial EspSerial(2, 3); // RX, TX
ESP8266 wifi(&EspSerial);

//Assigning V4 as Virtual LED in Blynk App
WidgetLCD lcd(V4);

int ir_value;
int triggered;

//Receive input from Blynk App to reset the Servo Position
BLYNK_WRITE(V3){
  if(param.asInt() == 1 && triggered == 1){
    resetDetection();
  }
}

void setup()
{
  // Debug console
  pinMode(8, INPUT);  //Prepare pin 8 as Input for the IR Sensor
  pinMode (13, OUTPUT); //Prepare pin 13 as Output for testing purposes to light up the LED 
  Serial.begin(9600); //Set up the serial monitor using BAUD rate of 9600

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  //Connecting arduino to blynk using the defined credential above
  Blynk.begin(auth, wifi, ssid, pass);

  resetDetection();
}

//Checking the value from the IR Sensor
void irSensor(){
  ir_value = digitalRead(8);
  Blynk.virtualWrite(V0, ir_value);
}

//Check the servo position
void servoDetail(){
  Blynk.virtualWrite(V2, myservo.read());
}

//Return servo to default position at 0 degree
void resetDetection(){
  myservo.attach(12);
  myservo.write(0);
  
  servoDetail();
  delay(1);
  myservo.detach();
  
  triggered = 0;
  lcd.clear();
  lcd.print(0,0,"Ready");
}


//Move the servo when detecting an object and send notification to Blynk app
void moveServo(){
  if(ir_value == 0 && triggered == 0){
    myservo.attach(12);
    myservo.write(90);
    
    servoDetail();
    delay(1);
    myservo.detach();
    
    triggered = 1;
    Blynk.notify("Mouse trapped! Check immedietaly!!");
    lcd.print(0,0,"Not Ready");
  }
}

void loop()
{
  Blynk.run();
  irSensor();
  moveServo();
}

Credits

ballas43

ballas43

0 projects • 0 followers
alfonsus_1501

alfonsus_1501

0 projects • 0 followers
ryokuuy

ryokuuy

0 projects • 0 followers
firmaulana

firmaulana

0 projects • 0 followers

Comments