LED problem with nano clone & 9V battery

I have a nano clone with an IR sensor switching between two LEDs depending on the sensor’s analog signal.
When I power the device with USB all is fine, flame detected = red light blinks, flame out = blue light blinks!
But when switched over to 9V battery on Vin, one of the LEDs (blue on pin2) remains permenantly illuminated.
In the “flame off” state the pin2 LED blinks up to full brightness but still never fully turns off.
In the “flame on” state, red LED blinks as expected and the blue LED remains on.
Back on to USB and all is well again!
Is there a trick with the nano when running off 9V or (more likely) something I’m doing thats fundamentally wrong !?

#define FLAME_DETECT A7     
#define FLAME_ON_LED 3
#define FLAME_OFF_LED 2
int Sensitivity = 350;
                                  
void setup()
{
  pinMode(FLAME_ON_LED, OUTPUT);
  pinMode (FLAME_OFF_LED, OUTPUT);
}

void loop()
{
  int Flame = analogRead(FLAME_DETECT);
  if (Flame < Sensitivity) {
    digitalWrite (FLAME_OFF_LED, LOW);
    flameON();
  }
  else {
    digitalWrite (FLAME_ON_LED, LOW);
    flameOFF();
  }
   
  delay(1000);   
}


void flameON(){
  digitalWrite (FLAME_ON_LED, HIGH);
  delay (50);
  digitalWrite (FLAME_ON_LED, LOW);
  delay (3000);
}
void flameOFF(){
  digitalWrite (FLAME_OFF_LED, HIGH);
  delay (800);
  digitalWrite (FLAME_OFF_LED, LOW);
  delay (500);
}

Budgebrewer:
I have a nano clone with an IR sensor switching between two LEDs depending on the sensor’s analog signal.
When I power the device with USB all is fine, flame detected = red light blinks, flame out = blue light blinks!
But when switched over to 9V battery on Vin, one of the LEDs (blue on pin2) remains permenantly illuminated.
In the “flame off” state the pin2 LED blinks up to full brightness but still never fully turns off.
In the “flame on” state, red LED blinks as expected and the blue LED remains on.
Back on to USB and all is well again!
Is there a trick with the nano when running off 9V or (more likely) something I’m doing thats fundamentally wrong !?

#define FLAME_DETECT A7     

#define FLAME_ON_LED 3
#define FLAME_OFF_LED 2
int Sensitivity = 350;
                                 
void setup()
{
  pinMode(FLAME_ON_LED, OUTPUT);
  pinMode (FLAME_OFF_LED, OUTPUT);
}

void loop()
{
  int Flame = analogRead(FLAME_DETECT);
  if (Flame < Sensitivity) {
    digitalWrite (FLAME_OFF_LED, LOW);
    flameON();
  }
  else {
    digitalWrite (FLAME_ON_LED, LOW);
    flameOFF();
  }
   
  delay(1000);   
}

void flameON(){
  digitalWrite (FLAME_ON_LED, HIGH);
  delay (50);
  digitalWrite (FLAME_ON_LED, LOW);
  delay (3000);
}
void flameOFF(){
  digitalWrite (FLAME_OFF_LED, HIGH);
  delay (800);
  digitalWrite (FLAME_OFF_LED, LOW);
  delay (500);
}

may be related to how you are powering the sensor.

did you try to put serial print in after you read FLAME_DETECT to see what value you return with/without USB?

mmmm… and there IS a difference :
USB dark value = 1000, light value = 20
9V dark value = 1000, light value = 290
(hence the threshold of 350 chosen for the sensitivity)

Using the Vin supply seems to be injecting pin2 …

OK, so perhaps post a schema showing how you are powering the sensor.

also, what type of sensor are you using (i.e. what is its power consumption?)

This is the sensor I’m using:
http://www.banggood.com/Flame-Detection-Sensor-Module-KY-026-Flame-Sensor-Module-Red-Arduino-p-91806.html

I haven’t been able to find any specs quickly and haven’t yet measured,
but its getting 5V from pin#27 of the nano and reading on pin#26 (Analog 7 on my nano version)

Budgebrewer: This is the sensor I'm using: http://www.banggood.com/Flame-Detection-Sensor-Module-KY-026-Flame-Sensor-Module-Red-Arduino-p-91806.html

I haven't been able to find any specs quickly and haven't yet measured, but its getting 5V from pin#27 of the nano and reading on pin#26 (Analog 7 on my nano version)

and you have the battery attached to equivalent of Pin 30? Which nano are you using?

I can't account for why the sensor will output different voltage if it is excited from the same flame source and powered with 5V either way.

Can you measure the voltage supplied to the sensor in both configurations?

That's correct - 9V to Vin (pin 30).

... the KangDigital ebay special ... http://www.ebay.com.au/itm/Nano-3-0-Controller-Board-Compatible-with-Arduino-Nano-CH340-USB-Driver-/351080750215?pt=LH_DefaultDomain_15&hash=item51be0b1c87&_uhb=1

I've removed the sensor and simulated high and low signals on the Analog pin but whup !... still get unexpected volts on that digital pin Swapped LEDs to pins further up the board and still the blue (flame off) pin goes hot when on battery.

Budgebrewer: I've removed the sensor and simulated high and low signals on the Analog pin but whup !... still get unexpected volts on that digital pin

not sure what that means....

check the expected 5 volts to the sensor in USB and Battery configurations. It sounds like they may be different.

You know never to connect anything above 5V to any pin on the Arduino (other than Vin)?

In other words the only 9V wire is from 9V supply to Vin and everything else is powered from the Vcc pin?

Talking of which the Nano cannot supply much current out on the Vcc pin so an external 5V regulator may be needed to power external circuitry.

You need to show us your circuit....

My inexpensive nano v.3 shows 4.6V at a multimeter when powered from usb, with 2m cable, and can show 5.0V at its 5V pin when powered from a a battery to V_in instead. Make sure that your hardware for sensors will ignore such a change.

Though the digital in/out pins are rated at more than 20mA, it is highly recommended to keep current draw through the chip below 1mA if possible by placing >4.7kOhm resistors between your nano and your sensor hardware. You might also want to consider whether your IR components could go in a circuit driven from the nano 3.3V, as that wastes less power than a 5V drive and does not depend on the usb|battery choice but (recommended) ought to have an extra transistor or fet to convert 3.3V to !5V

ad2049q: My inexpensive nano v.3 shows 4.6V at a multimeter when powered from usb, with 2m cable, and can show 5.0V at its 5V pin when powered from a a battery to V_in instead. Make sure that your hardware for sensors will ignore such a change.

Though the digital in/out pins are rated at more than 20mA, it is highly recommended to keep current draw through the chip below 1mA if possible by placing >4.7kOhm resistors between your nano and your sensor hardware. You might also want to consider whether your IR components could go in a circuit driven from the nano 3.3V, as that wastes less power than a 5V drive and does not depend on the usb|battery choice but (recommended) ought to have an extra transistor or fet to convert 3.3V to !5V

he's using a breakout board, capable of working in the range of voltages.

Budgebrewer: This is the sensor I'm using: http://www.banggood.com/Flame-Detection-Sensor-Module-KY-026-Flame-Sensor-Module-Red-Arduino-p-91806.html

You know never to connect anything above 5V to any pin on the Arduino (other than Vin)?

Yes.

In other words the only 9V wire is from 9V supply to Vin and everything else is powered from the Vcc pin?

Correct.

So throught the course of this thread we've established that the problem exists independantly of the sensor breakout board (designed for use with arduino) and the remaining circuit - which has been well described in the thread consists of:

No sensor, but the analog pin is being referenced as per the sketch. Two output pins driving LEDs (with an appropriate current limiting resistor). Apply 9V externally and one of the LED pins goes high (less than 5V - i don't need a multimeter to show me the LED is lit at about half brightness - when the sketch puts the pin to 5V the LED appears at expected brightness)

I'll swap out the nano when I get back to the project tonight.

Swapped out the nano and all now works as it should! One of life's little mysteries I guess... I'll press the miscreant nano back in to service another time and see if I can't track down it's gremlin. Thankyou to all who took the time to ponder this unusual problem.

I realize that this thread has been dormant for over six years, but I wanted to report that I just had the same experience as the original poster and that swapping out the nano clone proved to be the only solution I was able to find.