undergroundgasil.blogg.se

4n25 optical isolator
4n25 optical isolator










4n25 optical isolator
  1. #4n25 optical isolator serial
  2. #4n25 optical isolator code

The script follows: const int dataLedPin = 4 // LED indicating sensor data is received I only put the LED from 4n25 emitter to ground to show the pulses from my electricity meter and the same problem exists when the emitter is grounded. I added the println if no pulses were detected to help debug it and all it outputs is 0 (indicating no interrupts incremented the sensor variable).

#4n25 optical isolator serial

written meter readings to the serial port). In addition to the above there are 2 LED outputs from arduino digital pins 4 and 5 to show a loop has completed and we've logged a meter reading (i.e. The TSL261 is blue tacked over the LED on my electricity meter which flashes once for every watt. Ok, everthing has been working for a few days now and all of sudden it has stopped working. Sensor += 1 //Update number of pulses, 1 pulse = 1 watt Void interruptHandler() // routine called when external interrupt is triggered Void printDigits(int digits, char seperator) Serial.print(',') // print comma to seprate from previous data Total += sensor_count //total watts counter Sensor_count = sensor //get the count from the interrupt handler Uint8_t oldSREG = SREG // save interrupt registerĬli() // prevent interrupts while accessing the count whilst I hold the push switch down to light If I uncomment the following the interrupt keeps firing PinMode(dataLedPin, OUTPUT) // LED interrupt indicator initializationĪttachInterrupt(logInterrupt, interruptHandler, FALLING)

4n25 optical isolator

Serial.begin(19200) // opens serial port, sets data rate to 19200 bps

4n25 optical isolator

Unsigned long total = 0 // Total power used since the sketch started ? Volatile unsigned long sensor = 0 // Counts power pulses in interrupt, 1 pulse = 1 watt LED pinsĬonst int dataLedPin = 4 // LED indicating sensor data is receivedĬonst int logLedPin = 5 // LED flashes during a log attempĬonst int logInterrupt = 1 // ATmega 168 and 328 - interrupt 0 = pin 2, 1 = pin 3 Why? As soon as I turn the LED dataLedPin on/off then whilst I am holding the switch down to light the LED sat next to the sensor the interrupt keeps firing.

#4n25 optical isolator code

I have the code below and it works fine so long as I don’t turn another LED on and off. A push switch switches the LED on and on releasing the switch the LED is turned off. I have a simple setup with a TLS261 light sensor and an LED blue tacked together (ok, not perfect) so the tls261 only sees light from the LED. I am still an Arduino noob so please bare with me.












4n25 optical isolator