Devices & Components
Arduino Nano
9V battery (generic)
Jumper wires (generic)
Resistor 10k ohm
LDR sensor
Breadboard (generic)
9V Battery Clip
SG90 Micro-servo motor
Software & Tools
Arduino IDE
Project description
Code
Cockroach Laser Killer
arduino
1/* 2Project - Interaction LDR x Servo 3 */ 4#include <Servo.h> 5 6Servo servo1; // Servo object 7 8int pinServo = 2; // variable to store the servo position 9int triggerPoint = 970; //trigger point to start servo 10byte sensor = A0; 11int sensorValue; 12 13void setup() { 14 pinMode(pinServo, OUTPUT); 15 servo1.attach(pinServo); // attaches the servo pin 16 servo1.write(155);// tell servo to go to "up" position 17 delay(200); 18 pinMode(sensor, INPUT); 19} 20 21void loop() { 22 sensorValue = analogRead(sensor); 23 if (sensorValue > triggerPoint){ 24 servo1.write(75); // tell servo to go to "down" position 25 delay(3000); 26 servo1.write(155); 27 delay(200); 28 } 29}//End loop
Cockroach Laser Killer
arduino
1/* 2Project - Interaction LDR x Servo 3 */ 4#include <Servo.h> 5 6Servo 7 servo1; // Servo object 8 9int pinServo = 2; // variable to store the servo 10 position 11int triggerPoint = 970; //trigger point to start servo 12byte sensor 13 = A0; 14int sensorValue; 15 16void setup() { 17 pinMode(pinServo, OUTPUT); 18 19 servo1.attach(pinServo); // attaches the servo pin 20 servo1.write(155);// 21 tell servo to go to "up" position 22 delay(200); 23 pinMode(sensor, INPUT); 24} 25 26void 27 loop() { 28 sensorValue = analogRead(sensor); 29 if (sensorValue > triggerPoint){ 30 31 servo1.write(75); // tell servo to go to "down" position 32 delay(3000); 33 34 servo1.write(155); 35 delay(200); 36 } 37}//End loop
Downloadable files
Project Schematics
Project Schematics

Comments
Only logged in users can leave comments