I've got 2 PIR's wired up to a Arduino UNO that also has a single Songle 5VDC coil SRD that when closed powers a 12V 10A powersupply for 10 meters of Blue LED's.
Apologies but I've read about not using Fritzing and I just started look at the others.
When motion triggers, the lights come on and i'm super happy. Except when they don't shut off
1st) Since the 12V/10A is fairly high, I have the 5V Gate connected to the Arduino 5V. Should I have a transistor there?
2nd) It seems one of the pins is always reading high, even when the PIR isn't plugged in. I hope i'm assuming write that I have a floating issue there. Should I be look at a pull-down? Grumpy recommended it for a FET but applicable here?
3rd) I had originally sought the help of others looking at mosfet's for this relay/switch problem, but I think I'm okay with the clicking switch. Is it safe and an acceptable solution?
I want to turn on the LED's when motion has been sensed by either PIR sensor. They both seem to work but now and again they trigger without motion.
PowerSupply - Unknown Brand
Relay - SongLe SRD-05VDC-SL-C
PIR - HC-SR501
I'll give a go at the schmatic diagram but I thought I would ask because i've heard others say the learning curve is steep for this software (Eagle)
Here is my code if it helps, but I think the questions are mostly hardware based.
/*
* PIR sensor tester
*/
// int ledPin = 11;Â Â Â Â Â Â Â Â // choose the pin for the LED
int switchPowerPin = 7;Â Â Â Â // the pin where the power switch is connecte
int motionPin1 = 12;Â Â Â Â Â Â // choose the input pin for 1st PIR motion sensor
int motionPin2 = 13;Â Â Â Â Â Â // choose the input pin for 1st PIR motion sensor
int pirState = LOW;Â Â Â Â Â Â // we start, assuming no motion detected
int val1 = 0;Â Â Â Â Â Â Â Â Â // variable for reading the pin status
int val2 = 0;Â Â Â Â Â Â Â Â Â // variable for reading the pin status
int countdownTimer = 0;Â Â Â Â // will be used as a countown timer to detect when motion has stopped
String strVal1 = "The Value of val1 is ";
String strVal2 = "The Value of val2 is ";
String strDisplayVal;
void setup() {
//Â pinMode(ledPin, OUTPUT);Â Â Â Â Â // declare LED as output
 pinMode(motionPin1, INPUT);    // declare sensor 1 input pin as input
 pinMode(motionPin2, INPUT);    // declare sensor 2 input pin as input
 pinMode (switchPowerPin, OUTPUT); //declade switch as output
 Serial.begin(9600);
}
void loop(){
 delay(5000);
 val1 = digitalRead(motionPin1); // read 1st PIR Pin value
 val2 = digitalRead(motionPin2); // read 1st PIR Pin value
 if (val1 == HIGH | val2 == HIGH)
{Â Â Â Â Â Â // outter if.... check if the input is HIGH
  // digitalWrite(ledPin, HIGH); // turn LED ON for diagnostics
  digitalWrite(switchPowerPin, HIGH); // turn power switch ON
  if (pirState == LOW) { // looks at previous state
   // we have just turned on
   Serial.println("Motion detected!");
   // We only want to print on the output change, not state
   pirState = HIGH;
   while (val1 == HIGH | val2 == HIGH) // this loop continues as long as the sensors say motion active
    { // start for loop
    delay(1000);
    // Serial.println("Sensor is on. Sleeping for a second");
    val1 = digitalRead(motionPin1);
    strDisplayVal = strVal1 + val1;
    Serial.println(strDisplayVal);
    val2 = digitalRead(motionPin2);
    strDisplayVal = strVal2 + val2;
    Serial.println(strDisplayVal);
    } // end while loop
   for (int countdownTimer = 0; countdownTimer < 15; countdownTimer ++) // start this function when val is LOW
   { // start for loop
    delay(1000);
    Serial.print(countdownTimer);
   } //end for loop
} // end outter if
  Â
 } else {
  // digitalWrite(ledPin, LOW); // turn LED OFF
  digitalWrite(switchPowerPin, LOW); // turn power switch OFF
  if (pirState == HIGH){
   // we have just turned of
   Serial.println("Motion ended!");
   // We only want to print on the output change, not state
   pirState = LOW;
  }
 }
}
Eagle has defeated me. I really don't understand the app, couldn't even find the GND Icon. Therefore this drawing looks like a powerpoint. Hopefully this helps.
Had to zip the .sch file as the forum wouldn't let me upload it as sch.
JimboZA:
I haven't had a proper look through your code but this: while (val1 == HIGH | val2 == HIGH) needs a double || not a single |
You are right. Totally missed that one. Interestingly though when I put the sensors in a small box to shield them, the relay wasn't triggered and both showed a value of 0.
Eagle has defeated me. I really don't understand the app, couldn't even find the GND Icon. Therefore this drawing looks like a powerpoint. Hopefully this helps.
Had to zip the .sch file as the forum wouldn't let me upload it as sch.
Yes, Eagle isn't very helpful to the absolute beginner but half an hour of reading tutorials should get you started. Here's my top-5 tips for Eagle:
The part libraries it comes with are difficult to use and you can never be sure that they are right. Download the Sparkfun Eagle library. This includes an "aesthetics" library with symbols like the nice page border, ground and 5V symbols.
The only other library I use is the Element14 "Arduino" library, which has footprints for all the major Arduinos.
If you're just doing a schematic as a drawing (I draw plumbing and pneumatics with it too) then it doesn't matter which part you pick from the library. Draw your own just using lines. But for anything that will end up as a real PCB, you do need to be careful picking a symbol which has a PCB footprint you want to use - for example, 0805 surface-mount resistors are easier to place by hand than 0603 resistors and it's work to change it after you've put it on the schematic.
Layers are important - on the PCB the obvious layers are the top and bottom copper but if you want a note or label to appear on the finished PCB, it must be on a "names" or "place" layer, for top or bottom. On the schematic, the layer determines the colour of the line - I use whatever layer I want when I need a purple line, then change the layer appearance for that schematic.
Making your own library parts is not difficult. Often I will copy a part from another library just to get the PCB pad layout, then draw my own symbol. The copy process is not at all intuitive. Open the library you want the part to go into, in the library editor. Then on the control panel, browse to the library you are copying from and select "copy" when you find the part. You can also use copy-paste within the actual drawings, which has its own clunkiness.
Eagle has defeated me. I really don't understand the app, couldn't even find the GND Icon. Therefore this drawing looks like a powerpoint. Hopefully this helps.
Had to zip the .sch file as the forum wouldn't let me upload it as sch.
Here's my top 5 tips on drawing neat-looking schematics. This is the kind of stuff that you learn in a first year engineering course. Most of these are conventions which can be broken any time, to make your drawing look neater.
Try and avoid line crossings. Every time a line crosses another, it makes it less clear what is connected to what.
Where lines join, NEVER join on a cross or plus (4 wires connected to one point.) This looks too much like a crossing instead of a joining. Always join on T-shaped intersections. If you have to join 4 wires, then make two T's.
Positive supplies point up. Batteries have the positive terminal (longer line) on the top. Negative supplies and ground (GND) point down. If a ground pin is on the 'top' of a chip, draw an upside-down U so that the ground symbol is the right way up.
Left-to-right flow used to be important: inputs on the left and outputs on the right. I don't follow this convention much at all. What is more important is isolating the functional blocks so that you don't have a lot of lines crossing the page and those that do are important connections between the blocks.
Name your wires. "Analog-In-1" "Temp-Sensor-Outside" or whatever. Put the names onto the wire at both ends. Now you don't need to show the middle part of the wire, so delete it. This is a really powerful technique for making a schematic neater and easier to understand.
This is really good for connectors. Place the connector symbol in a vacant corner of the page, draw short wires to it and label those wires. Now it is obvious when you are building the thing where 5V and GND are on that connector.
It doesn't have to look like the actual component layout. Often you will see a little group of capacitors off to one side. These are the 'decoupling' capacitors that go adjacent to every chip, stabilising power and ground. But they aren't important to understand the function of the chip, so they are kept away from the parts of the schematic which are relevant to the function.
With a computer doing the drawing, you don't have to be careful on initial layout. Just start placing components and wires. If it gets crowded, drag things around until the functional blocks are arranged with space between them.
Once in the "Add Part" window, you can search the libraries, for instance GND, use * for wildcards. If you are looking for GND, then search "GND". If you're looking for the Atmega328p, just search "328p:.
MorganS:
Is this more like what you were trying to draw? This schematic is not workable like it is, but it is my interpretation of your coloured boxes.
Yes, that's exactly right. Thank you. I will try to create another following your advise.
Few questions if I may
MorganS:
I use whatever layer I want when I need a purple line, then change the layer appearance for that schematic.
So this is the proper way to have a color coded line as opposed to just choosing the line tool and a color?
Is it okay to use a generic square with VCC, GND and sensor specific pins as opposed to trying to locate the correct model for that sensor? Some have pretty indiscernible part numbers.
MorganS:
5. Making your own library parts is not difficult. Often I will copy a part from another library just to get the PCB pad layout, then draw my own symbol. The copy process is not at all intuitive.
Will try that now. I expected to possible only ever use maybe 10 parts/shapes as the most common one.
A resistor image is the same but do you normally write a value on it to mark it when explaining to others?
I'll never create my own PCB so all of this advice here works perfectly for me. Thank you!
codlink:
Once in the "Add Part" window, you can search the libraries, for instance GND, use * for wildcards. If you are looking for GND, then search "GND". If you're looking for the Atmega328p, just search "328p:.
I found it just for some reason it kept beeping when I tried to insert it.
I'll definitely try to be proficient in this app if I'm going to ask questions in the future. Thank you
Hopefully the explanation of my objective is complete and with the help of MorganS, the drawing is there.
I'm trying to understand if I use a relay, do I still need the pull-down or is that MOSFET specific?
How can I know if I have a floating issue with the PIR sensors or is it a code error?
eeze:
I
1st) Since the 12V/10A is fairly high, I have the 5V Gate connected to the Arduino 5V. Should I have a transistor there?
2nd) It seems one of the pins is always reading high, even when the PIR isn't plugged in. I hope i'm assuming write that I have a floating issue there. Should I be look at a pull-down? Grumpy recommended it for a FET but applicable here?
3rd) I had originally sought the help of others looking at mosfet's for this relay/switch problem, but I think I'm okay with the clicking switch. Is it safe and an acceptable solution?
That drawing is incomplete. It doesn't have some of the parts you mentioned in your first post. I thought that the schematic you drew was relevant to the current state of the circuit, not yesterday's circuit.
What is high? What gate?
Which pin? Maybe you need a pulldown, but unlikely.
Here is all all the components
Arduino Uno
2 PIR's
1 SongLe SRD-5VDC
Power supply connected to the SongLe SRD-5VDC.
There are no other components in my setup, except maybe the LED's but does that matter? as I'm just concerned about the power coming into the 5VDC Relay. If it shows On (closed) that i'm good.
Regarding the questions
When I meant 'High' -- Poor wording choice. I mean because the voltage and amperage is higher than what the Arduino board can handle and is also dangerous at 12V/10A, should I have a transistor to avoid burning out the board or ?
Pin 12 seems to jump around a bit between 0 and 1. It could be the PIR itself but it seems to float...
What i was attempting to ask here (apologies as I'm still learning the vernacular here) -- I'm using the SongLe SRD-05VDC-SL-C Relay to switch a 12V/10A power in from a supply out to some LED. It seems to work.
In a previous question I had, it was recommended to use a MOSFET and that I should use a pull-down transistor prevent the coil from charging/triggering the switch to close.
My question is, is this relay equal to that of a mosfet (plus the bonus clicking sound) and do I need a pull down or other safety mechanism?
I've had another go at trying to diagram my question. In all honest, I'd be better off with a block diagram in powerpoint. It's like trying to learn to hold a pencil again. Urgh.
Sorry if this is pathetic, I barely know what i'm doing electronic wise let alone how to draw it, hence the reason i'm here asking for help.
You'll need to use something other than an Arduino pin to drive the relay. For parts, the most common is 1 NPN transistor, 1 base resistor and 1 diode for the coil.