Let's Make Robots!

activate alarm using microcontroller

I have 2 circuits:

1. flame detection

2. alarm circuit

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.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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.

yes I can use transistors, but my microcontrller can only output .4V. is it enough for a transistor to switch?

here is what i use for alarm: 5.gif


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.

here is how I try to make pin3 output 4.2 volts: 

if (avg2>90) // flame  detected

avg2 is the value of sensor after confersion.  it doesn't work..

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.

that is the most confusing part... I don't understand how to make specific port output 4 volts.


 DDRD |= 1 << PD1; // set PD1 as output


now, what value should I change to make PD1 output 4v? 


sorry for stupid questions :( 

There are a number of ways to do it, but you need to tell the 328P to change the value of the PORTD register so that the PD1 control bit is set to 1.

PORTD |= B00000010;     //Changes PD1 to 1, leave all the others alone.

thanks!! it worked.


if (avg2>45)
PORTD |= 0B00000010;
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 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..