element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • 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 Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Arduino
  • Products
  • More
Arduino
Arduino Forum Code help please. Arduino Uno / velleman VMA05 controlling relays and rgb light for external 12V systems in vehicle.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 10 replies
  • Subscribers 392 subscribers
  • Views 436 views
  • Users 0 members are here
  • code
  • help!
  • arduino
Related

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

Former Member
Former Member over 9 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);

   }

   }

}

}

}

}

} 


  • Sign in to reply
  • Cancel
Parents
  • gadget.iom
    0 gadget.iom over 9 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

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to gadget.iom

    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;

    }

      }}}

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • autodeskguest
    0 autodeskguest over 9 years ago in reply to Former Member

    On 24/10/15 23:56, Thorgeir Innervik wrote:

    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?

     

    One of your mistakes is that you've posted this in the wrong place. This

    is a discussion group for the Cadsoft Eagle PCB design tool. You'd get

    better answers in a programming related forum.

     

     

    That said, if you want a toggle action, you must ignore the button being

    held and only toggle when it's first pressed. The basic code will be:

     

    if ( input==HIGH && old_input==LOW )     // Only act on leading edges

    {

        output = ! output;          // toggle the output

        old_input = input;          // remember the state for edge detect

    }

     

    I'll leave the incorporation of this principle, including the fixing of

    the glaring bug, as an exercise for the reader.

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 9 years ago in reply to autodeskguest

    Hi

     

    Oh sorry i did not realize, found my way here through some weird arduino google search and gave it a try.
    thank you for your help but as i am not a programmer this is a bit beyond me and since i need to make the code work just once i dont feel i have the time to learn programming for this one instance, but i greatly appreciate your efforts!

     

    I will try to make sense of this and keep searching for a more programming related page.

     

    Thankyou //Thor

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to Former Member

    You have posted this in on an ENTIRELY appropriate website. Just in the wrong area.

    I will ask element14jamie or element14support to move this topic to a more appropriate area.

    Maybe Arduino.

     

    From there we can help you further.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • element14jamie
    0 element14jamie over 9 years ago in reply to gadget.iom

    Hello gadget.iom

    Thank you, I have moved it.

     

    Thank you again,

     

    Jamie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to element14jamie

    Cheers element14jamie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • gadget.iom
    0 gadget.iom over 9 years ago in reply to element14jamie

    Cheers element14jamie

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
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 © 2025 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