I'm working on a project that requires 2 wires to be joined for less then 2 seconds in order to fire up a gasoline furnace. The input will be a the presence of 12v on a wire. Id like for the Arduino to check after a delay (30 minutes) to see if 12v is still present and if so join the 2 wires again for 2 second. The circuit should be pretty simple but all the example I see have to do with turning a momentary input into a steady state output.
Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.
Hello
That is a nice task.
Do you have experince in coding?
Post your current sketch well formatted, with comments and in code tags to see how we can help.
Have a nice day and have fun in coding C++.
I've coded a few things nothing major. I've never posted in this forum before, but have used it for ideas and to learn. I'm a beginner and I'm having trouble finding a good starting point for this.
I don't need help with wiring. I just need a good starting point for code. I've thought about this more and what I really need to be able to do in code is detect change, and when change is detected, have two pins behave as a momentary switch.
You are missing the point, we need help understanding your project, your wiring and we need to see your attempt at getting the code to work with the hardware.
The more information we get the more effective we can be at helping you.
Take a view into the IDE to find alot of coding examples.
As I write the encoding, see if this circuit meets your need.
Note:
All GNDs in the image need to be interconnected.
RV mineirim
You forgot the relay. Your switch seems to just short circuit the 12V supply.
By the way, that is not possible. This suggests that you do, in fact, need help with the wiring.
Now there's the relay.
RV mineirim
It's better to give the relay LED indicator its own resistor to 5V - the combined voltage drop of some LEDs, plus the optoisolator voltage drop, might exceed 5V.
This part of the relay from the IN pin I captured from the scheme of commercial relay modules available on the web.
RV mineirim
Hi @newshuttle
I didn't test it, I just compiled it.
See if this is what you need.
RV mineirim
#define Presence12V 2 // Pin for 12V detect
#define startBt 7 // Pin for start button
#define furnace 8 // Pin for furnace relay
unsigned long tempStart = 0; // Mark start time
unsigned long tempRepeat = 0; // Mark repeat time
unsigned long countUp = 0; // Control start button prest
bool flag = false; // Enable disabel furnace
//--------------------------------------
void setup() {
pinMode(startBt, INPUT_PULLUP); // Start button as INPUT mode Pullup resistor turned On
pinMode(Presence12V, INPUT); // Start button as INPUT mode
digitalWrite(furnace, HIGH); // Turn off furnace relay
pinMode(furnace, OUTPUT); // Furnace as output mode
}
//--------------------------------------
void loop() {
tempStart = millis(); // Refresh tempStart
if ( flag == false) // If not enable furnace time
{
while (digitalRead(startBt) == LOW) // While startBt is pressed
{
countUp = millis() - tempStart; // Refresh countUp
tempRepeat = millis(); // Refresh tempRepeat
if (countUp > 2000) // If countUp bigger 2000 2 seconds passed
{
flag = true; // Informe 2 seconds pass
}
}
}
if (Presence12V == HIGH and flag == true) // If 2 seconds pass and there is 12V
{
digitalWrite(furnace, LOW); // Fire furnace
}
if (Presence12V == LOW) // There is no 12V
{
digitalWrite(furnace, LOW); // Turn off furnace
flag = false; // Disable furnace time
}
if (tempRepeat > (60000ul * 30ul) and Presence12V == HIGH ) // Time 30 min or more ad there is 12V
{
flag = false; // Disable furnace time
}
}
(60000 * 30ul)
This is incredible! As I've thought about it, I do not need a timer as the two wires I'm essentially shorting together for a short period of time go to the Espar EasyStart timer, which in turn sends a signal (I believe LIN Bus but I'm not sure)to the furnace to fire.
I can set the default run timer to as long as I need to so all I truly need is for the code to turn off or on the furnace (by shorting the two wires for less then 2 seconds)
I'll probably use your wiring diagram, but delete the start button, and use "Wire 1" and "Wire 2" in your diagram to energize the coil of a 5v relay with the switched portion wired to the 2 wires that need shorted.
I have a few questions
- can I use a pin from the Arduino to provide +5v at R1 at the optocouple?
- are the resistors and zener necessary at the relay?
I've used your code and the StateChangeDetection example to make this
Thanks so much! I hope I didn't butcher good code!
#define Presence12V 2 // Pin for 12V detect
#define furnace 8 // Pin for furnace relay
int Presence12VvCounter = 0; // counter for the number of state changes
int Presence12VState = 0; // current state of the 12v
int lastPresence12VState = 0; // previous state of the 12v
//--------------------------------------
void setup() {
pinMode(Presence12V, INPUT); // Start button as INPUT mode
pinMode(furnace, OUTPUT); // Furnace as output mode
digitalWrite(furnace, HIGH); // Turn off furnace relay
}
//--------------------------------------
void loop() {
Presence12VState = digitalRead(Presence12V);
if (Presence12VState != lastPresence12VState) // something changed
{
Presence12VvCounter++;
Serial.print("Presence12V changed");
Serial.println(Presence12VvCounter);
digitalWrite(furnace, LOW); // fire furnace
delay(1500); //proper "button push" time
digitalWrite(furnace, HIGH); //end "button push"
}
else {
digitalWrite(furnace, HIGH);
}
{
delay(50);
}
lastPresence12VState = Presence12VState; // save the current state as the last state, for next time through the loop
can I not set a pin low, delay for some time, and then set it high?
I realize that I may have come off as arrogant. I apologize. I owe you a schematic, thanks for your help. should I download something to make a readable one? or just draw it out?