Flame detection circuit connected to the pololu robot controller.(atmel AtMega 328p) I am able to get the values from the ir sensor of flame detection circuit. I need to active an alarm when the value is, lets say = 100. I'm a little confused how can I do that using microcontroller... it dosn't output 5v, so I guess I need to use something that will work as a switch when microcontroller drives HIGH or LOW it would turn on/off the alarm circuit.
How you activate the alarm circuit will depend on the properties of the alarm, ie: what voltage does it need, how much current, can you activate it just by applying power or does it need an on signal command, etc etc…
I suggest you run a search for ‘transistor as a switch’, that should point you in the right direction.
I checked the AtMega328P datasheet, and it says that your digital outputs should be able to drive 4.2V at up to 40mA when using a 5V supply, which is plenty for a transistor. Since you’ve got a nice 555 timer controlling your alarm, you can add the transistor in place of the switch, so it can control power to the alarm. An alternative would be to put the transistor between the supply voltage and the reset pin, and use a pull-down resistor. This way the reset pin is held low unless the transistor is turned on, and then the 555 circuit will start operating, at least until the transistor turns off and the reset pin goes low again.
DDRC is the PortC data direction register - all you’re doing is changing that, you’re not actually changing what the output values are. I suggest you leave DDRC set to output on PortC pin 3, and just change the value of that pin.
if (avg2>45) PORTD |= 0B00000010; else PORTD |= 0B00000000;
i’m assuming 0B00000000 would turn it off? but for some reason it stays on. (avg2 has 2 values 42 is min and 127 is max) 127 means flame detected. I can see on lcd that the value is changing.
Nope, the command PORTD |= 0B00000000; will never do anything, ever. The operator ‘|=’ tells the micro to take the value you’re working with (PORTD in this case), use the OR function to combine it with the other operand (0B00000000 in this case), and then store the result back into the first value (PORTD again). Whenever you use OR to combine something with 0, you always get the original value back, ie: 0|0=0 and also 1|0=0. When you OR something with 1, you always get 1 as the result, ie: 0|1=1 and also 1|1=1.
The reason I suggested using PORTD |= 0B00000010; is because if you’re using the other port D pins for something else, this command won’t change them from their current value. You could just use PORTD = 0B00000010; to turn PD1 on, and PORTD = 0B00000000; to turn it off again, but both of those commands set the rest of port D to zero, and that might interfere with something else. The ‘opposite’ of PORTD |= 0B00000010; is really PORTD &= 0B11111101;.
If you use the command PORTD &= 0B11111101; then you’ll turn PD1 off, but the rest of port D will remain the same. Similarly to using OR, the AND function is basically the same thing in reverse, ie: 0&0=0 and 1&0=0 (using AND with 0 always results in 0) 0&1=0 and 1&1=1 (using AND with 1 doesn’t change the original value).
thanks for the nice thanks for the nice explanation… here is one more question… how can I change the output voltage? because it eather 0 or 4V I should probably use analog outputs…
In this example you only want ‘on’ or ‘off’ values, you don’t really want the alarm half-activated do you?
In any case, if you wanted to change the output voltage you can use an analog output, or a DAC chip to convert from digital to analog, or a resistor bridge DAC output, or a voltage divider, or a zener diode reference… tons of options, but you really need to have a clear idea of what you want in order to choose one.