i've got project breadboarded using attiny85. input attiny output pir sensor. i've tried couple of sensors of 2 types have. standalone, senors work expected i.e. few millivolts low , apprx. 3.7v high. when pir output connected physical pin 3 (ide pin 4) high output of pir pulled low approx. 68 millivolts. i've tried 3 attinys; results same. i've swapped 1 of sensors didn't work attiny 1 working in project using nano , works fine in nano project. jumpering attiny input pin 3 5v while pir still connected same pin results in project working if pir output did go high , reading on pin 3 approx. 4.7v. can't understand why attiny pin pullng down output of pir. ideas? - scotty
code: [select]
int ldr_val = 0;
byte ldr_pin = a3;
byte led_pin = 2;
byte pir_pin = 4;
int ledpin[] = {
0, 1,
}; // pwm pins only
int ledstate[2]; // last state of each led
long randnumber;
boolean sense_dark = false;
unsigned long sense_dark_start = 0;
boolean dark = false;
boolean pir_detect = false;
void setup() {
pinmode (led_pin, output);
pinmode (pir_pin, input);
digitalwrite (led_pin, high);
delay(500);
digitalwrite (led_pin, low);
delay(500);
digitalwrite (led_pin, high);
delay(500);
digitalwrite (led_pin, low);
delay(500);
digitalwrite (led_pin, high);
delay(500);
digitalwrite (led_pin, low);
delay(500);
(int = 0; <= 2; i++) { // set each led pin output
pinmode(ledpin[i], output);
}
randomseed(analogread(0)); // seed rnd generator noise unused pin
(int = 0; <= 2; i++) { // init. each led random value
ledstate[i] = random(20, 201);
}
// put setup code here, run once:
//serial.begin(9600);
//serial.begin(9600);
}
void loop() {
dark_detect();
report();
pir_detect();
illuminate();
if (dark) {
(int = 0; < 2; i++) { // each led
analogwrite(ledpin[i], ledstate[i]); // set pwm value of pin determined previously
randnumber = random(-40, 41); // generate new random number , add current value
ledstate[i] += randnumber; // range can tweaked change intensity of flickering
if (ledstate[i] > 200) { // clamp limits of pwm values remains within
ledstate[i] = 200; // pleasing range pwm range
}
if (ledstate[i] < 10) {
ledstate[i] = 10;
}
}
delay(100); // delay between changes
}
else {
analogwrite(ledpin[0], 0);
analogwrite(ledpin[1], 0);
}
}
void dark_detect() {
ldr_val = analogread(ldr_pin);
if (ldr_val < 450) {
if (sense_dark == false) {
sense_dark_start = millis();
}
sense_dark = true;
}
else {
sense_dark = false;
sense_dark_start = 0;
}
if (sense_dark & ((millis() - sense_dark_start) > 10000)) {
dark = true;
//digitalwrite (led_pin, dark);
}
else {
dark = false;
//digitalwrite (led_pin, dark);
}
}
void illuminate() {
if (dark && pir_detect) {
digitalwrite(led_pin, high);
}
else {
digitalwrite(led_pin, low);
}
}
void pir_detect() {
pir_detect = digitalread (pir_pin);
//digitalwrite (led_pin, pir_detect);
}
void report(){
//serial.print("pot value = ");
//serial.println(pot_val);
//serial.print("dark adjustment = ");
//serial.println(dark_adjustment);
//serial.print("ldr value = ");
//serial.println(ldr_val);
//serial.print("sense dark start = ");
//serial.println(sense_dark_start);
//serial.print("sense dark= ");
//serial.println(sense_dark);
//serial.print(" dark= ");
//serial.println(dark);
//serial.print("millis = ");
//serial.println (millis());
}
try using
or use external 1k - 10k pullup resistor if stronger signal needed
https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/connecting-to-a-pir
code: [select]
pinmode (pir_pin, input_pullup);
or use external 1k - 10k pullup resistor if stronger signal needed
https://learn.adafruit.com/pir-passive-infrared-proximity-motion-sensor/connecting-to-a-pir
Arduino Forum > Using Arduino > General Electronics > ATTiny85 pin pulling input down
arduino
Comments
Post a Comment