Go Down

Topic: Program to control 8 channel relay with arduino  (Read 9707 times) previous topic - next topic

Wawa

As mentioned, we need to know how big the solenoids are.
The right solution depends on the current draw of the solenoids.
Do you have a link to them, or do you know the resistance of the coils.

IR control is a different problem, but not that hard to add.
Leo..

larryd

Example of using a IR remote:
Code: [Select]
//**********************************************************************
 
#include "IRremote.h"
//LarryD

//Sketch to demonstrate using an IR hand remote to control Arduino outputs.
//The remote used here uses the NEC protocol.
//This remote sends the button code (example 0xFF629D) then a repeat code 0xFFFFFFFF
//The repeat code is re-sent as long as an IR remote button is pressed.
//The IR receiver used is the TSOP4838
 
/*  17 IR button remote layout   http://i.imgur.com/X1KIdqI.png
 
   ^
< OK  > 
   v
1  2  3
4  5  6
7  8  9
*  0  #
 
*/
 
 
const byte RECV_PIN = 7;   //IR receive pin
 
IRrecv irrecv(RECV_PIN);   //create instance of 'IRrecv'
decode_results results;    //create instance of 'decode_results'
 
unsigned long   TimerUp;   //UP arrow on the remote
boolean         TimerUpFlag = false;
 
unsigned long   TimerDown; //DOWN arrow on the remote
boolean         TimerDownFlag = false;
 
unsigned long TimerIntensity;
unsigned long TimerIncDec;
boolean intesityUpFlag   = false;
boolean intesityDownFlag = false;
int brightness;
 
unsigned long   dummy;
unsigned long * TimerPtr = &dummy; //pointer to the current timer
 
const byte upLED        = 13;  //turns on as long as the UP button is pressed
const byte downLED      = 12;  //turns on as long as the DOWN button is pressed
const byte leftLED      = 11;  //toggles on/off
const byte rightLED     = 10;  //toggles on/off
const byte intensityLED =  9;  //a LED which can have its intensity adjusted
 
 
//                           s e t u p ( )
//**********************************************************************
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); //start receive
 
  pinMode(upLED, OUTPUT);
  pinMode(downLED, OUTPUT);
  pinMode(leftLED, OUTPUT);
  pinMode(rightLED, OUTPUT);
  pinMode(intensityLED, OUTPUT); //this is a PWM output pin
 
} //                    E N D  O F  s e t u p ( )
 
 
 
//                            l o o p ( )
//**********************************************************************
void loop()
{
  if (irrecv.decode(&results)) //is there IR remote button code
  {
    //Serial.println(results.value);
    processButton(); //process button press
    irrecv.resume(); //restart for next button press
  }
 
  //**********************                                //Turn off upLED
  //if timing is enabled, is it time to stop
  if (TimerUpFlag && millis() - TimerUp >= 250ul)
  {
    TimerUpFlag = false; //disable timing
    TimerPtr = &dummy;   //pointer to dummy timer
    digitalWrite(upLED, LOW);
  }
 
  //**********************                                //Turn off downLED
  //if timing is enabled, is it time to stop
  if (TimerDownFlag && millis() - TimerDown >= 250ul)
  {
    TimerDownFlag = false; //disable timing
    TimerPtr = &dummy;     //pointer to dummy timer
    digitalWrite(downLED, LOW);
  }
 
  //**********************                                //LED intensity
  //are we still within the adjustment time
  if (millis() - TimerIntensity <= 300ul)
  {
    //is it time to increase/decrease the intensity
    if (millis() - TimerIncDec >= 200ul)
    {
      TimerIncDec = millis();
 
      if (intesityUpFlag == true) //Increase
      {
        brightness += 5;
        if (brightness > 255)
        {
          brightness = 255;
        }
      }
      else if (intesityDownFlag == true) //Decrease
      {
        brightness -= 5;
        if (brightness < 0)
        {
          brightness = 0;
        }
      }
 
      analogWrite(intensityLED, brightness);
      //Serial.println(brightness); //debug
    }
  }
  //stop increasing/decreasing intensity
  else
  {
    intesityUpFlag = false;
    intesityDownFlag = false;
  }
 
  //************************************
  //Other non blocking code goes here
  //************************************
 
} //                   E N D  O F  l o o p ( )
 
 
 
//======================================================================
//                       F U N C T I O N S
//======================================================================
 
//                   p r o c e s s B u t t o n ( )
//**********************************************************************
//process IR remote button presses
void processButton()
{
  switch (results.value)
  {
    //**********************
    case 0xFF629D:                                           //UP Arrow
      {
        Serial.println("UP");
        TimerPtr = &TimerUp;  //point to this timer
        TimerUpFlag = true;   //enable timing
        digitalWrite(upLED, HIGH);
        TimerUp = millis();
      }
      break;
 
    //**********************
    case 0xFFA857:                                           //DOWN Arrow
      {
        Serial.println("DOWN");
        TimerPtr = &TimerDown;  //point to this timer
        TimerDownFlag = true;   //enable timing
        digitalWrite(downLED, HIGH);
        TimerDown = millis();
      }
      break;
 
    //**********************
    case 0xFF22DD:                                           //LEFT Arrow
      {
        Serial.println("LEFT");
        digitalWrite(leftLED, !digitalRead(leftLED));   //Toggle LED
      }
      break;
 
    //**********************
    case 0xFFC23D:                                           //RIGHT Arrow
      {
        Serial.println("RIGHT");
        digitalWrite(rightLED, !digitalRead(rightLED)); //Toggle LED
      }
      break;
 
    //**********************
    case 0xFF42BD:                                           // * button
      {
        Serial.println("*");
        TimerPtr = &TimerIntensity;  //point to this timer
        intesityUpFlag = true;       //enable intensity up adjustment
        intesityDownFlag = false;
        TimerIncDec = millis();
        TimerIntensity = millis();
      }
      break;
 
    //**********************
   case 0xFF52AD:                                           // # button
      {
        Serial.println("#");
        TimerPtr = &TimerIntensity;  //point to this timer
        intesityDownFlag = true;     //enable intensity down adjustment
        intesityUpFlag = false;
        TimerIncDec = millis();
        TimerIntensity = millis();
      }
      break;
 
    //**********************
    case 0xFF02FD:
      Serial.println("OK");
      break;
 
    //**********************
    case 0xFF6897:
      Serial.println("1");
      break;
 
    //**********************
    case 0xFF9867:
      Serial.println("2");
      break;
 
    //**********************
    case 0xFFB04F:
      Serial.println("3");
      break;
 
    //**********************
    case 0xFF30CF:
      Serial.println("4");
      break;
 
    //**********************
    case 0xFF18E7:
      Serial.println("5");
      break;
 
    //**********************
    case 0xFF7A85:
      Serial.println("6");
      break;
 
    //**********************
    case 0xFF10EF:
      Serial.println("7");
      break;
 
    //**********************
    case 0xFF38C7:
      Serial.println("8");
      break;
 
    //**********************
    case 0xFF5AA5:
      Serial.println("9");
      break;
 
    //**********************
    case 0xFF4AB5:
      Serial.println("0");
      break;
 
    //**********************
    case 0xFFFFFFFF: //Repeat code
      {
        Serial.println("REPEAT");
        *TimerPtr = millis();       //reset the current timer
      }
      break;
 
  } // END switch case
 
} //             E N D  o f  p r o c e s s B u t t o n ( )
 
//**********************************************************************
 
//======================================================================
//                        E N D  O F  C O D E
//======================================================================
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

ktkamm

Wawa,

24 volts, 4.8 watts and 120mamps


Does that help?

larryd

#18
Nov 04, 2016, 03:50 am Last Edit: Nov 04, 2016, 03:53 am by LarryD
Coil resistance?


Edit
If you have the relay board already, I would use it for the physical isolation it offers.

Are the relays on the relay board 5v coil?
.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Wawa

Eight 120mA solenoids could be controlled with a single TPIC6B595.
No relays, nothing else.
Leo..

ktkamm

These are the solenoid units. I will need to check the relay board later when back home. If I use that chip, do I need to invest in a Raspberry Pi board?

larryd

The Arduino can drive TPIC6B595s.
Crossroads may have a finished board you could use.

You already have a relay board and it has screw terminals to connect your solenoid wiring, I would stick with it.

.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

INTP

What kind of range are you expecting with the IR remote setup? What is the maximum distance you'll be from any of the components? (Consider distance you can get between you and the actual gates, if you maintain line of sight, where you might be putting the controlling mcu, etc)

Since you haven't solidified a project design, it's still up in the air as to whether you want each gate to have its own remote controlled module, or if you want a centrally located relay board and have wires run everywhere.

And of course if you're going to be sitting next to the relay control board anyway, there's little point in having a remote control when a control panel with buttons/switches would be easier to use.

Wawa

If I use that chip, do I need to invest in a Raspberry Pi board?
Haha, no.
A $2.00 Nano clone could drive 1000 remote controlled solenoids, and make you a coffee at the same time.
Leo..

CrossRoads

Will need 125 TPIC6B595s of course for 1000 solenoids. And likely some buffering for the clock and latch lines.
I've done 45 in a project, blasted out data at 8 MHz to them.  Fast!
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

INTP

Basically, figure out how to turn on and off an LED with the Arduino.
Then figure out how to turn on and off an LED with the Arduino with the remote of your choice.
Then instead of controlling an LED, that wire instead goes into the signal lines of the relay. That's all there is to it.
The part that requires most of your attention will be powering the relay board with a separate power supply because you've got up to 8 coils needing a lot of current to simply stay on since these aren't latching relays.

terryking228

Quote
Why can I not remember 'wikispaces'   ?
Just type "arduinoinfo.info" in your browser and it'll get there...
Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

larryd

#27
Nov 06, 2016, 06:24 pm Last Edit: Nov 06, 2016, 06:35 pm by LarryD
But my memory is getting poor.

I had better stick with a shortcut on the desktop ;)

I do like the web site.
.
No technical PMs.
If you are asked a question, please respond with an answer.
If you are asked for more information, please supply it.
If you need clarification, ask for help.

Go Up