Author Topic: DigiSpark and DC relay input issue  (Read 3442 times)

XtremeIN

  • Newbie
  • *
  • Posts: 21
DigiSpark and DC relay input issue
« on: February 10, 2013, 05:37:42 pm »
Hello all,
I am trying to use a DigiSpark along with three DC Relay boards from DigiStump to run a traffic light.  I wrote the sketch without an input trigger to start the cycle.  It works perfect. I cannot get the input trigger to work, no matter what I do the light test runs and then the light cycle starts without the input trigger.


int motionSensor = 2;
int redLight = 3;
int yellowLight = 4;
int greenLight = 5;

void setup()
{
  pinMode(motionSensor, INPUT);
  pinMode(redLight, OUTPUT);
  pinMode(yellowLight, OUTPUT);
  pinMode(greenLight, OUTPUT);
 
  for (int Lighttest = 0; Lighttest < 4; Lighttest ++)
  {
    digitalWrite(redLight, HIGH);
    digitalWrite(yellowLight, HIGH);
    digitalWrite(greenLight, HIGH);
    delay(500);
    digitalWrite(redLight, LOW);
    digitalWrite(yellowLight, LOW);
    digitalWrite(greenLight, LOW);
    delay(500);
  }
}

void loop()
{
  if (motionSensor == x?x )
  {
    digitalWrite(redLight, HIGH);
    delay(3000);
    digitalWrite(redLight, LOW);
    digitalWrite(yellowLight, HIGH);
    delay(1500);
    digitalWrite(yellowLight, LOW);
    digitalWrite(greenLight, HIGH);
    delay(3000);
    digitalWrite(greenLight, LOW);
  }
  else
  {
    digitalWrite(redLight, LOW);
    digitalWrite(yellowLight, LOW);
    digitalWrite(greenLight, LOW);
  }
}

I have tried with the motionSensor == to HIGH and LOW. Is the sketch correct and my wiring wrong?
thank you,
Micheal

Mark

  • Full Member
  • ***
  • Posts: 196
Re: DigiSpark and DC relay input issue
« Reply #1 on: February 10, 2013, 06:53:33 pm »
XtremeIN


try this :-
Code: [Select]
void loop()
{
  if (digitalRead(motionSensor) == x?x )
  {

You need to read the input.
Not logical I agree .... but thats how it is.

You can also do a xyz = digitalRead(motionSensor), then do if (xyz == HIGH).

Cheers
Mark


XtremeIN

  • Newbie
  • *
  • Posts: 21
Re: DigiSpark and DC relay input issue
« Reply #2 on: February 10, 2013, 08:31:05 pm »
thanks Mark,
I had it written that way to start with. Not sure what happened, but I changed the code back to the way I started with/you suggested and went through all my wiring and now it works......

Micheal

Mark

  • Full Member
  • ***
  • Posts: 196
Re: DigiSpark and DC relay input issue
« Reply #3 on: February 10, 2013, 08:58:20 pm »
Micheal

Been there done that.
Even worse is the if without the double equals ...that's hard for a novice to spot.

Glad its working.

Mark