Hello everybody!
I have a few questions for you guys! To start off, I am building a firework controller (for detonating a fireworks display safely). I have put this code together:
The code will be put on an At-tiny85 chip using an Arduino-Uno as isp. The purpose of this code is that when the controller is turned on (with a key-switch), an LED will blink for 4 times, indicating the power-up of the system. The only problem is that the code does the opposite (it blinks the led when the switch is off, not on) and the led blinks continuously, not only 4 times . How do I fix this?
Secondly, could I use a 555 timer chip. In other words, is it possible to make the 555 chip blink the led for only a determined amount of times, then stop?
Finally, if none of the above is possible, are there other ways of doing this.
Fixing the code means writing it conforming to your plans.
If you want to have a number of blinks, you should check to see that number of blinks has occured yet.
I can't seem to find you do that in this code.
You are checking to see pin 1 gets HIGH.
Are you sure it gets LOW ?
Use pull ups or pull downs.
If you use the internal pull up, saving yourself some external hardware, you should wire the switch to GND, and check for the pin to go LOW.
You do not need a 555 to do this, that would only complicate things.
Just one more question: The switch controlling the unit is using 12 volts DC. Can I pass 2 wires directly from the switch to the arduino (kind of in parallel with the circuit)? Can I wire-up a 5 volt voltage regulator so the voltage is only 5 volts instead of 12 going to the switch pin? If not, what can I do?
You can use a transistor switch configuration.
Also might be an example where a 6 volt zener diode could be used.
(Some NPN base emitters have a Zener voltage of 6 volts, but that's another story)
+12 switched---1K---Base of NPN transistor eg 2N2222---Emitter to GND of Arduino and GND of 12 supply.
Then
+5 Arduino---10K---Collector and a Arduino digital input pin.
Note when the switch is closed +12 switched turns on the transistor. The collector goes LOW and you look for a LOW in software which indicates the switch is closed.
Frank-duino:
But how do I wire it up? And what type of transistor do I use?
You are requiring a lot of spoon feeding for something that you could find out from google.
Here is a more "basic" tutorial. http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads
Your switch is put in place of the motor or load and you do not need the diode.
Well the thing is, there are technically two loads. I want to use the transistor kind-of as a relay, so the arduino can read the switch's state without getting damaged (because the switch is connected to 12 volts). So the load is the switch's power (12volts).