Thanks for the blunt reply PaulS, I see now that taking the effort do make a nice introduction (unlike some other people that only leeches of the forum) was a waste of time.
Personally, I think you are wasting your time writing code for something you don't even have. There will be plenty of time to work out all that is potentially wrong with that code when you have hardware to test with.
I don't expect the code will just magically work because it compiles ok. I know the real issues will start arising when the hardware is active. I'm just anxious to get going and thought of using the time while I wait for the solenoid to start doing some work. At least I'm trying ![]()
For instance, how do you plan to connect the switches?
If you wire the switch the easy way, LOW will mean pressed.
Following this : http://www.arduino.cc/en/Tutorial/button button state will be HIGH if pressed. Or am I wrong?
What is a glassSensor? Why is Pin missing from the name? You are not really reading from a glassSensor. You are reading from a pin that might have a glass sensor, whatever that is, attached to it.
It's just a switch that gets depressed once a glass is in place. I changed the code accordingly. Hope it looks better now?
Connecting a switch to pin 1 is not a good idea. You'll learn why when you start trying to debug your code.
Ok, will keep an eye on that one. I like doing things in an orderly fashion, so thought of keeping the inputs to one side of the arduino and outputs to the other.
EDIT --> I see now that pin 1 is used for serial comms. That will stick in the back of my mind from now on XD (Made the neccesary changes).
I wonder if this should be maybe 1248. Or 1251. Magic numbers belong at the top of the code, with #define's names or variable names, so that they can be changed easily when the magic number turns out to be wrong.
That does make sense. I've added and changed to the code. I hope it is ok? The current magic number is only for an illustrative purpose. The precise number will be determined once the hardware is up and running and the flow through the solenoid can be determined.
Thanks for the pointers PaulS, I hope to hear more from you.
Here's the amended code :
/*
Fluid Dispenser v1.0
written by : Theo Gresse
Date : 15/10/2012
*/
const int buttonPressPin = 2; //refers to the pin where the button is connected for user input
const int glassSensorPin = 3; //refers to a button that is depressed by the weight of a glass
const int relayOutPin = 13; //refers to the pin being used to trigger the relay
const int delayTime = 1250; //constant value assigned to delayTime, used to keep solenoid valve open
void setup() //setup
{
pinMode(buttonPressPin, INPUT); //buttonPress defined as an input
pinMode(glassSensorPin, INPUT); //glassSensor defined as an input
pinMode(relayOutPin, OUTPUT); //relayOut defined as an output
}
void loop() //start of loop
{
if (digitalRead(buttonPressPin) == LOW //if the signal from the button is HIGH (or pressed)
&& //and
(digitalRead(glassSensorPin) == LOW))//if the signal from the glassSensor is HIGH (or pressed)
{ //then
digitalWrite(relayOutPin, HIGH); //activate the relay
delay(delayTime); //keep relay activated long enough to dispense certain volume
digitalWrite(relayOutPin, LOW); //deactivate the relay
}
else
{
digitalWrite(relayOutPin, LOW); //no button pressed, no action taken, relay deactivated
}
} //end loop