HI! guys!!!! I have a problem. When my arduino is plugged in the PC USB port the sketch works and executes perfectly, but whenever I power the arduino with an external power supply(from a step-up converter it is at 7.5vDC) the sketch wont run. Any ideas what causes this and on how to fix it?
I tried to troubleshoot it and did a bit of research on it. So here is what I did
1.) tried uploading the blink sketch (to check if the problem is on the software side) and ran the sketch with the arduino connected to PC USB and it worked, but when I connected the arduino to an external power supply thesame problem occurred and the LED did not blink.
2.) I also connected a 10k ohm resistor in between RX pin and TX pin. Still it did not solve my problem. BTW I am using an arduino nano.
Please help me out guys. I really need to finish this project for school.
... below is my source code.
/*
Typical pin layout used: RFID
-----------------------------------------------------------------------------------------
MFRC522 Arduino Arduino Arduino Arduino Arduino
Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro
Signal Pin Pin Pin Pin Pin Pin
-----------------------------------------------------------------------------------------
RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
SPI SS SDA(SS) 10 53 D10 10 10
SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16
SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14
SPI SCK SCK 0 13 / ICSP-3 52 D13 ICSP-3 15
*/
#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>
#include <MFRC522.h>
#include <TinyGPS.h>
#define SS_PIN_RFID 10
#define RST_PIN_RFID 9
#define ph_num "09271806021" //ari ibutang phone number
#define PIN_TX_808 7 //sim808_tx_in module tx is to tx(idk why haha)
#define PIN_RX_808 8 //sim808_rx_in module rx is to rx (idk why haha)
#define buzz_pin 5
#define EP 4 //vibration sensor pin
MFRC522 rfid(SS_PIN_RFID, RST_PIN_RFID); // Create MFRC522 instance
SoftwareSerial gps2(PIN_TX_808, PIN_RX_808);
DFRobot_SIM808 sim808(&gps2); //Connect RX,TX,PWR,
TinyGPS GPS;
int pass_string[4] = {240, 190, 103, 77}; //UID of the RFID card
//String pass_string2 = "82,192,48,91";
String googlePrefix = "http://maps.google.com/maps?q=";
const long interval = 20000;
unsigned long prevMillis = 0;
float lat, longi;
float speedo;
//this is for alarm periphirals
bool disarmNotif = false;
bool armNotif = false ;
bool alarmTriped = false;
bool posGPS = false;
bool posGPS2 = false;
void setup() {
//Serial.begin(9600);
gps2.begin(9600);
pinMode(buzz_pin, OUTPUT);
pinMode(EP, INPUT);
SPI.begin(); // Init SPI bus
rfid.PCD_Init(); // Init MFRC522
while (!sim808.init()) {
delay(1000);
Serial.print("Sim808 init error\r\n");
}
//************* Turn on the GPS power************
while ( !sim808.attachGPS()) {
digitalWrite(buzz_pin, HIGH);
delay(200);
digitalWrite(buzz_pin, LOW);
delay(50);
digitalWrite(buzz_pin, HIGH);
delay(200);
digitalWrite(buzz_pin, LOW);
delay(50);
digitalWrite(buzz_pin, HIGH);
delay(200);
digitalWrite(buzz_pin, LOW);
}
Serial.println("Open the GPS power ok");
}
//////////////////////////////////////////CUSTOM FUNCTIONS///////////////////////////////////////
long vibra_out() {
long measurement = pulseIn (EP, HIGH); //wait for the pin to get HIGH and returns measurement
return measurement;
}
bool verify_rfid() {
int i = 0;
boolean match = true;
while (i < rfid.uid.size)
{
if (!(rfid.uid.uidByte[i] == pass_string[i]))
{
match = false;
}
i++;
}
if (match) {
if (!disarmNotif) {
disarmNotif = true;
digitalWrite(buzz_pin, HIGH);
delay(200);
digitalWrite(buzz_pin, LOW);
delay(50);
digitalWrite(buzz_pin, HIGH);
delay(200);
digitalWrite(buzz_pin, LOW);
//resets evertyhing
armNotif = false;
alarmTriped = false;
posGPS2 = false;
return true;
}
}
else {
Serial.print("Invalid RFID!\n");
return false;
}
}
/////////////////////////////////////////////////////END OF CUSTOM FUNCTIONS/////////////////////////////
void loop() {
// Look for new cards
if ( ! rfid.PICC_IsNewCardPresent()) {
long vibra_read = 0;
if (!armNotif) {
armNotif = true;
digitalWrite(buzz_pin, HIGH);
delay(750);
digitalWrite(buzz_pin, LOW);
//arms alarm
disarmNotif = false;
posGPS = false;
}
if (!alarmTriped) {
vibra_read = vibra_out();
Serial.print("Vibra Reading: "); // displays the reading of the sensor
Serial.println(vibra_read);
if (vibra_read >= 1000) { //if the reading from the motion sensor exceeds 30k it triggers the system to send the user a notification through text message.
alarmTriped = true;
}
}
else {
byte a;
unsigned long currentMillis = millis();
String message;
while ( gps2.available() > 0 ) // if there is data coming from the GPS shield
{
a = gps2.read(); // get the byte of data
if (GPS.encode(a)) // if there is valid GPS data...
{
GPS.f_get_position(&lat, &longi);
// Serial.println("--------------------------------------------------------------");
// Serial.print("Lat: ");
//Serial.print(lat, 5);
// Serial.print(" Long: ");
//Serial.println(longi, 5);
// Serial.print(GPS.f_speed_kmph());
// Serial.println("km/h");
speedo = GPS.f_speed_kmph();
}
}
message = "Alert!\nYour bicycle has been stolen! It is currently at\nLocation: " + googlePrefix + String(lat, 5) + "," + String(longi, 5) + "\nSpeed: " + String(speedo) + " km/hr";
if (currentMillis - prevMillis >= interval) {//this part is where it sends the message at a defined interval
prevMillis = currentMillis;
char charbuff[message.length()];
message.toCharArray(charbuff, message.length() + 1);
Serial.println();
Serial.println(charbuff); // displays the converted String message to char on Serial monitor.
if (sim808.sendSMS(ph_num, charbuff)) {
Serial.println("sent message"); //displays confirmation that the message was sent.
}
else {
Serial.println("message sending failed");
}
}
}
//Serial.print("Alarm armed: ");
//Serial.println(alarmArmed);
return;
}
// Select one of the cards
if ( ! rfid.PICC_ReadCardSerial()) {
return;
}
while (verify_rfid()) {
// Stop encryption on PCD
rfid.PCD_StopCrypto1();
if ( ! rfid.PICC_IsNewCardPresent()) {
break;
}
}
byte a;
while ( gps2.available() > 0 ) {
a = gps2.read(); // get the byte of data
Serial.write(a);
if (GPS.encode(a)) // if there is valid GPS data...
{
if (!posGPS) {
posGPS = true ;
digitalWrite(buzz_pin, HIGH);
delay(50);
digitalWrite(buzz_pin, LOW);
delay(50);
digitalWrite(buzz_pin, HIGH);
delay(50);
digitalWrite(buzz_pin, LOW);
}
GPS.f_get_position(&lat, &longi);
///Serial.println("--------------------------------------------------------------");
//Serial.print("Lat: ");
// Serial.print(lat, 5);
//Serial.print(" Long: ");
//Serial.println(longi, 5);
speedo = GPS.f_speed_kmph();
//Serial.println("km/h");
}
}
// Serial.print("Alarm armed: ");
//Serial.println(alarmArmed);
}
Replies would be very much appreciated.