Introduction: Arduino Repeat Cycle Timer
This is an arduino based repeating cycle timer. The times are set in the sketch and cannot be modified during operation.
It is durable, reliable, simple and cheaper than a comparable unit.
This relay is rated for 10 amps. The relay will melt if you exceed the maximum load. a space heater, water pump or large fan will draw more current and should be used carefully.
Step 1: Arduino Repeat Cycle Timer
The parts list:
Arduino: 26$
http://www.canadarobotix.com/arduino-microcontroll...
1 Channel Relay: 5$
http://www.canadarobotix.com/mechanical-switches/1...
Project Box: 6$
http://www.walmart.ca/en/ip/lock-lock-800-ml-recta...
Re-purposed Xbox 360 cord: Free$
Cable Grip: 2.5$
http://www.digikey.ca/product-search/en/cables-wir...
Jumper wire kit: 13$
http://www.digikey.ca/product-detail/en/bud-indust...
Outlet: 1$
https://www.lowes.ca/building-supplies/electrical/...
I've used some risers for the relay and rigged my own risers for the Arduino from a Windex bottle straw and some nuts and bolts
Step 2: Install Into Box and Wire
i'd like to make a fancy wiring diagram with http://fritzing.org/home/ and add it here but....
The 12v wiring is
3.3v to VCC
Gnd to gnd
Pin 2 to IN
For the 120 v I've included a image of how I've wired the relay. you just run the common wire into the centre of the relay and then connect the N/C (normally closed) side of the terminal block to the outlet.
maybe ill update my Instructable with some diagrams in the future but for now this is what you get.
first I used a drill and file to create a hole for USB port and dc barrel jack to fit
second I marked the arduino's holes on the bottom of the project box for the risers to go into.
I've used a lighter and hair dry to soften the plastic when reaming or threading any holes to avoid the plastic cracking
I've also used a lighter the soften the risers into the plastic
I've also added a few air holes to allow heat to escape the box and used the cord grip to secure the power source the relay will get hot
I then used my dremel to cut the lid of the box to allow the 120v outlet fit.
Step 3: The Code
Here is the code
Change the offTime and onTime values to adjust the cycle times they are in milliseconds here's a link to a converter
https://www.google.ca/?ion=1&espv=2#q=minutes%20to...
I have plagiarized this code from other arduino projects and it works. the other project included multiple simultaneous functions and inputs this one does not.
I am aware of the the option to use delay instead of complex timer values and math.
13 Comments
8 months ago
Thank lot for this code...............
const int relayPin = 13;
unsigned int relayState = LOW;
long offTime = 1000;
long onTime = 5000;
unsigned long previousMillis=0;
void setup() {
// put your setup code here, to run once:
pinMode(relayPin, OUTPUT);
relayState = HIGH ;
digitalWrite(relayPin, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
long currentMillis = millis();
if ((relayState==LOW)&&(currentMillis-previousMillis>=offTime))
{
relayState = HIGH;// turn it on
previousMillis = currentMillis; // Remember the time
digitalWrite(relayPin, HIGH); // Update the actual relay
}
else if((relayState==HIGH)&&(currentMillis-previousMillis>=onTime))
{
//digitalWrite(RELAY, LOW);
relayState=LOW; // Turn it off
previousMillis = currentMillis; // Remember the time
digitalWrite(relayPin, LOW); // Update the actual relay
}
}
5 years ago
Great project. I really like the project box. For safety I might break the Black "HOT" cable through the relay instead of the White "Neutral"
Reply 5 years ago
what difference would it make ?
Reply 5 years ago
For safety reasons and I would change the normally close to the normally open connection and change the program with the inverse times as well
Reply 5 years ago
As someone who went to school to become an apprentice electrician, NEVER EVER switch a neutral. There is a good chance that if something goes wrong, YOU WILL DIE as the hot is still energized.
Reply 5 years ago
you will not die i'm a power engineer and i've been shocked enough times
Reply 5 years ago
It would make a difference between "DEAD or ALIVE"!!!!!! If you brake the "neutral" the "HOT/black" is still alive, and if you are gounded to something & touch that lead/black = DEAD YOU ARE!!!!
5 years ago
I think a 5v switched 120v solid state relay would be better for longevity and you could get a higher output capicity
5 years ago
But if you have taken a "doze" of say: 120VAC/60Hz @ 50mA, you wouldn''t be here among us writing your stupid messages, (there maybe a "heavenly" internet there through which you could communicate with us living people down here, please send me the "url to heaven", so I could communicate with THE GREAT MASTER OF UNIVERSUM himself) :) :)
5 years ago
1. You say "120V at 15A", 15Amps = 15,000mA. They estimate that You can't hold 120ACV with a Amperege of a 10mA, (READ 10milliamps), without damage. So Your 15A could kill about ~1,000 people at one stroke, (20mA/person)
2. It doesn't matter which side you "cut" your "load", the heat generated is allways the amount of power going thrue the wires. P=U*I => where P=power=Watt, U=Potential niveau difference=Volt, I=Current=Ampere. Wery often the the result of, (UxI), Power (W) results in "heat" (heaters), or in "motion" (motors)....etc.
5 years ago
Re: "what difference does it make?"
In the USA, it's the convention and required the National Electrical Code.
It's doubtful these low cost relay modules meet any electrical standards.
The below info is from a medical source. Skin resistance does play a roll.
1 mA;
Barely perceptible
16 mA; Maximum current an average man can grasp and “let go”
20 mA Paralysis of respiratory muscles
100 mA; Ventricular fibrillation threshold
2 A; Cardiac standstill and internal organ damage
15/20 A; Common fuse breaker opens circuit
5 years ago
This is an awesome Arduino timer.
5 years ago
This would be a really cool way to make a simple automation system.