I'm looking for an expert in Arduino development for a robotics project.
What I have:
I have created a security system using diode lasers and LDR sensors, acting as a sort of tripwire. The project is working perfectly so far, and I only need help enhancing it. As of right now, the system can be disengaged (green light) and engaged by pressing a button (light turns red). When that happens, if the laser is cut off from the direct beam onto the LDR, an alarm sounds and has to be reset by holding down the button. Cutting off the laser's path when the system is disengaged (light is green) will have no effect. (Everything is shown in the video below.).
I also have 3D-printed turrets using a 3D printer, laser diode, and microservo (SG90). Below is the exact type of turret I have. I will explain what I want to do with the turrets in a second.
What I need:
I want to modify the code and the circuit to add two more LDR sensors with lasers pointed at them, for a total of three 'tripwires'. I could use three Arduinos, but that is too many resources considering that I'm sure they can all fit into one. All of the lasers are 5V, but I connected them all to a battery, so they aren't connected to the Arduino and will simply shoot a laser until I disconnect the battery. In regards to the turrets, they are connected by one servo motor moving the x-axis and one on the y-axis. When the light is green (disengaged), I want them to be pointed upwards, and when the traps are engaged (red), I want them to orient themselves to point in the direction where the specific tripwire was triggered. I will have the tripwires connected perpendicularly so they cover both sides of a room and one down the middle. Do not worry about the exact position of where the turret goes (because I will change the values manually to where I want them once I set everything up), so please just make sure the text works in that way so all I have to do is change the amount each servo has to turn when the trap is triggered. So far, the circuit and code must be able to support 3 LDR's with lasers pointed straight at them and 3 turrets that are able to be disengaged and go into 'engaged' mode (with adjustable positions when engaged). Finally, I want to replace the button to engage and reset the circuit once a laser is broken with a keypad. I will provide below the exact keypad I'm using. The keypad should be configurable to change the password. The engage and dissengage codes should be different, one being the 'arming' code to make it go from disengaged to engaged, and one being the 'turn off' code, disabling the alarm and re-putting the turrets into disengaged mode when triggered.
To sum up:
I need a diagram that shows the connections from the Arduino to the breadboard and all the connections. The circuit and code must have three separate LDR's that are all able to be tripped, and once any of them are tripped, the system goes into alarm mode. However, each LDR needs to be separate from each other as the turrets (who should be aiming straight up when the system is not in alarm mode) need to know which laser was tripped to then be able to aim in that direction. Finally, the alarm needs to be continuous until I enter a predetermined 'turn off' code into the keypad, and when I enter it, it will be disengaged. Entering 'arming' the code again will reengage the trap.
Heres a video on the exact turret i'm using, so the connections will be the same:
[login to view URL]
Below is a video of all the things working and a wire diagram, keep in mind the lasers are connected to a battery only so they are separate from the arduino and can be placed anywhere at any range.
Here is my code:
const int triggeredLED = 7;
const int triggeredLED2 = 8;
const int RedLED = 4;
const int GreenLED = 5;
const int inputPin = A0;
const int speakerPin = 12;
const int armButton = 6;
boolean isArmed = true;
boolean isTriggered = false;
int buttonVal = 0;
int prev_buttonVal = 0;
int reading = 0;
int threshold = 0;
const int lowrange = 2000;
const int highrange = 4000;
void setup(){
pinMode(triggeredLED, OUTPUT);
pinMode(triggeredLED2, OUTPUT);
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
pinMode(armButton, INPUT);
digitalWrite(triggeredLED, HIGH);
delay(500);
digitalWrite(triggeredLED, LOW);
calibrate();
setArmedState();
}
void loop(){
reading = analogRead(inputPin);
int buttonVal = digitalRead(armButton);
if ((buttonVal == HIGH) && (prev_buttonVal == LOW)){
setArmedState();
delay(500);
}
if ((isArmed) && (reading < threshold)){
isTriggered = true;}
if (isTriggered){
for (int i = lowrange; i <= highrange; i++)
{
tone (speakerPin, i, 250);
}
for (int i = highrange; i >= lowrange; i--)
{
tone (speakerPin, i, 250);
}
digitalWrite(triggeredLED, HIGH);
delay(50);
digitalWrite(triggeredLED, LOW);
delay (50);
digitalWrite(triggeredLED2, HIGH);
delay (50);
digitalWrite(triggeredLED2, LOW);
delay (50);
}
delay(20);
}
void setArmedState(){
if (isArmed){
digitalWrite(GreenLED, HIGH);
digitalWrite(RedLED, LOW);
isTriggered = false;
isArmed = false;
} else {
digitalWrite(GreenLED, LOW);
digitalWrite(RedLED, HIGH);
tone(speakerPin, 220, 125);
delay(200);
tone(speakerPin, 196, 250);
isArmed = true;
}
}
void calibrate(){
int sample = 0;
int baseline = 0;
const int min_diff = 200;
const int sensitivity = 50;
int success_count = 0;
digitalWrite(RedLED, LOW);
digitalWrite(GreenLED, LOW);
for (int i=0; i<10; i++){
sample += analogRead(inputPin);
digitalWrite(GreenLED, HIGH);
delay (50);
digitalWrite(GreenLED, LOW);
delay (50);
}
do
{
sample = analogRead(inputPin);
if (sample > baseline + min_diff){
success_count++;
threshold += sample;
digitalWrite(GreenLED, HIGH);
delay (100);
digitalWrite(GreenLED, LOW);
delay (100);
} else {
success_count = 0;
threshold = 0;
}
} while (success_count < 3);
threshold = (threshold/3) - sensitivity;
tone(speakerPin, 196, 250);
delay(200);
tone(speakerPin, 220, 125);
}
Type of keypad:
[login to view URL]
Thank you in advance