Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. /* ===============================================================
  2. Project: 4 Channel 5V Relay Module
  3. Author: Scott C
  4. Created: 7th Sept 2014
  5. Arduino IDE: 1.0.5
  6. Website: http://arduinobasics.blogspot.com.au
  7. Description: Explore the difference between NC and NO terminals.
  8. ================================================================== */
  9.  
  10. /*
  11. Connect 5V on Arduino to VCC on Relay Module
  12. Connect GND on Arduino to GND on Relay Module
  13. Connect GND on Arduino to the Common Terminal (middle terminal) on Relay Module. */
  14.  
  15. #define CH1 8 // Connect Digital Pin 8 on Arduino to CH1 on Relay Module
  16. #define CH3 7 // Connect Digital Pin 7 on Arduino to CH3 on Relay Module
  17. #define LEDgreen 4 //Connect Digital Pin 4 on Arduino to Green LED (+ 330 ohm resistor) and then to "NO" terminal on relay module
  18. #define LEDyellow 12 //Connect Digital Pin 12 on Arduino to Yellow LED (+ 330 ohm resistor) and then to "NC" terminal on relay module
  19.  
  20. void setup(){
  21. //Setup all the Arduino Pins
  22. pinMode(CH1, OUTPUT);
  23. pinMode(CH3, OUTPUT);
  24. pinMode(LEDgreen, OUTPUT);
  25. pinMode(LEDyellow, OUTPUT);
  26.  
  27. //Provide power to both LEDs
  28. digitalWrite(LEDgreen, HIGH);
  29. digitalWrite(LEDyellow, HIGH);
  30.  
  31. //Turn OFF any power to the Relay channels
  32. digitalWrite(CH1,LOW);
  33. digitalWrite(CH3,LOW);
  34. delay(2000); //Wait 2 seconds before starting sequence
  35. }
  36.  
  37. void loop(){
  38. digitalWrite(CH1, HIGH); //Green LED on, Yellow LED off
  39. delay(1000);
  40. digitalWrite(CH1, LOW); //Yellow LED on, Green LED off
  41. delay(1000);
  42. digitalWrite(CH3, HIGH); //Relay 3 switches to NO
  43. delay(1000);
  44. digitalWrite(CH3,LOW); //Relay 3 switches to NC
  45. delay(1000);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement