Turning pc on with 12 led trigger

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Ok I’ve tried pasting the addons in but it says it expects “{“ before “value”
I’m not really sure where it’s ment to be pasted in, remember I’m only a beginner :)
As you can see on the post before, my program uses ldrPin so I’ve tried changing the “l” for ldrPin but that doesn’t work either.
 
Last edited:

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Hello everyone,
I’ve managed to get the ldr to flash an led When it passes 400 and flash when it passes 200 there is a space in between where the led is off (which I wanted) now I need to stop it flashing constantly and make it only flash just the once when it passes 400 and once when it passes 200
This is my program so far

const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop(){
int ldrStatus = analogRead(ldrPin);
if (ldrStatus >=400 ) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
} else {

if (ldrStatus <=200){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
}
}
}

How do I get it to flash just once when it passes both settings,
Thanks for any help,
Phil.
 

Wolframore

Joined Jan 21, 2019
2,619
hint: you need one more variable to show the "state" so if state is: low or high, then if ldrStatus reaches value then if the state is not updated update and flash... if it's updated then do nothing. Also take all those delays out you don't need it.
 

djsfantasi

Joined Apr 11, 2010
9,237
Hello everyone,
I’ve managed to get the ldr to flash an led When it passes 400 and flash when it passes 200 there is a space in between where the led is off (which I wanted) now I need to stop it flashing constantly and make it only flash just the once when it passes 400 and once when it passes 200
This is my program so far

const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop(){
int ldrStatus = analogRead(ldrPin);
if (ldrStatus >=400 ) {
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
} else {

if (ldrStatus <=200){
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
}
}
}

How do I get it to flash just once when it passes both settings,
Thanks for any help,
Phil.
Answered in one of my previous posts.
 

djsfantasi

Joined Apr 11, 2010
9,237
C:
void loop(){
[B]static boolean overUpper=false;
static boolean underLower=false;[/B]

int ldrStatus = analogRead(ldrPin);
if (ldrStatus >=400
  && ! overUpper) {
overUpper=true;
underLower=false;

digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
} else {

if (ldrStatus <=200

  && ! underLower){
overUpper=false;
underLower=true;

digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println( ldrStatus);
}

if(ldrstatus<400) overUpper=false;
if(ldrStatus>200) underLower=false;

}
...or something close to that. I’m eating dinner at a bar. There could be a typo.

UODATE: Lookec at it again. No typos.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,237
Answered in one of my previous posts.
take the delays out and use millis() and you're pretty much set. You definitely don't need the delay after pin low...
Gentlemen,

I’m not so sure he doesn’t need the delays. If he were to remove them, they wouldn’t flash and the delay after setting the pin low is needed in the event conditions dictate that it flash more than once. Both are required.

And using millis() complicates the code greatly.
 

Wolframore

Joined Jan 21, 2019
2,619
I just had a thought why are we using an LDR why not just monitor the output current/voltage out of the solar panels? should be a blocking diode on the charging circuit.
 

Reloadron

Joined Jan 15, 2015
7,891
I just had a thought why are we using an LDR why not just monitor the output current/voltage out of the solar panels? should be a blocking diode on the charging circuit.
I wondered about that as initially it was mentioned the solar charger had two led indicators and way back there I suggested using them. I believe the original post indicated having the PC On while the solar charger was On? Seems simple enough to me.

Ron
 

visionofast

Joined Oct 17, 2018
106
Thanks very much VISIONOFAST that would be spot on but I’ve just noticed the led on the charger flashes when charging, another led stays on when there’s no charge,
Funny you should mention ldr’s, I’ve just been looking at YouTube videos on them, I think as I’m looking for it to work when the sun comes up, I may as well have an ldr on the outside so when the sun comes up, it turns it on?
Is there a relay that can flick on for a millisecond to activate the pc, then flick the relay again when the ldr goes off?
so,you can consider the no-charge LED as trigger along with a Dark-activated ldr circuit.
the next step is using Logic ICs like latch and flip-flop to make a momentary or latched relay circuit...but you can ditch this hardware complications with an arduino or microcontroller and by just some programming tricks (as mentioned).
 

Wolframore

Joined Jan 21, 2019
2,619
lol yep that would work too, apologies my friend, I was lost on another path... @Yaakov ... I would just do voltage divider to the ADC and set the thresholds based on readings.
 
Last edited:

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Hey all,
thanks to DJSFANTASI’s amazing promgam editing, it’s up and working,
It must be nice to be sat in a pub relaxing and just come up with a program just like that, I’m in ore of your talent and I thank you for your time and patience’s,
Here’s how the code ended up:-

const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
static boolean overUpper=false;
static boolean underLower=false;

int ldrStatus = analogRead(ldrPin);
if (ldrStatus >=400 && ! overUpper) {
overUpper=true;
underLower=false;
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
} else {

if (ldrStatus <=200 && ! underLower) {
overUpper=false;
underLower=true;
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println( ldrStatus);
}
if(ldrStatus<400 ) overUpper=false;
if(ldrStatus>200) underLower=false;
}
}

I’ll get it all wired up to a relay now for the pc switch, I’m not bothered about a hard shutdown, it’s good enough for me that way,
THANKS again to all that helped in this project, especially DJSFANTASI and his wisdom :)
 
Last edited:

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Sorry to be a pain but I’ve just noticed that the program flashes on and of at the setting (which we were aiming for) but when it goes above 400 then down to let’s say 300 then back up to 400 it will flash again, the same happens when it passes 200 then up to let’s say 300 then back down to 200,
I had to remove the B and /B at the beginning of the program as it said B was not declared in this scope, I’m assuming this would stop the flashing every time it’s passes the setting numerous times,
The only thing needed now is to declare B but I haven’t got a clue how to do this,
 
Last edited:

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Hi again,
I figured it out, it was really quite simple in the end, I just needed the area between 80-480 to asign the led OFF
Here what I did:-

const int ledPin = 13;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
static boolean overUpper=false;
static boolean underLower=false;
int ldrStatus = analogRead(ldrPin);
if (ldrStatus >=480 && ! overUpper){
overUpper=true;
underLower=false;
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println(ldrStatus);
} else {

if (ldrStatus <=80 && ! underLower) {
overUpper=false;
underLower=true;
digitalWrite(ledPin, HIGH);
delay(500);
digitalWrite(ledPin, LOW);
delay(500);
Serial.println( ldrStatus);
}
if (ldrStatus <=480 && ldrStatus >=80)
digitalWrite(ledPin, LOW);
}
}

Thanks again to everyone involved with this,
Phil.
:)
 

MisterBill2

Joined Jan 23, 2018
27,563
I have not looked at this thread in a while, and I am wondering, what is the TS mining? All I have seen is about light sensing and program coding?
What sort of mining?
 

Thread Starter

Bigfillly

Joined Jan 4, 2019
73
Hi,
It’s a bitcoin miner, It will be going back on soon due to the fact bitcoins cycle means it will be going up in the coming year or so,
If your looking to invest, Wait a week or so for the dip then buy in ;-)
 
Top