Arduino 120V AC Relay Example

I got tired of poking around with LCD drivers with my Arduino. Time for a quick project to mix it up…staring at a surge protector always puts 120V on my mind. As it turns out, I tore apart an old humidifier a while ago on my ‘workbench.’ Monday night is Katie’s reality TV night…time for something sweet.

Investigating duty cycles on this plastic fan:

fan hack

fan hack

I figured that I could horse around with my PowerSwitch Tail, and make it somewhat mimic a PWM 5V setup. I was curious how long I would have to ‘pulse’ the switch with juice to keep the fan constantly rolling. I started with it fully on, and kicked my ‘active’ duty cycles lower until I reached a nearly-continual state of motion. Pause for Arduino code snippet:

/*
PowerSwitch Tail Template

120V AC Driver w/ LED indicator

Joseph Swanson
2011 | http://swantron.com
*/

void setup() {
// declare pins (13, 7) for writing
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
}

void loop() {
// Fire relay / LED
digitalWrite(13, HIGH);
digitalWrite(7, HIGH);

// Configure for “on” time
delay (50);

// Kill relay / LED
digitalWrite(13, LOW);
digitalWrite(7, LOW);

// Configure for “off” time
delay (950);
}

Pause for a small small-video break:

As that code and vid indicate, 1/20th of a second is all it took to keep the fan rolling, with 19/20th of a second idle. Not bad. Not sure what the takeaway is, but that is something to mention.

Put that knowledge somewhere safe, provided the question of humidifier fan duty cycles should spring up.

14 thoughts on “Arduino 120V AC Relay Example

  1. 120 volts is for sissies. step up to 220 volts and do it big.

  2. I would really like to thank you very much for the work you have made in writing this post. 120V relays are cool.

  3. Awesome blog over here! Thanks for sharing this very usefull information. I will visit your blog again into a couple off days to check if you have some new articles.

  4. Very cool. I can see a ton of uses for 120 volts with the arduino.

  5. You lost me, friend. I mean, I imagine I get what youre indicating. I have an understanding of what you’re saying, but you just appear to have forgotten that you will find some other persons in the world who understand this stuff.

  6. Good job on this effort.

  7. The swan tron blog appears to get a sizable ammount of site visitors. How can you get traffic to this?

  8. We really like the code snippet that you posted. Where can we find the full source code so that we can start playing with our plastic fans too?