Hello,
I've designed a working circuit that, when the circuit completes it should create a 5V high pulse, which lasts up to a maximum of 0.5s.
I've then wired up my mega2560 to monitor an input and to then update, adding 1 count for every pulse, if the pulse stays high it shouldn't add to the count.
I have several queries regarding this and I'll try to number them:
1st. What does, what I've actually typed...mean, I've managed to skif together this program by looking at other similar type things but I'm not 100% sure what everything does, short of the very very basics in programming an arduino.. (I am new)
2nd. When I open the Serial Monitor, it is updating constantly, even when there are no changes, it spams this very quickly to the point it does sometimes miss a pulse, I want to point out that my pulses are by no means fast, I'm looking for this circuit to maybe complete like at most, a few times in under 5 seconds. so, how can I have the Arduino monitor the pin for changes in digital input without updating the Serial when there are no changes.
3rd. I'm looking to then export this count onto an LCD display or some form of digital counter, can anyone please advise me on this as I have absolutely no idea where or how to start.. :<
I've also attached a drawing of the circuit which creates the pulse, it is working in its current form on a breadboard but, it is incomplete as I have been unable to get the arduino to count in a way I am comfortable with in the last like 4 days!
Background: I'm pretty much brand new to Arduino programming and base level electronics, so this is a big learning curve. you can contact me on Telegram @DieselRulez if you want to have a more 1 to 1, live conversation with me, I'd very much appreciate the help and can show video's of whats going on incase I've described it poorly :>
The Circuit: The point above "C" is the +5V supply and all of the Grounds are connected together, the lower half can be ignored as its not actually needed right now, I am focusing on the circuit that is made between the two AND gates to achieve a U/S Count (Upstream Count).
photo_2021-08-15_20-47-56|236x500
The Code (Credit to whomever made the actual count code, this was not me!:
int AND1I = 2;
int AND1O = 3;
const int AND2I = 4;
int AND2O = 5;
int var = 0;
int pulse = 0;
void setup() {
// put your setup code here, to run once:
pinMode(2, INPUT);
pinMode(4, INPUT);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
Serial.begin(9600);
Serial.println(F("no pulses yet... >:I"));
Serial.print(F("Program Entering Loop"));
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(AND1I) == HIGH)
{
digitalWrite(AND1O, HIGH);
delay(1000);
}
if (digitalRead(AND1I) == LOW)
{ digitalWrite(AND1O, LOW);}
//BLANK FOR NEW LAYER OF CODE FOR PULSE COUNT
if(digitalRead(4) > var) { var = 1; pulse++;
}
Serial.print(pulse); Serial.print(F(" pulse"));
// Put an "s" if the amount of pulses is greater than 1. if(pulse > 1) {Serial.print(F("s"));}
Serial.println(F(" detected."));
if(digitalRead(4) == 0) {var = 0;}
delay(50);
}
// Delay for stability. }