Hi everyone, im looking for help the programming my arduino to control a dust extractor in my workshop. i have the hardware sorted and i thought i could just use some simple logic if and else program but the delays stop the sensor from reading so this is no good. hopefully this will be useful to other people as well as the only arduino dust extractor controls i could find are simple remote control on/off things.
the hardware is basically a dust extractor which has 2 motors (record power dx4000) which gives two different power settings; with one motor running it is low suction which is great for sanders and with both motors running it has high suction which is great for routing.
i have the arduino with two current sensors; one for the router and one for the sander, they are dc bi-directional sensors so i had to include an op amp circuit to trim the signal as they are detecting ac current, this is sorted now so i get a clean-ish signal that the arduino can use (around 3 when no current and varies 30 - 300 when current is detected) i ran a basic sketch to turn on a relay at >15 and it worked fine.
the dust extractor also has a split pipe, one side goes to the sander and the other goes to the router and i intend to use auto blast gates to close/open each pipe when needed.
i have a four channel relay board so can control both motors and 2 blast gates independently using simple high/low outputs.
so what i want the program to do is this-
when router is on-
open blast gate1
delay 1 sec
fan1 on
delay .5 secs //this delay is to reduce load so everything isnt turning on at the same time
fan2 on
when router is off-
delay 4 seconds // for dust to clear in pipes
fan1 off
fan2 off
close blast gate1
when sander is on-
open blast gate2
delay 1 secs
fan1 on
when sander is off-
delay 4 seconds // for dust to clear in pipes
fan1 off
close blast gate2
i have 2 problems at the moment first is the delay interrupts the sensors reading so i just get an oscillation effect and second is when i stack digitalwrite to turn 2 relays on at the same time only the first one activates and it skips the other?
if anyone has a simple way of doing this i would be really grateful, i am not a programmer!
Sarcasm isn't going to help, ironically lack of code is why i came here.
need to read, understand, and embrace the philosophy in the blink without delay example.
Thanks, that does help a little more, but is a little like pointing in random direction and saying "north isnt that way" ive been googling millis for a few hours now and most examples seem to be just using it to blink led's, which is really pretty but not much help.
How can i start millis timing using if and then make it activate a relay at a certain point? cant find any example of that anywhere.
Unlikely. Either the code isn't doing what you think, because of missing braces, or your relays draw too much current.
thanks, i had got part of the code for this correct, i hadnt realised the relay board is HIGH in its natural state which was confusing the results of my experimentation, sorted now.
i dont expect anyone to write the entire code for me and i appreciate the need to learn for my self and i suppose it doesnt help that im starting to learn code from scratch with something quite complex(to me), but bear in mind i have never programmed anything before so just a little more help would be really appreciated.
we can not honestly help unless you give us something to work with. Even crap code that lists the inputs and outputs is better than no code. The blink with out delay example is the most common used program for beginners to start to understand how to use millis timers.
The program looks easy to write if you understand millis timers but with out that basic understanding the program will seem incredibly complicated and you will never be able to understand the way the code flows.
Thanks, that does help a little more, but is a little like pointing in random direction and saying "north isnt that way" ive been googling millis for a few hours now and most examples seem to be just using it to blink led's, which is really pretty but not much help.
The whole point of that example is that something happens, and then, a fixed amount of time later, something else happens WITHOUT the need to just stuff your thumb up your ass while waiting, which is what delay() does.
If you find the concept difficult to understand, don't make programmer your career choice.
I'm sorry if I seem harsh, but programming does require that you be able to think, to understand what some bit of code is doing, and to be able to adapt that to your needs. North is not that way.
i hadnt realised the relay board is HIGH in its natural state which was confusing the results of my experimentation, sorted now.
That's another part of programming. You don't expect to hunt and peck and tap out the whole program in one go. You write a function, and see how the hardware behaves. You confirm that the Serial.print() statements agree with what actually happens. "Relay off" appearing in the serial monitor should not happen at the same time the fan connected to the relay blows up. If it does, you know that you have a problem. Might be software; might be hardware. Does need to be fixed BEFORE you write any more code.
As you do not seem to have any code you wish to share and as a learning lesson I quickly knocked up a basic program that might do what you want. Inputs are pullups so either change the code or rewire so the pin is connected to ground when on. I guessed at names and pin numbers.
If you don't understand millis timers this will look like Egyptian hieroglyphics
p.s this is all cut and paste code so I wouldn't hook up anything you care about before testing.
Thanks gpop, thats really helpful. there is a lot in there that is is obviously not in the blinking led tutorial (unsurprisingly) so that should hopefully teach me some more. ill have a good look at it when i have some more spare time.
i did manage some code but i seem to have been barking up the wrong tree (again unsurprisingly)
it does compile but then when uploaded the relay board lights at ex1 and ex2 flash on for a split second and then nothing else happens. when sensor value is over 15 (when current passes through) the relays should open but they dont, without all the millis stuff in there they do turn off and on appropriately.
anyway looking at your code i have been looking at it completely the wrong way. i do understand the concept of using millis and the concept of defining all the parameters but as of friday morning i hadnt ever done any programming so obviously the translation of the logic in my head to a usable code will take some learning.
just edited to add- this obviously isnt everything i need the code to do, just experimenting with part of it to get the millis delays to work.
const int ex1 = 10; //fan 1 output
const int ex2 = 11; //fan 2 output
unsigned long previousMillis = 0;
long delayTime = 2000;
void setup()
{
pinMode(ex1, OUTPUT);
pinMode(ex2, OUTPUT);
}
void loop()
{
int sensorValue5 = analogRead(A1);
int sensorValue16 = analogRead(A2);
if (sensorValue16 >= 15);
unsigned long currentMillis = millis();
if((currentMillis - previousMillis >= delayTime) && (sensorValue16 >= 15))
{
digitalWrite(ex2, LOW);
digitalWrite(ex1, LOW);
}
else if (sensorValue16 < 15);{
digitalWrite (ex1, HIGH);
digitalWrite (ex2, HIGH);
}
Just to say many thanks again for your effort Gpop. i re worked that code as the inputs were analog and it works perfectly. also added an extra delay so the blast gates close a few seconds after the fans stop as the suction is enough to jam them in position if they haven't stopped moving.
also really helped me to get my head around these millis and how to code them.
russty1980:
so what i want the program to do is this-
when router is on-
open blast gate1
delay 1 sec
fan1 on
delay .5 secs //this delay is to reduce load so everything isnt turning on at the same time
fan2 on
Wrong. Everyone makes this mistake at first . What you really want is
when router changes from being off to being on-
open blast gate1
delay 1 sec
fan1 on
delay .5 secs //this delay is to reduce load so everything isnt turning on at the same time
fan2 on
im glad you have it working and have figured out one way to deal with timing.
I hope you can re-read pauls posts now and understand that he was pointing you in the right direction. No one wants to write code from scratch because it means guessing names and pin numbers and writing the boring stuff like pinmode etc.
A lot of new people would have just loaded the code I posted and screamed that it didn't work and demanded that it was fixed then add more requests as they didn't understand the basics so they end up with a code that works but they have no idea why it works.
The people with high post counts have fell into this trap many times where they end up writing custom code and the person they are trying to help has learn nothing so they tend to point you in the right direction to make you learn.
Im really glad to see that you changed the program and played with the code with out coming back hoping that someone else would fix it for you and I didn't have to feel bad about giving you to much help.