ATTiny85 pin pulling input down

I’ve got a project breadboarded using an ATTiny85. An input to the ATTiny is the output from a PIR sensor. I’ve tried a couple of sensors of the two types I have. Standalone, the senors work as expected i.e. a few millivolts LOW and apprx. 3.7V HIGH. When the PIR output is connected to physical pin 3 (IDE pin 4) the HIGH output of the PIR is pulled low to approx. 68 millivolts. I’ve tried 3 ATTinys; results are the same. I’ve swapped one of the sensors that didn’t work with the ATTiny with one that is working in another project using a Nano and it works fine in the Nano project. Jumpering the ATTiny input pin 3 to 5V while the PIR is still connected to the same pin results in the project working as if the PIR output did go HIGH and the reading on pin 3 is approx. 4.7V. Just can’t understand why the ATTiny pin is pullng down the output of the PIR. Any ideas? Thanks - Scotty

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);
  for (int i = 0; i <= 2; i++) { // set each led pin as an output
    pinMode(ledPin[i], OUTPUT);
  }
  randomSeed(analogRead(0));     // seed the rnd generator with noise from unused pin
  for (int i = 0; i <= 2; i++) { // init. each led with a random value
    ledState[i] = random(20, 201);
  }
  // put your setup code here, to run once:
  //Serial.begin(9600);
  //Serial.begin(9600);
}

void loop() {
  Dark_Detect();
  Report();
  PIR_Detect();
  Illuminate();

  if (dark) {
    for (int i = 0; i < 2; i++) {             // for each led
      analogWrite(ledPin[i], ledState[i]);     // set the pwm value of that pin determined previously
      randNumber = random(-40, 41);            // generate new random number and add that to the current value
      ledState[i] += randNumber;               // that range can be tweaked to change the intensity of the flickering
      if (ledState[i] > 200) {                 // clamp the limits of the pwm values so it remains within
        ledState[i] = 200;                     // a pleasing range as well as the pwm range
      }
      if (ledState[i] < 10) {
        ledState[i] = 10;
      }
    }
    delay(100);    // the 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

pinMode (PIR_pin, INPUT_PULLUP);

or use an external 1K - 10K pullup resistor if a stronger signal is needed

Thanks for your response. Unfortunately your suggestion results in a constant HIGH at pin 3, regardless of the PIR output state. - Scotty

I guess you may have this type

where the output is switch high when motion is detected, then switches to high impedance (off) when no motion is detected. Please disregard my previous suggestion.

If this type, then this brings you back to the original problem. Are there pots that need adjusting? Are you sure your connections are correct? Are pins 1 and 3 are reversed?

Perhaps your sensor is an analog output type. In any case, it would be helpful if you could provide a link or datasheet to your PIR sensor.

This is the sensor.

Are there pots that need adjusting? Are you sure your connections are correct? Are pins 1 and 3 are reversed?

The sensor was temporarily installed in another project and worked fine.

I did see a sketch in the Learning section for a PIR sensor and a line in setup was digitalWrite(PIR_pin, LOW);. That had the same effect as not including that line. It’s like that pin is in a low state.

  • Scotty

Your link is general and covers various sensor types. For instance, in the link provided to the Parallax sensor, the pinout is different than what you are using.

Doesn't your sensor have a model# or part number labelled on it?
Can you provide a link to where you purchased it and/or can you provide a picture of it?
Does your sensor have a re-trigger jumper? If so, is it configured so that output is not in pulse mode?

Doesn't your sensor have a model# or part number labelled on it?

Yes, D-SUN.

Can you provide a link to where you purchased it and/or can you provide a picture of it?

This is the module I purchased.

Does your sensor have a re-trigger jumper? If so, is it configured so that output is not in pulse mode?

The sensor I am currently using does not have a jumper. Testing shows it to be in retriggerable mode.

I breadboarded a simple circuit with an ATTiny85, the PIR, an LED and resistor and ran this code:

byte led_pin = 3;
byte PIR_pin = 4;
boolean PIR_detect = false;


void setup() {
  pinMode (led_pin, OUTPUT);
  pinMode (PIR_pin, INPUT);
  digitalWrite(PIR_pin, LOW);
  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);
}

void loop() {
  PIR_detect = digitalRead (PIR_pin);
  digitalWrite (led_pin, PIR_detect);
}

Circuit works as intended; When the PIR is triggered, the LED illuminates.

Took the same ATTiny, reprogrammed the originally posted code and installed it in the original breadboarded circuit and the unwanted results remain. The expected HIGH from the PIR does not go above 100mV.

So verified that the ATTiny using the same input pin and pin configuration works. Verified that the PIR works as it should. Seems to be the code but the code is pretty simple and I can't see a problem in it. This is not making sense. Think I'll try not calling function(s) just to see if that makes any difference.

  • Scotty

Is the original breadboard "twin bus" type where both bus bars are separated in the middle?

Hi,
Does the signal still load down with the ATTiny removed from the circuit?

Tom… :slight_smile:

Is the original breadboard "twin bus" type where both bus bars are separated in the middle?

I'm using a half sized breadboard. The buses are continuous. There are jumpers connecting the buses on both edges of the board.

Does the signal still load down with the ATTiny removed from the circuit?

No.

  • Scotty

Aha! I did not stop calling a function or functions. What I did do was to comment out these lines of code in the loop:

/*for (int i = 0; i <= 2; i++) { // set each led pin as an output
    pinMode(ledPin[i], OUTPUT);
  }
  randomSeed(analogRead(0));     // seed the rnd generator with noise from unused pin
  for (int i = 0; i <= 2; i++) { // init. each led with a random value
    ledState[i] = random(20, 201);
  }*/

The circuit is functioning as desired; the PIR detects, the LED array turns on.

I suspect that this pin numbering ,for (int i = 0; i <= 2; i++), has gone too far.
I think it should be for (int i = 0; i <= 1; i++).

I’ll make the change and report back.

  • Scotty

Yep, that was the problem. The circuit is almost working as desired. There seems to be another problem in that the LED array is half lit when 'dark' is not detected and the PIR detects and fully lit when 'dark' is detected and the PIR detects. But that's something else to investigate and fix. At least the PIR function is now working, swinging from a few millivolts no-detcetion to approx 3.4V detection on the input pin to the ATTiny.

Thanks for your help guys. I Appreciate it. - Scotty