I'm doing a simple project for class, I am using a IR photogate to count the co2 bubbles that are released during the beer/wine brewing process, using a teensy 3.1. I picked up a IR photograte from sparkfun and soldered it together. I have some code written out and I should have everything hooked up correctly on my bread board. I wanted to try to use VB for a external editor but I do not know VB and we didn't have enough time in class to go over it, and I think I should leave it for next year to learn. Right now I want the led to turn off and back on when a bubble passes through my gate. I'm just not sure where to put that line of code. Also I was thinking of using note pad as the external editor so that I can have some type of log. Sorry I am still new at this and in class we just speedy pass everything. Here is the code, thank you for your time. Please take it easy on me I am new at this. I found pieces of the code online and had a little help in class.
int ledpin = 13; // led is on pin 13
int photoPin = 2;
int val = 0;
int valold = 0;
unsigned int count = 0;
unsigned long sstart;
const int ledPin = 13;
void setup ()
{
pinMode(ledpin, OUTPUT);
pinMode(photoPin, INPUT);
valold = digitalRead(photoPin);
Serial.begin(9600);
}
void loop () // runs over and over
{
sstart = millis ();
digitalWrite(ledPin, HIGH);
if (val != valold) {
count ++;
valold = val;
}
// if over a min print out the counts
Serial.print("Bubbles per minute: ");
Serial.println(count,DEC);
}
It seems that you don't understand the difference between setup() and loop().
When the Arduino program starts it runs setup() once. That means the your command "valold = digitalRead(photoPin);" will happen once.
When setup() is finished loop() runs repeatedly. So
if (val != valold) {
count ++;
valold = val;
}
will run over and over for ever. What do you think will happen the variable called count (which, by the way does not seem to have beed declared anwhere). And what do you think will happen with the test "if (val != valold)".
The net effect of all this (I think) is that the presence of a bubble is only checked once and ........ ?
Separately, your use of the the phrase "using note pad as the external editor so that I can have some type of log" makes me think you have the wrong concept of what an editor does. An editor is the thing you use to write your code. It's job is complete wne you compile (verify and upload) your code. It has nothing to do with the output from the Arduino. The output can be viewed in the Arduino Serial Monitor or any other terminal such as puTTY. Most of those other terminals have the option of saving what they receive into a text file.
...R
I need it to continue to check for co2 bubbles to pass through the photogate so I want it to always be checking for one if possible, and for the led to blink every time a bubble passes through the gate. Oh also I need it to output the information somewhere else, in class I was able to get it to output the readings or results to note pad. That is what I am talking about for a external editor? How can I fix the code so that it works in this fashion? I've been trying to figure it out but I am not well versed enough to fix it on my own. I'm sorry if I'm confusing I'm trying my best to explain, but please help me if you can. Thank you.
My earlier comments should be sufficient to enable you to make a better second version of your code. Then we can move on a further step.
...R
Had a little help from my best friend how does this look now?
int ledpin = 13; // led is on pin 13
int photoPin = 2;
int val = 0;
int count = 0;
const int ledPin = 13;
const int time = 3600;
void setup ()
{
pinMode(ledpin, OUTPUT);
pinMode(photoPin, INPUT);
val = digitalRead(photoPin);
Serial.begin(9600);
}
void loop () // runs over and over
{
//the loop continually runs if(you read something from the input)
{
blink the led update the count (count++) if(the system time == time)
{
print();
}//end inner if }//end outer if
}//end loop //This is a function, I don't know the proper //way to write this
function print()
{
Serial.print("Bubbles per minute: ");
Serial.println(count,DEC);
}//end print
The old grey-matter seems to be on holiday. Let's try again.
Which line of your code detects the bubbles?
Where is that line of code?
How often does it detect bubbles?
And I strongly suspect that your code won't compile.
And please read the How to Use the Forum and learn how to put the code in code tags.
...R