Controlling 220v using arduino relay board

Sumber : http://browse-tutorials.com/tutorial/controlling-220v-using-arduino-relay-board

Controlling 220v using Arduino relay board

This guide shows how to control 220 / 230 V using relay board. This is very general relay board, you can find it in ebay, amazon and even in some local stores. This is a general board 5v relay that can control 250V AC, 125V AC, 30V DC or 28V DC. I live in Europe so my household electricity runs on 230V which fits nicely in the 250V limit. The board relay says it is up to 10A, but I wouldn't use that much on it. In this example I am trying to switch a lamp or if to be more exact a household socket that runs on 230V and you can put any item you have in your home to work on it. My board has 2 relays, but in this example I am going to use just 1 relay. You can modify the code on what ever amount of relays your controller can bare. Relay boards are available with 1, 2, 4, 8 and even 16 relays. The amount of relays you control is not restricted to the amount of Arduino pins. You have use shift registers to control more relays if Arduino doesn't have enough pins for your setup.
Source code viewer


  1. #define RELAY_ON 0
  2. #define RELAY_OFF 1
  3. #define RELAY_1 2
  4. void setup()
  5. {
  6. // Set pin as output.
  7. pinMode(RELAY_1, OUTPUT);
  8. // Initialize relay one as off so that on reset it would be off by default
  9. digitalWrite(RELAY_1, RELAY_OFF);
  10. }
     
  11.  void loop() 
  12. {
  13. // Turn on and wait 3 seconds.
  14. digitalWrite(RELAY_1, RELAY_ON;
  15. delay(3000);
  16. // Turn off and wait 3 seconds.
  17. digitalWrite(RELAY_1, RELAY_OFF);
  18. delay(3000);
  19. }

Komentar

Postingan populer dari blog ini

K3 dalam Merakit PC

Xiaomi Xiaoyi Downgrade Firmware