NerdFatherRJ
Published © GPL3+

Cockroach Laser Killer

Kill this terrifying bug at any distance with a laser ray! (Or dream about it...)

BeginnerShowcase (no instructions)18,289
Cockroach Laser Killer

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
LDR sensor
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
The 170 points breadboard
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Project Schematics

Code

Cockroach Laser Killer

Arduino
/*
Project - Interaction LDR x Servo
 */
#include <Servo.h>

Servo servo1;  // Servo object

int pinServo = 2;    // variable to store the servo position
int triggerPoint = 970; //trigger point to start servo
byte sensor = A0; 
int sensorValue;

void setup() {
  pinMode(pinServo, OUTPUT);
  servo1.attach(pinServo);  // attaches the servo pin  
  servo1.write(155);// tell servo to go to "up" position
  delay(200);
  pinMode(sensor, INPUT);
}

void loop() {
  sensorValue = analogRead(sensor);
    if (sensorValue > triggerPoint){
    servo1.write(75); // tell servo to go to "down" position
    delay(3000);
    servo1.write(155);
    delay(200);
    }
}//End loop

Credits

NerdFatherRJ
5 projects • 27 followers

Comments