Arduino/Projects/Cruise Control/Relay Control Code Sample

From msgwiki
Revision as of 16:19, 10 November 2023 by Walttheboss (talk | contribs)
Jump to navigation Jump to search
Access restrictions were established for this page. If you see this message, you have no access to this page.

Simple Code for starting the Relay module

This code makes the relay module 1 and 2 turn off and on in 6 second intervals. To run code copy and paste below text into Arduino IDE and verify and upload to board.

int RELAY1 = 6;

int RELAY2 = 7;

int LED1 = 13;

int LED2 = 12;

int delayValue = 6000;

void setup() {

  // put your setup code here, to run once:

  pinMode(RELAY1, OUTPUT);

  pinMode(LED1, OUTPUT);

  pinMode(RELAY2, OUTPUT);

  pinMode(LED2, OUTPUT);

  digitalWrite(RELAY1, HIGH);

  digitalWrite(RELAY2, HIGH);

  digitalWrite(LED1, HIGH);

  digitalWrite(LED2, HIGH);

  Serial.begin(9600);

}

void loop() {

 

  // put your main code here, to run repeatedly:

  digitalWrite(RELAY1, LOW);

  digitalWrite(LED1, HIGH);

  Serial.println("RELAY1 ON");

  delay(delayValue);


  digitalWrite(RELAY1, HIGH);

  digitalWrite(LED1, LOW);

  Serial.println("RELAY1 OFF");

//  delay(delayValue);

  digitalWrite(RELAY2, LOW);

  digitalWrite(LED2, HIGH);

  Serial.println("RELAY2 ON");

  delay(delayValue);

 

  digitalWrite(RELAY2, HIGH);

  digitalWrite(LED2, LOW);

  Serial.println("RELAY2 OFF");

//  delay(delayValue);

}

Connection Guide (Arduino Uno to Relay Module)

The way I first learned how to connect the board battery, cruise control module, and Relay Control Module, is showed on the right side.

R = Relay Control Module

CCM = Cruise Control Module

B = Arduino Uno R3

From the board to the relay module the connect is;

B Gnd = R Gnd

B 5v = R Vcc

B 7 = R In1

B 6 = R In2

R Vcc + JDVcc = Jumper

After connecting the Relay module to the board if you run the code it should blink the lights on the relay back and forth and turn the Relay switch on and off for 6 seconds each.

Connection Guide (Relay Module to 12v battery/ Cruise Control Module)