Need code for a 10 sec LED timeline

Hello forum,

I'm in a pinch.

Bottom Line Up Front: I'm not seeking advice or guidance for other solutions. Please bear with me a moment... Though I can post the requirements and know the solution too, I cant seem to crack the code to get there. The only meaningful help is providing working code. In any other case, I'd welcome opinion. With that in mind, please reply with working code.

Background: The requirement is to control a 75 amp/240VAC solid state relay (SSR) that is activated when 5v is applied from the Arduino. The desired control methodology is important for this project because the Arduino is being integrated in a complex system.

Requirements:
A. 10K Potentiometer (Pot) control for the SSR.
B. The Pot has to have three distinctive states of control.
-- 1st state, is OFF (i.e., 0V output) (e.g., full left turn of the knob)
-- 2nd state, equal sub-divisions or time increments that interrupt the 10 second timeline with a 0V output. Specifically, each increment of right turn of the Pot, increases the OFF period within the 10 second timeline. It is important to note that the increment of OFF time should consume part of the 10 second time line.
-- 3rd state is ON (i.e., 5V output) (e.g., full right turn of the knob).

The idea I to have a single knob that turns from the 7 O'clock to the 5 O'clock position (roughly 270 degrees of rotation) if one could imagine a clock face as a range of rotation.
When turned full left to the 7 O'clock position, there shall be a 0V output.
When turned to the 8 O'clock position a 5V output shall begin for one second, after a 9 second delay. A slight rotation to the 9 O'clock position there shall be 5V output for 2 seconds, after an 8 second delay, etc...
There are approximately 9 whole number increments between the 8 and 4 O'clock positions (excluding the 7 [OFF] and 5 [ON]). The range between 8 and 4 O'clock can be reduced to finer increments (that would offer better control) and be more desirable.

Thank you in advance for your consideration.

Hello forum,

I'm in a pinch.

Bottom Line Up Front: I'm not seeking advice or guidance for other solutions. Please bear with me a moment... Though I can post the requirements and know the solution too, I cant seem to crack the code to get there. The only meaningful help is providing working code. In any other case, I'd welcome opinion. With that in mind, please reply with working code.

Background: The requirement is to control a 75 amp/240VAC solid state relay (SSR) that is activated when 5v is applied from the Arduino. The desired control methodology is important for this project because the Arduino is being integrated in a complex system.

Requirements:
A. 10K Potentiometer (Pot) control for the SSR.
B. The Pot has to have three distinctive states of control.
-- 1st state, is OFF (i.e., 0V output) (e.g., full left turn of the knob)
-- 2nd state, equal sub-divisions or time increments that interrupt the 10 second timeline with a 0V output. Specifically, each increment of right turn of the Pot, increases the ON period within the 10 second timeline. It is important to note that the increment of OFF time should consume part of the 10 second normally ON time line.
-- 3rd state is ON (i.e., 5V output) (e.g., full right turn of the knob).

The idea I to have a single knob that turns from the 7 O'clock to the 5 O'clock position (roughly 270 degrees of rotation) if one could imagine a clock face as a range of rotation.
When turned full left to the 7 O'clock position, there shall be a 0V output.
When turned to the 8 O'clock position a 5V output shall begin for one second, after a 9 second delay. A slight rotation to the 9 O'clock position there shall be 5V output for 2 seconds, after an 8 second delay, etc...
There are approximately 9 whole number increments between the 8 and 4 O'clock positions (excluding the 7 [OFF] and 5 [ON]). The range between 8 and 4 O'clock can be reduced to finer increments (that would offer better control) and be more desirable.

Thank you in advance for your consideration.

Hi Vaughn,

I assume you've got the SSR and other electronics covered. I'm impressed with the 240 VAC / 75 Amp circuit. I hope that this part of the project is being performed by someone who knows what they're doing. That's dangerous stuff.

So... Let me simplify your request to make sure we understand what you're asking.

You want to use a 10K pot to control the on/off ratio of a GPIO pin that will drive the SSR with a 10 second period. Full CCW = OFF, Full CW = ON.

This is essentially a pulse width modulation (PWM) signal with a 10 second period. google it to understand what I'm talking about.

You would also like a guard band on either end: from 7:00 to 8:00 (always off) and from 4:00 to 5:00 (always on).

Sound right?

cross-post

Don’t cross-post!

We know you are anxious to get an answer to your problem, but re-posting the same question to multiple parts of the forum causes duplicate effort, and divides the focus on your problem. You’ll get a better answer if everyone can discuss it in one place. Cross-posting is very annoying; the moderators will delete your extra posts, and you will get a warning. Save all the hassle, and just post the question once. It will be noticed.

If you aren’t sure what section to post in (Programming Questions, Electronics, etc.) make a guess. Don’t cross post “just in case”.

This is the code from the example of the Blink without Delay and make to your Requirements.

/* Blink without Delay
 
 Turns on and off a light emitting diode(LED) connected to a digital  
 pin, without using the delay() function.  This means that other code
 can run at the same time without being interrupted by the LED code.
 
 The circuit:
 * LED attached from pin 13 to ground.
 * Note: on most Arduinos, there is already an LED on the board
 that's attached to pin 13, so no hardware is needed for this example.
 
 created 2005
 by David A. Mellis
 modified 8 Feb 2010
 by Paul Stoffregen
 modified 11 Nov 2013
 by Scott Fitzgerald
 
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
 */

// constants won't change. Used here to set a pin number :
const int ledPin =  13;      // the number of the LED pin
const int sensorPin = A0;    // select the input pin for the potentiometer



// Variables will change :
int ledState = LOW;             // ledState used to set the LED
int PotSetState = LOW;             // PotSeState used to set the LED  high
int PotClrState = LOW;             // PotClrState used to set the LED low 
int sensorValue = 0;  // variable to store the value coming from the sensor

// Generally, you shuould use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillisON = 0;        // will store last time LED was ON
unsigned long previousMillisOFF = 0;        // will store last time LED was OFF


long intervalON = 1000;           // interval at which to ON (milliseconds)
long intervalOFF = 9000;           // interval at which to OFF (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);      
}

void loop()
{
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the 
  // difference between the current time and last time you blinked 
  // the LED is bigger than the interval at which you want to 
  // blink the LED.
  unsigned long currentMillis = millis();

   // read the value from the sensor:
  sensorValue = analogRead(sensorPin);  
	if(sensorValue > 925)
	{
		PotSetState = HIGH;
		intervalON = 10000; 
		intervalOFF = 1000;

	}
	else if(sensorValue < 20)
	{
		PotClrState = HIGH;
		intervalON = 1000; 
		intervalOFF = 10000;

	}
	else if(sensorValue < 102)
	{
		intervalON = 1000; 
		intervalOFF = 9000;
	}
	else if(sensorValue < 204)
	{
		intervalON = 2000; 
		intervalOFF = 8000;
	}
	else if(sensorValue < 306)
	{
		intervalON = 3000; 
		intervalOFF = 7000;
	}
	else if(sensorValue < 408)
	{
		intervalON = 4000; 
		intervalOFF = 6000;
	}
	else if(sensorValue < 510)
	{
		intervalON = 5000; 
		intervalOFF = 5000;
	}
	else if(sensorValue < 612)
	{
		intervalON = 6000; 
		intervalOFF = 4000;
	}
	else if(sensorValue < 714)
	{
		intervalON = 7000; 
		intervalOFF = 3000;
	}
	else if(sensorValue < 816)
	{
		intervalON = 8000; 
		intervalOFF = 2000;
	}
	else if(sensorValue < 924)
	{
		intervalON = 9000; 
		intervalOFF = 1000;
	}


  if((currentMillis - previousMillisON >= intervalON) || PotSetState ) {
    // save the last time you blinked the LED 
    previousMillisON = currentMillis;   

      ledState = HIGH;
	  PotSetState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }

  if((currentMillis - previousMillisOFF >= intervalOFF)|| PotClrState) {
    // save the last time you blinked the LED 
    previousMillisOFF = currentMillis;   

      ledState = LOW;
	  PotClrState = LOW;

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

Brock(?),

Maybe if you are in a pinch you shouldn’t have so many conditions on the help you’ll accept.

Jimmy

Threads merged.

I'm in a pinch.

Bottom Line Up Front: I'm not seeking advice or guidance for other solutions. Please bear with me a moment... Though I can post the requirements and know the solution too, I cant seem to crack the code to get there. The only meaningful help is providing working code. In any other case, I'd welcome opinion. With that in mind, please reply with working code.

TRANSLATION:
"I am running out of time on my school project. I have been busy playing video games and now I am out of time. Project is almost due and I have nothing to submit. Please write the code for my project so I can get a passing grade and don't have to retake the class...

Thank you in advance for your consideration.

"

I cant seem to crack the code to get there.

If you (really) tried to "crack the code" (as you put it) , then you have some code .

Show us what you tried .
Post the code you have so far.

Since you have such detailed requirements, you must have some code.

FYI, since you just registered on the forum on April 16, 2016, you probably don't know it, but we get these kind of posts every year. They always contain the same constraint that the code must meet the requirements exactly and no other alternatives or changes or suggestions will be accepted (dead giveaway that it's a school assignment) and last but not least ...they are always "in a pinch" (student code for "I have a project deadline")

This is not a code writing service. We are happy to offer guidance but we don't do homework projects on demand.

You might want to look at the MAP function.

Forum,

Please accept my sincere apology for having the audacity to ask for help and double posting. I took steps to delete first post because it contained an error only to find that the writer of the original post cant delete. It is worth noting that the first post could not be updated or modified either. May sound trivial at first read, but is likely going to trigger a second post.

Thanks for the replies for those that took the time to write. I found a solution. After waking up this morning and reading the 6 replies, I decided to verify a hunch by reading other replies from the same 6 individuals. Simply stated, I had a moment of clarity...

Five out of the six replies meet the minimum threshold of what I call "that guy" syndrome. This site if full of "that guy". You probably know the guy. The guy at the conference table who has to be there and doesn't want to be. The kind of guy that always has something to say, especially if it undermines the good will and creativity of a dedicated team and hides behind a 35 year resume of experience, but cant offer a single solution. The guy who everyone else if they had one wish, it would be that that guy wasn't around. You know the kind of guy to eat the last piece of pizza without hesitation and then yell out some kind of victory slogan and do a little dance. The guy who takes lunches from the community fridge, then says he was cleaning out the old stuff. The guy that offers little to society and is generally considered an asshole by the masses. You may find him by looking into a mirror or asking the people around you if you ever come across as "that guy". You are highly likely going to get a blank stare and look of; are you kidding, just before they confirm what an asshole you are.

The solution came 15 minutes after reading the replies to this post. I ordered four parts online that gave me two options for less than $100 bucks. The Arduino and the $200 of associated things that go with it will go back in the box and placed in my workshop for another year or so.

Respect and courtesy command that I reply to those who asked a question:

The kind reply (only one). Yes, I Know what I'm doing in regard to the 240V/75A circuit. I fabricated the system. My attempt was to add safety and prevent boil over by inserting a simple pot circuit downstream from the PID currently used to control boil. The solution is going to involve replacing the 3-20V DC controlled SSR with a SSR that has a built in 500K Pot interface. I might lose PID control with this method which we wanted to keep. Not sure, but one test is worth a 1000 opinions... I'll let you know how it turns out in a private message.

I'm not a student and this was not homework.

I didn't post code that I wrote because it distracts from the mission. However, I did write code for blinking, fading, and using a Pot to control them both. I watched 4 hours of useless YouTube videos, read strings of poorly written blogs and also tried to connect with my neighbor who could do something like this in a few minutes (and test it with me); but he was out of town.

The conditions (actually requirements) were not flexible. The $7K system used to boil and move fluids at specific times that this project was to interface with can ruin the product, and burn the operator if safe temps are continually exceeded.

I wont double post again.

Actually, this is the right place for having code written. The freedom from liability are inherent in forums and YouTube. I would have happily paid for the code. Interesting reply though. Would you accept the liability that would be incurred for providing services for compensation that the state of CA affords the buyer? No need to reply...

Actually, this is the right place for having code written.

No, that would be the "Gigs and collaborations" section.
This here's "Project guidance"

The kind of guy that always has something to say, especially if it undermines the good will and creativity of a dedicated team and hides behind a 35 year resume of experience, but cant offer a single solution.

1-This is Project Guidance
2-

The only meaningful help is providing working code.

This is not a code writing service
3- As stated, solicited code service is “Gigs and Collaborations”
4-

The guy that offers little to society and is generally considered an asshole by the masses.

I have 244 Karma points . You have 0. The Global Moderators know exactly where my karma points came from because they can see the id of each and every member who added them (apparently not) so they know my karma points came from members I helped and are not “padded” by bogus points from a friend or such. I earned each and every one of them. I sacrificed ten times that many because I refuse to hand the answer on a silver platter to those who are too lazy to even ask a single technical question. You, sir, are pure BS. Everything you said was total BS.

Simply stated, I had a moment of clarity…

Apparently your clarity only lasts for a brief moment, since you can’t seem to formulate a single question.

You did not post any code (despite your lame excuses) and you did not ask any code related questions.
You made absolutely NO effort to learn and had the audacity to demand we write your code for you.
You sir, are the USER. I help people who make an effort to learn, who aren’t lazy, who don’t BS, and who take the time to ask a technical question or two, rather than simply requesting that we do their work. You are “that guy”.

raschemmel:
1-This is Project Guidance
2-This is not a code writing service
3- As stated, solicited code service is "Gigs and Collaborations"

You made absolutely NO effort to learn and had the audacity to demand we write your code for you.
You sir, are the USER. I help people who make an effort to learn, who aren't lazy, who don't BS, and who take the time to ask a technical question or two, rather than simply requesting that we do their work. You are "that guy".

What he said!!! People that show up in various places and demand that people do their work for them are generally a pain (these same people have no interest in helping others, they just want someone to do their job for them). Too bad.

Vaughn7937:
With that in mind, please reply with working code.

OK, if "fully working code is the only thing you'll accept, then I'm out.

Vaughn7937:
Background: The requirement is to control a 75 amp/240VAC solid state relay (SSR) that is activated when 5v is applied from the Arduino. The desired control methodology is important for this project because the Arduino is being integrated in a complex system.

And if you'd like to switch dangerous voltage/current of unknown power devices, while being clueless about the code, I'm double-out.

So the only thing I have to you are some greetings from Germany:

Bye and have a nice day!

to all readers,

NOTE that OP did NOT post any schematic for the system he asked us to write the code for.

raschemmel:
The Global Moderators know exactly where my karma points came from because they can see the id of each and every member who added them

Nope.