Arduino doesn't work with external 9V battery, but works with USB cable

Hi guys, I have a project exhibition coming up in 3 days and my prototype isn’t working;

my input is an RDM6300 RFID sensor, outputs are 2 LED lights, an OLED screen and a piezo buzzer.

So I plugged it into the external 9v battery source, and it was working for awhile, but all of the suddenly the RFID sensor wouldn’t detect the tags anymore! The OLED screen was still working. But it still works when I plug it into my laptop.

This is my rough code. It’s supposed to act as a food detector to separate the ‘contaminated’ ones to the ‘uncontaminated’ ones.

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>

// If using software SPI (the default case):
#define OLED_MOSI 9
#define OLED_CLK 10
#define OLED_DC 11
#define OLED_CS 12
#define OLED_RESET 13
Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

/* Uncomment this block to use hardware SPI
#define OLED_DC 6
#define OLED_CS 7
#define OLED_RESET 8
Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
*/

#define NUMFLAKES 10
#define XPOS 0
#define YPOS 1
#define DELTAY 2

#define LOGO16_GLCD_HEIGHT 16
#define LOGO16_GLCD_WIDTH 16

static const unsigned char PROGMEM logo16_glcd_bmp =
{ B00000000, B11000000,
B00000001, B11000000,
B00000001, B11000000,
B00000011, B11100000,
B11110011, B11100000,
B11111110, B11111000,
B01111110, B11111111,
B00110011, B10011111,
B00011111, B11111100,
B00001101, B01110000,
B00011011, B10100000,
B00111111, B11100000,
B00111111, B11110000,
B01111100, B11110000,
B01110000, B01110000,
B00000000, B00110000
};

SoftwareSerial RFID(2, 3); // RX and TX
int i;
int data1 = 0;
int ok = -1;
int yes = 7;
int no = 6;
int ledPPin = 4; // standard white
int piezoPin = 8;

// use first sketch in http://wp.me/p3LK05-3Gk to get your tag numbers
int tag1[14] = {2, 49, 53, 48, 48, 49, 53, 51, 70, 66, 48, 56, 70, 3 };
int tag2[14] = {2, 49, 53, 48, 48, 49, 53, 53, 50, 50, 53, 55, 55, 3 };
int tag3[14] = {2, 49, 53, 48, 48, 49, 53, 69, 69, 52, 54, 65, 56, 3 };
int tag4[14] = {2, 49, 53, 48, 48, 49, 53, 53, 54, 55, 57, 50, 70, 3 };

int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // used for read comparisons

void setup() {
Serial.begin(9600);
RFID.begin(9600); // start serial to RFID reader
pinMode(yes, OUTPUT); // LED
pinMode(no, OUTPUT);
pinMode(ledPPin, OUTPUT);

// by default, we’ll generate the high voltage from the 3.3v line internally! (neat!)
display.begin(SSD1306_SWITCHCAPVCC);
// init done

// Show image buffer on the display hardware.
// Since the buffer is intialized with an Adafruit splashscreen
// internally, this will display the splashscreen.
display.display();
delay(2000);

// Clear the buffer.
display.clearDisplay();
display.display();

display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(30,0);
display.println("~~~~~~~");
display.setCursor(20,10);
display.setTextSize(1.7);
display.println(“F A M I N O I D”);
display.setTextSize(0.02);
display.println(“Est. 2095”);
display.display();
delay(3500);
display.clearDisplay();
display.clearDisplay();

}

boolean comparetag(int aa[14], int bb[14])
{
boolean ff = false;
int fg = 0;
for (int cc = 0 ; cc < 14 ; cc++)
{
if (aa[cc] == bb[cc])
{
fg++;
}
}
if (fg == 14)
{
ff = true;
}
return ff;
}

void checkmytags() // compares each tag against the tag just read
{
ok = 0; // this variable helps decision-making,
// if it is 1 we have a match, zero is a read but no match,
// -1 is no read attempt made
if (comparetag(newtag, tag1) == true)
{
ok++;
}
if (comparetag(newtag, tag2) == true)
{
ok++;
}
if (comparetag(newtag, tag3) == true)
{
ok++;
}
if (comparetag(newtag, tag4) == true)
{
ok++;
}
}

void readTags()
{
ok = -1;

if (RFID.available() > 0)
{
// read tag numbers
delay(100); // needed to allow time for the data to come in from the serial buffer.

for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data1 = RFID.read();
newtag[z] = data1;

}

//RFID.flush();

// do the tags match up?
checkmytags();

}

// now do something based on tag type
if (ok > 0) // if we had a match
{

tone(piezoPin, 1000, 1000);

Serial.println(“Accepted”);
digitalWrite(yes, HIGH);
delay(1000);

display.setTextColor(WHITE);
display.setCursor(30,0);
display.setTextSize(2);
display.println(“SAFE”);
display.setTextColor(WHITE);
display.setTextSize(1);
display.println(“Made in France”);
display.println(“no Titanium Oxide”);
display.display();
delay(4000);
display.clearDisplay();
display.display();
digitalWrite(yes, LOW);

ok = -1;
}
else if (ok == 0) // if we didn’t have a match // ADD SkULL IMAGE
{
tone(piezoPin, 700, 1000);

Serial.println(“Rejected”);
digitalWrite(no, HIGH);
delay(1000);

display.setCursor(0,0);
display.setTextSize(2);
display.println("!!UNSAFE!!");
display.setTextColor(WHITE);
display.setTextSize(0.1);
display.println(“Contains Titanium Oxide”);
display.display();
delay(4000);
display.clearDisplay();
display.display();
digitalWrite(no, LOW);
ok = -1;
}
}

void loop() {

while(RFID.read() > -1);

digitalWrite(ledPPin, HIGH);

display.setTextColor(WHITE);
display.setCursor(0,7);
display.setTextSize(1);
display.println(“Please point the”);
display.println(“Faminoid at food.”);
display.display();
display.clearDisplay();
display.clearDisplay();

readTags();

}

I would appreciate all the help I can get as I’m still relatively a beginner!!!

I plugged it into the external 9v battery source, and it was working for awhile, but all of the suddenly the RFID sensor wouldn't detect the tags anymore!

At a guess the PP3 battery that you used cannot supply enough current to power the system for very long. They really are weedy and not designed to deliver large amounts of current.

Try a much beefier battery.

The square kind of 9V battery are inappropriate for most Arduino projects. Try using AA or AAA batteries. They can deliver a lot more current.

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

These batteries are not suitable.

Thanks.. Tom... :slight_smile: