Go Down

Topic: Need help programming a photocell/relay shield (Read 7313 times) previous topic - next topic

irishluck

So plain and simple, I have no idea how to program period.
Ive done CSS and HTML for web design but never programming and have no idea where to even start.

I have the arduino uno and I also purchased a nightfire arduino shield with relay and photocell.

I need to program this so when the light beam is broken that is hitting the photocell on the ardruino shield that it will trip the relay for anywhere from 30 seconds to 3 minutes. Depending on what I want it set on.

Can someone help me how to do this?

irishluck

Ill even pay someone a small fee to help me do this.
I have no idea how to write code

UKHeliBob

If you do not want to program this yourself then this request would be better moved to the Gigs and Collaborations section of the forum.  Contact one of the moderators and they will move it for you.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

irishluck

Oh id like to program this myself but have no idea what to do or where to start

Riva

The job seems simple enough but you will need to supply more information so people can help you.
First off a link to the shield your talking about and details of what the sensors are and what pins they are connected to.
How are you expecting to adjust the relay delay time. Will this be written in the code and the Arduino needs re-programming if you change the time or will you use a switch(s) or variable resistor to set the time range.

irishluck

The relay on the shield can be programmed and can be be set to what ever time needed.
I want the time to be adjustable in the program.

This is the shield I purchased.
http://vakits.com/nf-arduino-photocell-controlled-relay-shield-kit-4523

Is gives the full details of the kit. Im trying to get the schematic for it so that I know what pins do what on the shield
The shield plugs in directly to the top of the arduino uno.

The sensor is a photocell. A light will be hitting it and when the light is broken I want it to instantly trigger the relay for what ever time I set it for. Now once the light has been broken I want the relay that is connected to the board to remain effectively tripped until the timer is up whether the light hits the photocell again or not.

Riva


The relay on the shield can be programmed and can be be set to what ever time needed.
I want the time to be adjustable in the program.
Will the arduino need a display and buttons so you can see and adjust the delay time or will it be plugged into a PC all the time so you could adjust/see the time using the serial monitor on the PC.

This is the shield I purchased.
http://vakits.com/nf-arduino-photocell-controlled-relay-shield-kit-4523
Is gives the full details of the kit. Im trying to get the schematic for it so that I know what pins do what on the shield
The shield plugs in directly to the top of the arduino uno.
I cannot find schematics of the shield on there site so don't know what pins each device is connected to or the logic levels they need/produce. Hopefully you have more details with the shield.

The sensor is a photocell. A light will be hitting it and when the light is broken I want it to instantly trigger the relay for what ever time I set it for. Now once the light has been broken I want the relay that is connected to the board to remain effectively tripped until the timer is up whether the light hits the photocell again or not.
And what happens if the light is still broken after the relay timeout. Does it trip the relay again or waits until beam is restored before re-arming to operate relay on next beam break?

irishluck

RIVA:

No display or buttons. I will pretty much have it set to one time. If it needs to be changed, I will plug it into my computer to change the setting in the ardruino software.

Im working on getting the schematic as we speak. They did send me the schematic in a DCH file but i do now know how to open a DCH file extension. So trying to get them to send it to me in different format.

So basically when the light is broken I want the relay to trip for the time I have it set for. So for this example we will say 30 seconds. After the relay has tripped for 30 seconds It to arm again. So if the light beam is broken again, the relay trips again for another 30 seconds.

Does that make since?

Riva


No display or buttons. I will pretty much have it set to one time. If it needs to be changed, I will plug it into my computer to change the setting in the ardruino software.
If the relay duration is not critical then you could use a potentiometer to adjust the delay time between your max/min ranges. Would save reprogramming the chip every time.

Im working on getting the schematic as we speak. They did send me the schematic in a DCH file but i do now know how to open a DCH file extension. So trying to get them to send it to me in different format.
Not very helpful of them. If you had not already bought the shield I would have suggested buying the Relay and LDR as separate items.

So basically when the light is broken I want the relay to trip for the time I have it set for. So for this example we will say 30 seconds. After the relay has tripped for 30 seconds It to arm again. So if the light beam is broken again, the relay trips again for another 30 seconds.
What if the beam is still broken after the 30 second delay is up. Does the relay fire again right away or wait till beam is restored to re-arm the relay?

irishluck

#9
Mar 12, 2014, 03:47 am Last Edit: Mar 12, 2014, 03:56 am by irishluck Reason: 1
Its really not an issue if I need to plug it in to a computer to change it. Once its set to what Id like it to be at, it wont be changed again. Really don't want to use a potentiometer to adjust that.

It really shouldn't be an issue to where the beam wont reconnect. In theory, the beam should only break for a split second. But if by chance its still broken then the relay should stay tripped. But there shouldn't be any issue with that. Should be an instant 1 second trip if that.

I finally was able to get a schematic of the shield.
It says its a temperature shield but it is the exact same board as the relay/photocell board.

PLEASE read this before you look at the schematic. Ignore the 2nd relay and also ignore the U2 circuit. I did not get the board with 2 relays or 2 photocells. The U2 circuit is ignore.
U1 has the photocell attached to it.

Riva

Try this, you will have to alter the '#define triggerLevel 512' value to suit your circuit and it's logic may need reversing from
Code: [Select]
  if (analogRead(ldrPin) < triggerLevel){
to
Code: [Select]
  if (analogRead(ldrPin) > triggerLevel){
the
Code: [Select]
#define relayDelay 20UL
defines the relay delay (20 seconds) but keep the UL on the end else it may cause timing issues later in code.

Code: [Select]
#define ldrPin A0                 // Pin the light dependent resistor is connected to
#define relayPin 2                // Pin relay is connected to
#define ledPin 13                 // Pin LED is connected to

#define triggerLevel 512          // Levels below this threshold will trigger relay
#define relayDelay 20UL           // Relay delay time in seconds

unsigned long relayOffTime = 0;   // Time to turn off relay

void setup(){
  //Serial.begin(115200);
  pinMode(relayPin,OUTPUT);
  digitalWrite(ledPin,LOW);       // Turn relay off
  pinMode(ledPin,OUTPUT);
  digitalWrite(ledPin,LOW);       // Turn LED off
}

void loop(){
  if (analogRead(ldrPin) < triggerLevel){
    if (relayOffTime == 0) {      // Relay off time zero so relay is off and we need to turn it on
      digitalWrite(ledPin,HIGH);  // Turn relay on
      digitalWrite(ledPin,HIGH);  // Turn LED on
      relayOffTime = (relayDelay * 1000UL) + millis();  // Set off time
      //Serial.println("Relay On");
    }
  }
 
  if (relayOffTime != 0) {        // Relay off time not zero so relay is on and we need to check if it's time to turn it off
    if (millis() > relayOffTime){ // Time expired?
      digitalWrite(ledPin,LOW);   // Turn relay off
      digitalWrite(ledPin,LOW);   // Turn LED off
      relayOffTime = 0;           // Clear off time
      //Serial.println("Relay Off");
    }
  }
}

irishluck

Awesome. I would have never gotten any of that. I wish I could learn this. I'm sure I will eventually learn it, just will take some time.

Now just a couple of questions. I'm assuming that I will have to supply 12v to both the arduino board and the shield?
Ans also, what exactly is a dip switch? This board comes with a 2 position dip switch.


UKHeliBob

Quote
Ans also, what exactly is a dip switch

DIP = Dual Inline Package

http://en.wikipedia.org/wiki/DIP_switch
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Riva


Awesome. I would have never gotten any of that. I wish I could learn this. I'm sure I will eventually learn it, just will take some time.
I think the code I wrote is fairly well documented so you should get an idea of what's happening. Other could probably recommend a good tutorial on C++
Now just a couple of questions. I'm assuming that I will have to supply 12v to both the arduino board and the shield?
The relays need 12V. If the Arduino is going to be connected to a PC via USB then no need to supply it with 12V but if it's stand alone then you will need to supply power. 12V is okay but keep an eye on how warm the voltage regulator gets as dropping 12V to 5V will generate a bit of heat.
Ans also, what exactly is a dip switch? This board comes with a 2 position dip switch.





irishluck

#14
Mar 13, 2014, 01:18 pm Last Edit: Mar 13, 2014, 01:49 pm by irishluck Reason: 1
Maybe I should have explained myself more on the dip switch.
I kind of know what it is but I dont know what its used for on this shield.

I mean is the dip switch used to turn on the U1 or U2 circuit? So for each photocell, the dip switch is what turns the circuit on?

RIVA:

You said the voltage reg can get a bit hot. Does the arduino board have to run off 12v or can it run off something lower? Also can I just mount a heat sink on the voltage reg to help cool it?

Go Up