First time poster and beginner, please have patience and I very much appreciate the help.
I have two Arduino nano boards communicating wirelessly through the HC-12. The transmitting nano has a Panasonic AMN34112 PIR sensor that turns on a simple LED on the receiving nano. This is working well.
The transmitting nano is also using a PWM to step up a TIP120 MOSFET that powers an 8W, 12v/1a LED illuminator.
The concept is this: When there is motion, the LED illuminator PWM continues to increment until it reaches it's max, like a slowly incrementing/decrementing security light. I get remotely notified by a single red led anytime there is motion detected.
My issue is when i connect the 12v power supply to the 8W LED illuminator, the motion sensor immediately goes high and stays high. When the 12v power supply is turned off, the motion sensor works as expected. I've isolated the PIR sensor from the MOSFET and any motion to avoid thermal affects and to confirm there is indeed no motion. I've tried two different 12v supplies (both are wall plugs).
I've done my best to create a schematic and provide my code for reference. I'm certain my code isn't perfect, but I don't know if code improvements will fix this issue.
Schematic:
Transmitting nano code:
#include <SoftwareSerial.h>
SoftwareSerial HC12(4, 3); // HC-12 TX Pin, HC-12 RX Pin
int PIRinput = 2; // choose the input pin (for PIR sensor)
int val = 0; // variable for reading the pin status
int noMotionCount = 0; // counter to check how long since no motion was detected
int noCurrent = 0; // no current until initializing complete
int startingCurrent = 2500; // lowest starting current value
int topCurrent = 8191; // highest allowable current value
void setup() {
DDRB |= (1 << DDB1) | (1 << DDB2); // Set ports
TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM11); // Fast PWM mode
TCCR1B = (1 << WGM12) | (1 << WGM13) | (1 << CS10); // Fast PWM mode, no clock prescaling possible
OCR1A = noCurrent; // Start PWM just below MOSFET turn on, start this as zero at first to increment and find out what value turns on the mosfet
ICR1 = topCurrent; // Set the number of PWM steps
Serial.begin(9600);
HC12.begin(9600); // Serial port to HC12
pinMode(PIRinput, INPUT); // declare PIR sensor as input
Serial.println("Calibrating the sensor");
delay(20000);
Serial.println("Calibration complete");
OCR1A = startingCurrent;
}
void loop(){
val = digitalRead(PIRinput); // read input value
if (val == HIGH) { // check if the input is HIGH
HC12.write(val);
Serial.print("Motion detected, incrementing current to: ");
OCR1A++; // Increase PWM setting
Serial.println(OCR1A);
//delay(5000);
noMotionCount = 0;
}
else {
HC12.write(val); // turn LED OFF
noMotionCount++;
if (noMotionCount > 49) {
if (OCR1A > 2500) OCR1A--;
noMotionCount = 0;
Serial.print("No motion, decrementing current to: ");
Serial.println(OCR1A);
//delay(5000);
}
}
}
Receiving nano code:
#include <SoftwareSerial.h>
SoftwareSerial HC12(11, 2); // HC-12 TX Pin, HC-12 RX Pin
int LEDout = 12;
void setup() {
Serial.begin(9600); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
pinMode(LEDout,OUTPUT);
}
void loop() {
while (HC12.available()) { // If HC-12 has data
int val = HC12.read();
Serial.println(HC12.read()); // Send the data to Serial monitor
digitalWrite(LEDout,val);
}
}
PIR spec sheet:
- NaPiOn series
a) Digital output Items---------------------------------------Symbol---------Specified Value
Rated consumption current (Stand by) Note)-------lw-----------------170μA ave.
Rated operating voltage------------------------------------Vdd---------------3.0VDC min. 6.0VDC max.
Output current (When detecting)-----------------------Iout---------------100uA
Output voltage (When detecting)-----------------------Vout--------------Vdd-0.5V
Circuit stability time-----------------------------------------Two---------------30s max