Page 1 of 1

Internal exception "error"

Posted: 30 Mar 2016 22:01
by nsrkhn123
#include <LiquidCrystal.h>
#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;
/*********************************************************************
INITIAL CONFIG
*********************************************************************/

const int pingPin = 4;
const int echoPin = 5;

#define limit_max 1000 // 500cm
#define limit_min 100 // 100cm

#define streetlight 3 // pin trigger alarm
#define LedPing 13 // pin Led ping Sensor
int pir = 2;
int ldr = A0;
int ldrvalue = 0;
/*********************************************************************
SETUP - FUNCTION
*********************************************************************/


// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void setup()
{
pinMode(streetlight, OUTPUT);
pinMode(LedPing, OUTPUT);
digitalWrite(streetlight, LOW);
digitalWrite(LedPing, LOW);
pinMode(pir, INPUT);
// initialize serial communication:
Serial.begin(9600);
lcd.begin(20,4);
{

#ifdef AVR
Wire.begin();
#else
Wire1.begin(); // Shield I2C pins connect to alt I2C bus on Arduino Due
#endif
rtc.begin();

if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// following line sets the RTC to the date & time this sketch was compiled
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
// This line sets the RTC with an explicit date & time, for example to set
// January 21, 2014 at 3am you would call:
// rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
}
}
}



/*********************************************************************
LOOP - FUNCTION
*********************************************************************/



void loop()
{
ldrvalue = analogRead(ldr);
Serial.print("LDR = ");
Serial.print(ldrvalue);
if (ldrvalue <= 600)
{
{
DateTime now = rtc.now();

lcd.setCursor(0, 2);
lcd.print("DATE ");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);

lcd.setCursor(0, 3);
lcd.print("TIME ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);

}
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;

digitalWrite(LedPing, HIGH);
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);

// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(echoPin, INPUT);
duration = pulseIn(echoPin, HIGH);

// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);


// SERIAL DEBUG
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");

lcd.setCursor(0, 0);
lcd.print(" Dist in inch = ");
lcd.print(inches);

lcd.setCursor(0, 1);
lcd.print(" Dist in CM = ");
lcd.print(cm);

if((cm < limit_min) || (cm > limit_max) || digitalRead(pir)== HIGH){
digitalWrite(LedPing, LOW);
digitalWrite(streetlight, HIGH);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" Detected car! ");

Serial.print(" Detected car!");
Serial.println();

delay(2000);
digitalWrite(streetlight, LOW);
}else{
Serial.println();
}

digitalWrite(LedPing, LOW);
delay(100);
}else
{
DateTime now = rtc.now();

lcd.setCursor(0, 2);
lcd.print("DATE ");
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);

lcd.setCursor(0, 3);
lcd.print("TIME ");
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
lcd.print(':');
lcd.print(now.second(), DEC);




lcd.setCursor(0, 0);
lcd.print(" DAY TIME ");
lcd.setCursor(0, 1);
lcd.print(" ");
}
}




/*********************************************************************
SUBROTINES
*********************************************************************/

long microsecondsToInches(long microseconds)
{

return microseconds / 87 / 2;
}



//-------------------------------------------------------------------
long microsecondsToCentimeters(long microseconds)
{

return microseconds / 29 / 2;
}




/*********************************************************************
END
*********************************************************************/



plz help me

Re: Internal exception "error"

Posted: 31 Mar 2016 11:04
by uros.cvetinovic
Hi,

Can you please be more specified?

What are you trying to achieve?

Which compiler do you use?

Which hardware and MCU do you use?

Best regards,

Uros