Pages: [1]   Go Down
Author Topic: LED/Photocells with Relay Module  (Read 132 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How would I program an arduino with LEDS/photocells using a relay module so that when I swiped up on a series of photocells, the LEDS would stay lit, and once the top one was activated, an external light would turn on? 
Logged

Johannesburg. UTC+2
Online Online
Faraday Member
**
Karma: 82
Posts: 3885
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First step is to forget about the program as such- at least in a formal, code sense- and list in detail exactly what the steps are. You have it in your mind I guess, and listed it in broad outline already, but now you need to list it more fully.
Logged

The Elders of the Internet know who I am.....

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First step is to forget about the program as such- at least in a formal, code sense- and list in detail exactly what the steps are. You have it in your mind I guess, and listed it in broad outline already, but now you need to list it more fully.

1. user runs finger up a line of 6 photocell sensors paired with 6 LED's
2. photocells activate each LED's
3. LED's stay lit as the users finger runs over each cell
4. once you reach the top (6th) LED an external light turns on [through a relay module]
5. in order to turn off the external light, you must repeat the process but in reverse
       ... so start at top (6th) LED and swipe down- once you deactivate the bottom (1st) LED, the external light turns off

I hope this makes more sense   smiley
Logged

Anacortes, WA
Offline Offline
Full Member
***
Karma: 2
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The LEDs leave a "finger track"? Do they go off when the big light goes on? What if the user swipes diagonal only hitting the middle sensors?

-jim lee
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The LEDs leave a "finger track"? Do they go off when the big light goes on? What if the user swipes diagonal only hitting the middle sensors?

-jim lee

Yes, they would leave a track, and stay lit while the external light is on. If they were only to pass over the middle sensors the external light wouldn't activate.. all LED's would need to be turned on for that to happen
Logged

Anacortes, WA
Offline Offline
Full Member
***
Karma: 2
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How many LEDs we talking about again? Just the 6?

-jim lee
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How many LEDs we talking about again? Just the 6?

-jim lee

For now, yes.
Logged

Anacortes, WA
Offline Offline
Full Member
***
Karma: 2
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

LEDs & Sensors can be thought of as matched pairs? If so I'd think along these lines..

class sensorLEDPair {

   public:
      sensorLEDPair(int sensPin,int LEDPin);

     void  loopTime(void);  // Call this in your loop to see if the sensor is touched, turn on/off LED etc.
      boolean isOn(void);    // returns the state of the LED.

      boolean LEDOnOff;    // saves the state of the LED
};

in your sketch you can create one of these.

sensorLEDPair firstPair(S_PIN1,L_PIN1);

void setup(void) {

}


void loop() {

   firstPair.loopTime();   // Let the fist sensor figure out what's going on etc.
  if (firstPair.LEDOnOff()) {
      biglightOn();                       // Need to write this.
   }
}

Once you get it working with one pair, just ad more pairs and adjust your loop() code accordingly.

For example
if (pair1.LEDOnOff() && pair2.LEDOnOff() && pair2.LEDOnOff()…) {

}

HOpe this helps

-jim lee
     
   
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

LEDs & Sensors can be thought of as matched pairs? If so I'd think along these lines..

class sensorLEDPair {

   public:
      sensorLEDPair(int sensPin,int LEDPin);

     void  loopTime(void);  // Call this in your loop to see if the sensor is touched, turn on/off LED etc.
      boolean isOn(void);    // returns the state of the LED.

      boolean LEDOnOff;    // saves the state of the LED
};

in your sketch you can create one of these.

sensorLEDPair firstPair(S_PIN1,L_PIN1);

void setup(void) {

}


void loop() {

   firstPair.loopTime();   // Let the fist sensor figure out what's going on etc.
  if (firstPair.LEDOnOff()) {
      biglightOn();                       // Need to write this.
   }
}

Once you get it working with one pair, just ad more pairs and adjust your loop() code accordingly.

For example
if (pair1.LEDOnOff() && pair2.LEDOnOff() && pair2.LEDOnOff()…) {

}

HOpe this helps

-jim lee
     
   


Thank you so much for taking your time to do this!!! I am still having a tough time understanding what I need to finish within that sketch...

Here is what I have currently- This sketch tells whichever photocell is triggered to light up one of the 6 LED's.  I am running the first LED output to a relay module with an external light.


sensorLEDPair(int LDR, int LEDPin)
int LDR = 0;
int LDR2 = 1;
int LDR3 = 2;
int LDR4 = 3;
int LDR5 = 4;
int LDR6 = 5;

//analog pin to which LDR is connected, here we set it to 0 so it means A0

int LDRValue = 0;
int LDRValue2 = 1;
int LDRValue3 = 2;
int LDRValue4 = 3;
int LDRValue5 = 4;
int LDRValue6 = 5;

//that’s a variable to store LDR values

int light_sensitivity = 470;
int light_sensitivity2 = 450;
int light_sensitivity3 = 450;
int light_sensitivity4 = 450;
int light_sensitivity5 = 300;
int light_sensitivity6 = 300;

//This is the approx value of light surrounding your LDR
void setup()
  {
    {
    Serial.begin(9600);            //start the serial monitor with 9600 buad
    pinMode(13, OUTPUT) = LEDPin;           //we mostly use13 because there is already a built in yellow LED in arduino which shows output when 13 pin is enabled
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  delay(3000);
  }
}
 
void loop()
  {
    LDRValue = analogRead(LDR);
    LDRValue2 = analogRead(LDR2);
    LDRValue3 = analogRead(LDR3);
    LDRValue4 = analogRead(LDR4);
    LDRValue5 = analogRead(LDR5);
    LDRValue6 = analogRead(LDR6);

    Serial.println(LDRValue);
    Serial.println(LDRValue2);
    Serial.println(LDRValue3);
    Serial.println(LDRValue4);
    Serial.println(LDRValue5);
    Serial.println(LDRValue6);    //prints the LDR values to serial monitor                   //This is the speed by which LDR sends value to arduino
 
    if (LDRValue < light_sensitivity)
    {
     digitalWrite(13, HIGH);
    }
    else
      {
        digitalWrite(13, LOW);
      }
     
    if (LDRValue2 < light_sensitivity2)
    {
      digitalWrite(12, HIGH);
    }
    else
    {
     digitalWrite(12,LOW);
    }
   
      if (LDRValue3 < light_sensitivity3)
      {
       digitalWrite(11, HIGH);
      }
    else
      {
       digitalWrite(11, LOW);
      }
     
      if (LDRValue4 < light_sensitivity4)
      {
        digitalWrite(10, HIGH);
      }
    else
      {
        digitalWrite(10, LOW);
      }
     
      if (LDRValue5 < light_sensitivity5)
    {
     digitalWrite(9, HIGH);
    }
    else
      {
        digitalWrite(9, LOW);
      }
     
      if (LDRValue6 < light_sensitivity6)
    {
     digitalWrite(8, HIGH);
    }
    else
      {
        digitalWrite(8, LOW);
      }
     
  }
 
Logged

Anacortes, WA
Offline Offline
Full Member
***
Karma: 2
Posts: 155
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

What I'm pushing to towards is to break your deal down to chunks that are easily manageable. This is what the class is for. You solve everything for that one class. Pass in the pins and now I see the parameters for that certain sensor. This gives you an isolated playground you can use work out how to make this one pair run without worrying about anything else.

If you do your code right, this gives you the n-th case of a pair. You can use this to create as many pairs as you want/need/can run that take care of themselves.

Now your main program/sketch is just managing these objects that control everything.

I don't know if you've worked in c++ or anything. This could be obvious to you, or, as for as you know, I could be speaking Klingon . But, at least get the main point, to break it into pairs and manage them as sets.

Hope this helps!

-jim lee
Logged

Pages: [1]   Go Up
Jump to: