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.

thanks

Comment viewing options

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

yeah, that's what I've used until something blow out one of the motor control circuit

 

0J668.200.jpg?1248057868

pins M1B, M1A

so, only 1 motor is running now which is connected to M2B, M2A

no, i need it to run motors... and I obviosly need to control the voltage..so I have to use analog outputs.
You are probably better served using PWM to control the motors rather than using analog control.
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.

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!! it worked.

 

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.

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.

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 :( 

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.