First, here is a simplified version of my code. I took out a few things that smooth out the operation of stuff just to see if I can narrow it down to what the problem is.
/* A motion sensor, when detecting motion, sends 3.3v to Pin 2
After getting input on pin 2, pin 3 will activate a motor for 1 second.
Then the program will wait designated time before activating the motor again.
*/
const int PIR = 2;
const int PUMP = 3;
const int RedLED = 1;
const int GreenLED= 4;
void setup()
{
//Red LED indicates wait time for sensor to calibrate.
pinMode(RedLED, OUTPUT);
pinMode(GreenLED, OUTPUT);
pinMode(PIR, INPUT);// initialize PIR sensor as an input
pinMode(PUMP, OUTPUT); //initialize the motor pump as an output
digitalWrite(RedLED, HIGH);
delay(15*1000); //wait 20 seconds to calibrate....
//Green LED indicates ready to fire.
digitalWrite(GreenLED, HIGH);
}
//Runs until shutting down. Wait for input, send output, wait designated time, repeat
void loop(){
//if sensing sensing movement activate pump
if (digitalRead(PIR) == HIGH){
//turn motor on
digitalWrite(PUMP, HIGH);
digitalWrite(RedLED, HIGH);
delay(1000);
}
if (digitalRead(PIR) == LOW)
{
//if not sensing movement do nothing
digitalWrite(PUMP, LOW);
digitalWrite(RedLED, LOW);
delay(50);
}
}
I originally used an if/else statement instead of two if statements...I just changed that too, but it still didn't work. In my attempts to troublshoot what I did was plug in an additional jumper wire in parallel with my pump output(ATTINY pin 3) and attached my multimeter red probe to that and the black to circuit ground. This was telling me I'm getting just a little over a volt coming out of pin 3 with no motion. When I wave my hand in front of the motion sensor the voltage on pin 3, output, climbs to about 1.25-1.33V. Not enough to activate my logic level mosfet, at least 2.5V I believe. The ATTINY should put out about 5V though. This is a brand new chip I just put in too. The other one did exactly the same thing with the same voltage. Any ideas what might be limiting this voltage output. I can only figure it's my code.
Oh ya, this worked with my Arduino before, if that helps....
red913:
This was telling me I'm getting just a little over a volt coming out of pin 3 with no motion. When I wave my hand in front of the motion sensor the voltage on pin 3, output, climbs to about 1.25-1.33V. Not enough to activate my logic level mosfet, at least 2.5V I believe.
Sounds like you're overloading the pin. What voltages do you see if you disconnect everything from that pin?
Do you need a voltage divider on the 3.3V output of the PIR into a 5V input on the Tiny85?
You have a capacitor connected between Tiny85 GND pin to GND, should this be between VCC and GND?
You have a capacitor connected between Tiny85 GND pin to GND, should this be between VCC and GND?
+1 to what Riva said. You have no DC circuit for power to the ATtiny.
so how does it light up the green and red LEDs then. Those work.
Also, it had power from the regulator and the tiny is grounded on the same and add everything else. I'm not sure why it wouldn't have a circuit for power.
I was only going by the schematic you posted, in which the tiny is not grounded in the way it should be. Physical pin 4 (GND) should be connected directly to ground (0V).
If you have found a reference design which has a capacitor in series with the GND pin, I would be interested to see it.
Riva:
Do you need a voltage divider on the 3.3V output of the PIR into a 5V input on the Tiny85?
You have a capacitor connected between Tiny85 GND pin to GND, should this be between VCC and GND?
THANKS!
So once I removed the capacitor I stumbled upon the fact that I have too much resistance in R2. The resistor inline with the ctrl wire coming out of the sensor. I was checking voltage on it with the multimeter by running the meter in parallel and noticed it would work with the meter plugged in and wouldn't work with the meter removed. So removing the resistor all together and making it a solid connection fixed the issue. I'm still going to put a resistor in there, I just need to run some ohm's law and figure out the right one. I think someone told me to put it in there just to make sure I don't overload the ATTINY.
But with the capacitor between gnd on tiny to circuit gnd nothing worked right. Removing the capacitor and resistor...fixed. Thanks again everyone else that helped point me in the right direction.
Most of the example circuits for the PIR don't use a resistor on CTRL but if you want to then put the 10K pulldown the other side of R2 and it (R2) stops working as part of a voltage divider and should just limit current as you want.