Hello all, I have recently began a hobby with arduino! Unfortunately when I ran a traffic department for a municipality. I had software that made life a bit too easy. If I had a problem with a pin. I could just copy its functions to a spare pin and do the hardwiring in the cabinet. With one of the extra pig tail wires. So the municipality never trained me on scripting. I have found the reference section, under help in the Arduino software. It has helped greatly. I have started with a basic script. The origional script was from an example I found online. Then I researched to understand the purpose of the script used and changed it. Again it is just the bare basics, until I get it right. My next project will be researching and adding a RTC to the board. My project is for a aquarium controller. My delema I am currently facing is, I believe, I may have exceeded the limits of delay on my nano. Can the delays be used as a timing function? From what I have researched, the delay can keep counting up to ~50 days. So I figured I could use it to get a basic 24 hour outlet timer. I tried it and in my script where relay2 turns off, relay1&3 turned off for a second and came back on? I am trying the script again. I used the auto format in the arduino software first this time. Would my scetch work properly for what I have it listed as? I do not know if it was the delays causing the problem or if I had some sort of conflict/bug type thing. If theoretically my script should work. I will start researching how to add the RTC and use a better method to time the relays. Eventually I want to use my nano, Ethernet shield, RTC,16x2 display and some type of shield I baught, that is supposed to connect or drive LEDs. My display has the buttons too. So needless to say, I have a lot to learn about scripting. lol Here is my script! My first one! lol Should it work? Or am I testing the delay use and that would be a bug? Thank you in advance, if someone answers!
Since the pins default to INPUT, you are turning the internal pullup resistor off before setting the pin to be an OUTPUT pin. You are NOT making certain that the pin is off. You need to set them as output first, then turn them off (though that really isn't necessary, since they default to off).
delay(3600000);
Literals are interpreted as ints. That doesn't look like an int. Add UL to the end, to tell the compiler to interpret it as an unsigned long, instead of an int.
Thank you for the reply! I was under the belief that, it was as simple as if I put in a delay. That it would just default to counting millis. I will research the term you mentioned and see how int would relate to either delay or millis. Origionally I had relay 2 on pin d3 of the Arduino. Then found out it was a PWM pin. So I switched it to 7. When I woke up, it seemed to be in the proper spot in the script. I did not see if relay1&3 turned of and came back on this time. So I am tryin g it again. When you mention making sure the pin is off..... Would using the HIGH/LOW wording be better? The the 0&1 , you are saying is for the pullup?
I got this method from the basic blink example in the Arduino software. Would it be better?
int Relay1 = 2;
int Relay2 = 7;
int Relay3 = 4;
void setup() {
pinMode (Relay1, OUTPUT);
pinMode (Relay2, OUTPUT);
pinMode (Relay3, OUTPUT);
digitalWrite(Relay3, HIGH);
delay(5000);
}
If it worked then your program would leave the Relay3 pin HIGH as it is never taken LOW. Is that what you want ?
As to whether it will work. Did you read what PaulS said about literal values being interpreted as ints and his suggestion as to how make the be regarded as unsigned longs ?
Can I suggest that you write the millis() value to the serial monitor when the delays in your program finish. That way, even if you are asleep you will know that they happened.
Yes, for now Relay3 is supposed to be always on. I have actually been researching unsigned longs. Since it was recommended. Then came back here to check for replies. Seems like unsigned longs are related to if and else statements. Currently I am trying to figure out how to write a timeout with if and else statements. I see the examples, but have been trying to understand the type of wording, instead of just copying and pasting. Then changing the values. Arduino's help page recommends becoming familiar with c++. That would probably help. Thank you for the replies! I am sure the recomendation will help! Give me a bit of time to research and understand that part of scripting and I will reply, what you already know, that it will work! lol Origionally when relay1&3 came off with relay2. Relay3 was not in setup. I was trouble shooting to see if then only relay1 would be affected. If I put relay3 outside the loop. I will look into serial monitoring the Arduino as well. Thank you for the recommendation. It would be nice, if the money I spent on these parts could keep me learning for awhile. As it is what I was looking for, a hobby!
Seems like unsigned longs are related to if and else statements.
Wrong, I am afraid.
unsigned longs are just a type of variable. They allow longer (larger) integers to be stored than an int and being unsigned are always positive. Look at the data type pages on here Arduino - Home for an explanation of the range of values that each data type can hold.
I compiled this in the software and it looks good. Before I load it in my Arduino. Does this look correct? Or would all the variables need to be listed as time? I ask becouse, I origionally listed Relay2 twice and it returned an error. Then described what the unsigned long was for each time (instead of just the relay coming up next). Then the software accepted it.
unsigned long time;
int Relay1 = 2;
int Relay2 = 7;
int Relay3 = 4;
void setup() {
pinMode (Relay1, OUTPUT);
pinMode (Relay2, OUTPUT);
pinMode (Relay3, OUTPUT);
delay(5000);
digitalWrite(Relay3, HIGH);
delay(3000);
}
void loop() {
digitalWrite(Relay1, HIGH);
unsigned long Relay2 = 360000;
digitalWrite(Relay2, HIGH);
unsigned long Relay2off = 25200000;
digitalWrite (Relay2, LOW);
unsigned long Relay1off = 360000;
digitalWrite (Relay1, LOW);
unsigned long Relay1backon = 54000000;
Go back to the code you had in reply #3. All you need to do is add the UL suffix to your delays as suggested, like this:
delay(3600000UL);
Testing it's going to be a bit tedious though - you might want to make them a bit smaller.
Later I suspect, you'll want to move away from the use of delay. Right around the time you try to read the buttons on the LCD. When that time comes, as usual, look at the Blink without delay example that comes with the IDE.
That makes sence! Thank you. I was under the interpretation the UL replaced the entire delay wording. Sort of like making a countdown. Instead of a duration.
And yes Wildbill! I eventually do want to get away from delays. Maybe that is why my mind went to trying to figure it out without the word delay even in the script. I read that delays will mess up communication I do have a RTC, Ethernet shield, 16x2 display with buttons, an extra nano and another part. That is supposed to free up some pins for the display and can direct drive LEDs. Thank you once again everyone for the replies! I am going to need some time to process information that was given to me. Once I understand the UL. My next project will probably be researching incorperating the Ethernet shield and the display. I have the extra nano incase I need to use it as a slave for more output pins. Eventually, I will incorperate the rest of the 8relay strip I have. For dosing pumps and control of circulation pumps. I want to do a bit of research first. To understand the information given first though. Thanks again. I included a pic of my aqaurium, I am trying to make the controler for.
I ended up going with my first sketch posted and added UL, like recommended. I uploaded one of the other sketches and was like; huh? lol that isn't right. lol Ofcourse once I started to get close to the point of relay2 turning back off. Ohio weather decided to knock us with a snow storm. The whole condo developement where I live, kept having real quick power outages. So I made a redneck type backup power supply for now. My car jumper charges by a.c. and has a d.c. power supply, in the form of an outlet similar to a cigarette lighter in a car. Then my nieghbor was nice enough, to drop off a pile of resistors!!! So I can use them when needed during my project. I can go through the pile with my multi meter and sort them out. While waiting for the timing cycle. Forgive the ugly wiring. I am just doing temperary wires for now. I am sure I will have to move pins or something, while adding more shields I just dont want to move to the next step until I know this will work. I have a belief this project will take me about a year! lol First, I need to get better at electrical sketching. lol It is a good inexpensive hobby though.