DETAILED DESCRIPTION
It is a simple attiny project for detecting tunder and shoot with a camera under 50ms. It's a really sensitive stuff. Based on light changeing, not the light strenght. It can detect a shadow, if you want.
The attiny/arduino code:
#define SHOT_PIN 1 //shoot pin
#define SENSITIVITY A3 //sensitivity pin potentiometer
#define LIGHTSENSOR_PIN A2 //a photoresistor pin
#define MAXINCREMENT 10 //smoothing
unsigned long timer = 0;
int soothArray[MAXINCREMENT];
int increment = 0;
int total = 0; // the running total
int average = 0; // the average
bool isOn;
int lastRelevant;
void setup() {
timer = millis();
lastRelevant = 0;
isOn = false;
pinMode(LIGHTSENSOR_PIN, INPUT); //beállítom bemenetire a késleltetés potméter pinjét
pinMode(SENSITIVITY, INPUT); //beállítom bemenetire a késleltetés potméter pinjét
pinMode(SHOT_PIN, OUTPUT); //beállítom kimentre a gyujtó relay pinjét
digitalWrite(SHOT_PIN, HIGH);
delay(500);
digitalWrite(SHOT_PIN, LOW);
delay(500);
digitalWrite(SHOT_PIN, HIGH);
delay(500);
digitalWrite(SHOT_PIN, LOW);
//Serial.begin ( 115200 );
for (int i = 0; i < MAXINCREMENT; i++)
{
int lsv = analogRead(LIGHTSENSOR_PIN);
soothArray[i] = lsv;
total += lsv;
}
}
void loop() {
unsigned long now = millis(); // a loop starting time
total -= soothArray[increment];
int lsv = analogRead(LIGHTSENSOR_PIN); //reading photoresistor value
int sens = analogRead(SENSITIVITY); //reading sensitivity
sens /= 2;
soothArray[increment++] = lsv;
total += lsv;
average = total / MAXINCREMENT;
// Serial.print ( "LIGHTSENSOR: " );
// Serial.print ( average );
// Serial.print ( "SENSITIVITY: " );
// Serial.println ( sens );
if (increment >= MAXINCREMENT)
{
increment = 0;
}
if (timer + 50 < now && !isOn) {
if (lastRelevant - sens > average) {
digitalWrite(SHOT_PIN, HIGH);
isOn = true;
}
timer = now;
lastRelevant = average;
}
if (timer + 2000 < now && isOn) { //turn off shooting after 2 mp
digitalWrite(SHOT_PIN, LOW);
isOn = false;
timer = now;
lastRelevant = 0;
}
}
Authors
- /
- Active Participants
Components & Releases
Fabricate
Delete release
Are you sure you want to delete this Release?
This action cannot be undone.
Unable to download from CircuitMaker
You cannot download files inside CircuitMaker.
Please, open this page in browser and download file from there.
To copy hyperlink, press Ctrl+C with selected text below:
Comments ()