Hello to all the members of the forum reading this topic. Its my first post so I want to introduce myself. I am an automotive engineering student and curently I am working on a project for creating an air driven test equipment. Since its operation is relatevely simple I chose to use the Arduino Uno V3 to automate the task. Unfortunatelly I have limited knowledge and also limited experience programing with the C/C++ languages (Only did some Matlab at school for data processing). This is not a reason to give up though as it is not my first time doing something without any background.
Basically I want to have a machine where Arduino would control an air solenoid (12V 4.5W through a transistor TIP122 and 1k base resistor) so that an assembly (lets call it a pneumatic motor) is rotated with certain rpm(frequency). The speed will be monitored by a 50%PWM signal (comes from auxiliary equipment)which has the same frequency as the axle rotation. It is desired that:
- The operator would press a button (momentary switch acts like a trigger for the arduino to start air supply. Switch works with a voltage devider on one of the digital pins as the whole system is 12V)
- Arduino opens the solenoid and monitors motor speed.
3.Once the desired frequency is reached Arduino veries the output to the solenoid ON/OFF for certain time(a few seconds) so that speed is stabilized
4.After the time ends solenoid is turned off.
In addition the system has an LCD monitor to display the frequency when the mashine is working. This is not too much for now, but the monitor probably will be used with different functionality later on. So far I started writing the code:
//Include LCD RS E DW4 DW5 DW6 DW7
LiquidCrystal lcd (7,8,9,10,11,12);
pinMode(6, INPUT); //AIR SUPPLY TRIGGER SWITCH ON PIN 6
pinMode(5, INPUT); //SENSOR SIGNAL 50%PWM / PIN 5 / FREQUENCY OF SIGNALS CORRESPONDS TO ROTATIONAL FREQUENCY
pinMode(3, OUTPUT); //TRANSISTOR/SOLENOID OUTPUT / DRIVE THE SOLENOID THROUGH A TRANSISTOR(+1kOhm) ON PIN 3
if ((digitalRead (6)==HIGH) && FREQ<25) //HOW TO MAKE THE IF/ELSE IF FUNC. CONTROL SPEED FOR CERTAIN TIME(4-5sec) AFTER LIMIT (25Hz) IS REACHED
FREQ = 500000/pulseIn(5, HIGH); //HOW TO MAKE THE FOR LOOP RUN ONLY ONCE WHEN THE BUTTON IS USED or HOW TO USE PUSH BUTTON???
digitalWrite (3, HIGH);
else if ((digitalRead (6)==HIGH) && (FREQ>=25))
FREQ = 500000/pulseIn(5, HIGH); // CALCULATE FREQUENCY (PULSEIN USES MICROSECONDS)
digitalWrite (3, LOW);
for (digitalRead (6)==LOW) //DOES ADDING FOR… AFTER IF/ELSE WORK???
lcd.print (SETUP READY);
In the way I have done it now it acts with a normal electric switch and the only functionality is to drive the assembly with the desired speed. Therefore I have many questions and if you got so far reading this I would be really grateful to hear some ideas.
Firstly I do not understand how to use a pushbutton in order to start the air supply and run the whole thing automaticaly. Since I define the pin 6 should be high in the loop itself as far as I understand if a pushbutton is used the moment it is released the tool will stop. How can I define it then in diferent way? I still want to have a loop checking the button status so that the display shows something like “tool ready” before the button is pressed.
Secondly how can I make the if/else if statements run for certain time once the speed is reached?
Also is it even possible to use the for command after the if/else if statements so that in case the button is not pressed the display still gives feedback that tool is operational?
Finally where am I supposed to define the frequency calculation - in the for loop or outside of it?
This is quite much information sorry! I already spend the whole day on this and I am a bit discouraged so I hope I gave good feedback on the purpose of the code. I dont expect to receive ready code and its not the purpose of my registration here. I would be really happy if somebody would point me what control structures can be combined and how in order to achieve the functionality. Thanks a lot for reading !