element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Autodesk EAGLE
  • Products
  • More
Autodesk EAGLE
EAGLE User Support (English) Code help please. Arduino Uno / velleman VMA05 controlling relays and rgb light for external 12V systems in vehicle.
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Autodesk EAGLE to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 5 replies
  • Subscribers 179 subscribers
  • Views 459 views
  • Users 0 members are here
Related

Code help please. Arduino Uno / velleman VMA05 controlling relays and rgb light for external 12V systems in vehicle.

autodeskguest
autodeskguest over 10 years ago

Hi

I have been desperatly trying to write a code that i felt would be

simple but i am unable to finish it.

I want to control the VMA05 relays with individual buttons in a toggle

fashion with momentane pushbuttons. Six relays and six buttons. i also

want a specific behavior of several RGB lights to indicate open or

closed relay by switching from green to blue when activated and back

when deactivated by a second press.

 

 

i have been trying several variants of code just stumbling around but i

want the setup to be closely like this (in assumed function) I

apreachiate any and all help, a dream would be if someone really smart

could fix this code for me. The arduino board will be used to control

systems for a vehicle used in Swedish volonteer mountain rescue

situations as well as other live scenarios (which due to the lack of

budget explains the use of arduino)

 

Thanks

 

 

const int BTN1 =7;

int press1 =0;

const int BTN2 = 6;

int press2 =0;

const int BTN3 = 5;

int press3 =0;

const int BTN4 = 4;

int press4 =0;

const int BTN5 = 3;

int press5 =0;

const int BTN6 = 2;

int press6 =0;

 

 

int relay1 =8;

int relay2 =9;

int relay3 =10;

int relay4 =11;

int relay5 =12;

int relay6 =13;

 

 

 

 

void setup()

{

  pinMode(8, OUTPUT);

  pinMode(9, OUTPUT);

  pinMode(10, OUTPUT);

  pinMode(11, OUTPUT);

  pinMode(12, OUTPUT);

  pinMode(13, OUTPUT);

 

  pinMode(7, INPUT);

  pinMode(6, INPUT);

  pinMode(5, INPUT);

  pinMode(4, INPUT);

  pinMode(3, INPUT);

  pinMode(2, INPUT); 

}

 

 

void loop()

{

  press1 = digitalRead(BTN1);

  if (press1 == HIGH && relay1 == LOW )

  {

   (relay1, HIGH);

  }else

   {

   (relay1, LOW);

   }

 

   {

    press2 = digitalRead(BTN2);

  if (press2 == HIGH && relay2 == LOW )

  {

   (relay2, HIGH);

  }else

   {

   (relay2, LOW);

   }

 

   {

    press3 = digitalRead(BTN3);

  if (press3 == HIGH && relay3 == LOW )

  {

   (relay3, HIGH);

  }else

   {

   (relay3, LOW);

   }

 

   {

    press4 = digitalRead(BTN4);

  if (press4 == HIGH && relay4 == LOW )

  {

   (relay4, HIGH);

  }else

   {

   (relay4, LOW);

   }

 

   {

    press5 = digitalRead(BTN5);

  if (press5 == HIGH && relay5 == LOW )

  {

   (relay5, HIGH);

  }else

   {

   (relay5, LOW);

   }

 

   {

    press6 = digitalRead(BTN6);

  if (press6 == HIGH && relay6 == LOW )

  {

   (relay6, HIGH);

  }else

   {

   (relay6, LOW);

   }

   }

}

}

}

}

} 

 

--

To view any images and attachments in this post, visit:

http://www.element14.com/community/message/164791

 

  • Sign in to reply
  • Cancel
Parents
  • autodeskguest
    autodeskguest over 10 years ago

    Hi

     

    Looking at your code it would appear that it is working, but not as you

    expected, because the program is looping so fast that pressing the

    button will result in an on statement and an off statement almost

    immediately.

     

    Take a look at the following code, taking into account the use of the

    "previous" variable and incorporate this into your design.

    https://www.arduino.cc/en/Tutorial/Switch

    You could basically replicate this code 6 times and add a number to

    these variables.

     

    Does this make sense?

    Paul

     

    --

    To view any images and attachments in this post, visit:

    http://www.element14.com/community/message/164827

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • autodeskguest
    autodeskguest over 10 years ago

    Hi

     

    Looking at your code it would appear that it is working, but not as you

    expected, because the program is looping so fast that pressing the

    button will result in an on statement and an off statement almost

    immediately.

     

    Take a look at the following code, taking into account the use of the

    "previous" variable and incorporate this into your design.

    https://www.arduino.cc/en/Tutorial/Switch

    You could basically replicate this code 6 times and add a number to

    these variables.

     

    Does this make sense?

    Paul

     

    --

    To view any images and attachments in this post, visit:

    http://www.element14.com/community/message/164827

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • autodeskguest
    autodeskguest over 10 years ago in reply to autodeskguest

    Hello and thankyou for your reply

     

    I actually found this specific tutorial and gave it a try. I failed

    however, i tried this without result.

    I dont know where to add the relay HIGH... As i want a on off toggle

    effect with the same momentane button i am at a loss. So you see my

    mistake?

     

    int inPin1 = 2;       

    int inPin2 = 3;       

    int inPin3 = 4;      

    int inPin4 = 5;      

     

     

    int outPin1 = 13;

    int outPin2 = 12;

    int outPin3 = 11;

    int outPin4 = 10;

     

     

     

     

    int state = HIGH;      // the current state of the output pin

    int reading1;

    int reading2;

    int reading3;

    int reading4;          // the current reading from the input pin

    int previous = LOW;    // the previous reading from the input pin

     

     

    // the follow variables are long's because the time, measured in

    miliseconds,

    // will quickly become a bigger number than can be stored in an int.

    long time = 0;         // the last time the output pin was toggled

    long debounce = 200;   // the debounce time, increase if the output

    flickers

     

     

    void setup()

    {

      pinMode(inPin1, INPUT);

      pinMode(inPin2, INPUT);

      pinMode(inPin3, INPUT);

      pinMode(inPin4, INPUT);

     

     

      pinMode(outPin1, OUTPUT);

      pinMode(outPin2, OUTPUT);

      pinMode(outPin3, OUTPUT);

      pinMode(outPin4, OUTPUT);

     

     

    }

     

     

    void loop()

    {

      reading1 = digitalRead(inPin1);

     

     

     

     

      // if the input just went from LOW and HIGH and we've waited long

    enough

      // to ignore any noise on the circuit, toggle the output pin and

    remember

      // the time

      if (reading1 == HIGH && previous == LOW && millis() - time > debounce)

    {

        if (state == HIGH)

          state = LOW;

        else

          state = HIGH;

     

     

        time = millis();   

      }

    { 

      reading2 = digitalRead(inPin2);

     

     

      if (reading2 == HIGH && previous == LOW && millis() - time > debounce)

    {

        if (state == HIGH)

          state = LOW;

        else

          state = HIGH;

     

     

        time = millis();  

      }

      {  reading3 = digitalRead(inPin3);

     

      if (reading3 == HIGH && previous == LOW && millis() - time > debounce)

    {

        if (state == HIGH)

          state = LOW;

        else

          state = HIGH;

     

     

        time = millis();  

      }

      {reading4 = digitalRead(inPin4);

      if (reading4 == HIGH && previous == LOW && millis() - time > debounce)

    {

        if (state == HIGH)

          state = LOW;

        else

          state = HIGH;

     

     

        time = millis();  

      }

      digitalWrite(outPin1, state);

      digitalWrite(outPin2, state);

      digitalWrite(outPin3, state);

      digitalWrite(outPin4, state);

     

     

      previous = reading1;

      previous = reading2;

      previous = reading3;

      previous = reading4;

    }

      }}}

     

    --

    To view any images and attachments in this post, visit:

    http://www.element14.com/community/message/164865

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube