I intend to build a small production machine where I need certain relays controlled at specific times.
I put this into the LED section since programming leds or relays should be the same.
The mechanical part is pretty much finished of the project but now I need to programm the arduino nano.
The problem is that I am quite experienced in electronics but know close to nothing about programming.
What I need:
timing of 4 or 5 relays independently (to move an object through a small production chain)
I need to tweak the timings for every relay just right so it will work.
For example:
Relay 1 starts at 340ms and stays on for 250ms and so on.
Are these relays on / off separately? That is, is there ever a time when two relays are on at the same time?
Relay 1 starts at 340ms and stays on for 250ms and so on.
These are very short times for a mechanical relay and although you can energise them at this speed with the pull in and pull out time this might not be the times the relays are actually on for.
oger:
The problem is that I am quite experienced in electronics but know close to nothing about programming.
Then start with the basic examples that come with the IDE.
You soon will get to the "BlinkWithoutDelay" example, that could do what you're asking.
Leo..
Thanks for the replies!
I did some digging and found out that it was easiest to just use a code for controlling a multi colored led.
I was able to enhance this to do exactly what I want.
Also I can use the pwm pins so I can regulate power to the coils.
Now I just need to figure out how to change the code the looping to a single push button running
the sequence...
here's the code.
Works great so far.
But I just need it to start at a pushbutton and loop as long as the pushbutton is pressed.
But It always has to end at the last step (after releasing the pushbutton) otherwise my object gets stuck in the process.
int valve = 3; // valve
int motorcw = 5; // Motor CW
int motorccw = 6; // Motor CCW
int feed = 9; // feed solenoid
void setup() {
pinMode(valve, OUTPUT);
pinMode(motorcw, OUTPUT);
pinMode(motorccw, OUTPUT);
pinMode(feed, OUTPUT);
}
void loop() {
setColor(255, 0, 0, 0); // activate valve
delay(250); // valve opening time
setColor(0, 255, 0, 255); // motor CW
delay(200); // motor travel time
setColor(0, 0, 0, 0); // loading
delay(100); // loading time
setColor(0, 0, 255, 255); // motor CCW
delay(200); // motor travel time
setColor(0, 0, 0, 0); // done
delay(2000);
}
void setColor(int redValue, int greenValue, int blueValue, int orangeValue) {
analogWrite(valve, redValue);
analogWrite(motorcw, greenValue);
analogWrite(motorccw, blueValue);
analogWrite(feed, orangeValue);
}
@larryd's tutorial implements most of what it seems you need. Naturally, there'll be tweaks and you'll have to modify the state machine control but, a lot of the grunt work is already done.
Thanks for the info.
I wish I saw that before.
But as my code is doing pretty much everything I need, I'll stick to that.
Just need this switch implemented and I'm done...
int Button = 1; // button
Pin 0 and 1 are already used by the USB<>Serial chip, so don't use these.
const byte buttonPin = 2; // button pin 2
const byte = 3; // valve pin 3
etc.
Best to use constant byte for values < 255 that do not change, like pin numbers. It saves memory.
pinMode(Button, INPUT_PULLUP); // internal pull up resistor assumes you are going to connect the button between pin and ground.
The pin is HIGH (from the pull up) when the button is not pressed (open circuit).
while(digitalRead(Button) == 0); // wait until button is pushed released
This assumes to wait here while the button is held down. Did you want that?
while(digitalRead(buttonPin); // this is the same...
while(digitalRead(buttonPin == HIGH); //as this
It means: wait here while the buttonPin is HIGH (not pressed).
Remove the two brackets there.
Next time use code tags. Read the "how to post" sticky on top of every main page.
Leo..