I want to create an arduino sketch that will take input from the positive and negative terminals of an LED and keep a cumulative count of how many times the LED lights up and output this to a 128x64 OLED and it will show how many times the LED lit up in the last hour, and the last 24 hours, and the last month.
Any ideas/suggestion greatly appreciated for this neophyte.
See how the following setup (Fig-1) goes!
You excite LED1 with known analogWrite() function for 5 seconds during which LED1 will be On/Off. You measure the voltage at A0-pin to detect the Off-states of LED1, which can be displayed on SM/OLED.
The OP has been asked to take connection from across the terminals of the LED. When the LED is ON, the voltage across it is about 2.5V (my LED shows: 1.7V) which is below VIH (3.0V) specification of ATmega328P MCU of the UNO Board; so, On/Off conditions of the LED can not be accounted by digitalRead() function.
So, my idea is to On/Off the LED by analogWrite(9, 128) at 490 times/sec and then count the On states for 5-sec through the evaluation of analogRead(A0) function. Let me do the experiment.
This is the outcome of my experiment with 7.8% error which can be brought down to 2% (I hope so) by tuning the delay! Theoretical values is: 490x5 = 2450.
OK, I'm learning as I go from watching YT vids. Actually I'm making a Muon detector that doesn't involve an arduino. I have the components for that and a diagram for connections. It will light up a LED every time a muon is detected. No problem getting that far but I don't want to have to sit around and watch for the LED to blink every now and then so that is why I want to add an arduino nano after this and output to an OLED and have it keep track of the muons detected (daily and weekly and monthly cumulative totals displayed on the OLED.
I have purchased a 74HC08 And Gate that I think is needed to work with the Nano. Presume the 74HC08 will be between the LED and the Nano. My sketch knowledge is very limited so that is where I was looking for guidance inasmuch as the And Gate will, I believe, track the LED lighting up and able to send that to the nano.
Hope I explained that OK. In the next few days I should have the muon detector completed with the LED flashing when a muon is detected and I can update with a video link.
Thanks for all the kind replies!
Correction- the 74HC08 will be used to detect the simultanuous input from 2 geiger counters to light up the LED. I have updated and corrected my original post.
2. Voltage drop across LED varies from 1.5V to 2.5V with 10 mA current passing through it. No doubt that the On/Off states of a LED are digital events; unfortunately, we cannot handle them using digitalReadd() instruction. My ADC approach has given acceptable results in Arduino UNO Platform.
In that case, you have to set the discrimination level (the threshold) externally using hardware at one input-pin (usually AIN0) of the comparator, which depends on the voltage drop of the LED. Better to adjust it programmatically using the internal ADC.
unsigned long presentMillis;
int myCount;
void setup()
{
Serial.begin(9600);
analogWrite(9, 128); //490 Hz square wave
}
void loop()
{
presentMillis = millis();
while (millis() - presentMillis < 5000)
{
unsigned int y = analogRead(A0);
if (y > 347) //1023/5*1.7 ~= 347; adjustable discrimination level = f(LEDVOLT)
{
myCount++;
}
delayMicroseconds(900); // to adjust for the ON-time of 490 Hz PWM
}
Serial.println(myCount);
myCount = 0;
}
Output: for 5-sec (expected: 490 x 5 = 2450) with 0.9% error.