learnelectronics

4X Relay Tester

May 9th, 2023
904
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.79 KB | Source Code | 0 0
  1. /********************************************
  2.  *                                          *
  3.  *           Relay Board Test Jig           *
  4.  *           by Learnelectronics            *
  5.  * https://www.youtube.com/learnelectronics *
  6.  *                                          *
  7.  ********************************************/
  8.  
  9.  
  10. void setup() {                                      // Setup Loop - Runs once, set's the parameters of the Arduino
  11.  pinMode(A0,INPUT);                                 // set the analog 0 pin as input o control delay
  12.  pinMode(7,OUTPUT);                                 // set digital pins 7-4 as outputs
  13.  pinMode(6,OUTPUT);
  14.  pinMode(5,OUTPUT);
  15.  pinMode(4,OUTPUT);
  16.  digitalWrite(7,HIGH);                              // set digital pins 7-4 OUTPUT ON (HIGH)
  17.  digitalWrite(6,HIGH);                              // relay works off of low signal
  18.  digitalWrite(5,HIGH);                              // so a HIGH pin is an idle pin in this case
  19.  digitalWrite(4,HIGH);
  20.  
  21.  
  22. }
  23.  
  24. void loop() {                                       //Main Loop - runs over and over
  25.  
  26.   int potraw = (analogRead(A0));                    //get reading from the potentiomter on A0
  27.   int waitfor = map(potraw, 0, 1024, 1, 254);       //Take the raw value 0-1024 and convert it into
  28.                                                     //a 0-254 value the Arduino can use
  29.  
  30.   digitalWrite(7,LOW);                              //relay on
  31.   delay(waitfor);                                   //stay on for time determined by var waitfor
  32.   digitalWrite(7,HIGH);                             //relay off
  33.  
  34.   digitalWrite(6,LOW);
  35.   delay(waitfor);
  36.   digitalWrite(6,HIGH);
  37.  
  38.   digitalWrite(5,LOW);
  39.   delay(waitfor);
  40.   digitalWrite(5,HIGH);
  41.  
  42.   digitalWrite(4,LOW);
  43.   delay(waitfor);
  44.   digitalWrite(4,HIGH);
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment