I need help writing a program for my Uno R3 for testing pruposes. I'd like to use the UNO to accomlish a few things: (Drawing supplied)
1.) Turn on a relay (digital output 8) that supplies power to a device I am testing. The test will be 20 seconds long. The UUT should turn on a switch after 10 seconds so I'll use a range between 8-12 seconds to read if the switch comes on or not. That switch will be between ground and Digital pin 2.
2.) After power is supplied to turn on the relay, start a timer to determine if the UUT turns on between Gnd and pin 2 for 10 seconds.
3.) If it was on for 8-12 seconds, turn on a green LED (Digital output 11) and if it falls outside 8-12 seconds, in other words, it fails the test - it turns on a Red LED (Digital output 12).
4.) use a pushbutton to reset then a seperate button to the run the test again. Push button 1 between Gnd and Pin 3. Push button between Gnd and Pin 4.
Any Help would be great - I have no starting code nor know where to begin. Thanks in advance!!!
You have no current limiting resistor on the base of Q1. Perhaps you meant to use R3 but it's in the wrong place.
Your LEDs are wired backwards.
It's a bad idea to operate the relay from the Arduino 5V supply and there is no freewheeling diode for back EMF.
For code look at the "digital" examples that ship with the IDE. You can find them in the "examples" tab.
Technically, you don't need a state machine to implement this, it would just make it more responsive - for example if you want to interrupt a test in the middle, with a button press. With straightforward sequential timing, once you start a timed operation, nothing else can happen.
Also, in your diagram you have a timing chart. But the input signal is exactly the same as the output signal. Why not just use a wire? Ha, I know you don't mean that. But the timing diagram is too far simplified to be useful.
Then why do you have a driver transistor at all? Also you can not run a 12V relay on 5V, obviously.
Also, please don't covertly go back and edit previous posts. It makes the responses seem strange. If you have a new drawing or some other information, post it in a new message.
The relay drive circuit is still all wrong because you haven't looked at the relay module very much.
RV, this is what happens when people go back and edit their posts. The responses seem stupid or inappropriate. I almost always point it out, as I did this time, in my previous message. In the original diagram, the base was connected directly to the Arduino output.