Undefined reference to `'my file (unsigned char, unsigned char, bool)'

I basically took two codes from the internet one for an earthquake detector and a second to attach that with a GSM.
I compiled both codes, did some basic things but I am getting this error while I run it. and in the end, it says "error: exit status 1". Please help me with this, this is for my school project.

The code is :

#define buzzer 12
#define x A0
#define y A1
#define z A2

int xsample=0;
int ysample=0;
int zsample=0;
long start;
int b=0;
#define samples 50
#define maxVal 20
#define minVal -20
#define buzTime 2000

void setup()
{
Serial.begin(9600);
delay(1000);
pinMode(buzzer, OUTPUT);
b=0;
digitalWrite(buzzer, b);
for(int i=0;i<samples;i++)
{
xsample+=analogRead(x);
ysample+=analogRead(y);
zsample+=analogRead(z);
}

xsample/=samples;
ysample/=samples;
zsample/=samples;

#include<SoftwareSerial.h>
SoftwareSerial gsm(2,3);

delay(10000);
Serial.begin(9600);
gsm.begin(9600);
gsm.println("AT+CMGF=1");
delay(1000);
gsm.println("AT+CMGS="+91xxxxxxxxxx"\r"); //replace x by your number
delay(1000);
gsm.println("hello");
delay(100);
gsm.println((char)26);
delay(1000);
}

void loop()
{
int value1=analogRead(x);
int value2=analogRead(y);
int value3=analogRead(z);

int xValue=xsample-value1;
int yValue=ysample-value2;
int zValue=zsample-value3;



if(xValue < minVal || xValue > maxVal  || yValue < minVal || yValue > maxVal  || zValue < minVal || zValue > maxVal)
{ 
  if(b == 0)
  start=millis();
   b=1;
} 

else if(b == 1)
{
if(millis()>= start+buzTime)
b=0;
}
digitalWrite(buzzer, b);
Serial.print("x=");
Serial.println(xValue);
Serial.print("y=");
Serial.println(yValue);
Serial.print("z=");
Serial.println(zValue);
Serial.println(" $");
}

Three things you need to do

  1. Read the forum introduction
  2. Edit your post and put the code in code tags
  3. Copy and paste the entire compile error listing.
  1. Read a tutorial on how to merge two sketches.
1 Like

You should put #include statements at the top, not inside setup().

#include<SoftwareSerial.h>

#define buzzer 12
#define x A0
#define y A1
#define z A2

int xsample = 0;
int ysample = 0;
int zsample = 0;
unsigned long start;
int b = 0;
#define samples 50
#define maxVal 20
#define minVal -20
#define buzTime 2000

void setup()
{
  Serial.begin(9600);
  delay(1000);
  pinMode(buzzer, OUTPUT);
  b = 0;
  digitalWrite(buzzer, b);
  for (int i = 0; i < samples; i++)
  {
    xsample += analogRead(x);
    ysample += analogRead(y);
    zsample += analogRead(z);
  }

  xsample /= samples;
  ysample /= samples;
  zsample /= samples;


  SoftwareSerial gsm(2, 3);

  delay(10000);
  Serial.begin(9600);
  gsm.begin(9600);
  gsm.println("AT+CMGF=1");
  delay(1000);
  gsm.println("AT+CMGS=91xxxxxxxxxx"); //replace x by your number
  delay(1000);
  gsm.println("hello");
  delay(100);
  gsm.println((char)26);
  delay(1000);
}

void loop()
{
  int value1 = analogRead(x);
  int value2 = analogRead(y);
  int value3 = analogRead(z);

  int xValue = xsample - value1;
  int yValue = ysample - value2;
  int zValue = zsample - value3;



  if (xValue < minVal || xValue > maxVal  || yValue < minVal || yValue > maxVal  || zValue < minVal || zValue > maxVal)
  {
    if (b == 0)
      start = millis();
    b = 1;
  }
  else if (b == 1)
  {
    if (millis() >= start + buzTime)
      b = 0;
  }
  digitalWrite(buzzer, b);
  Serial.print("x=");
  Serial.println(xValue);
  Serial.print("y=");
  Serial.println(yValue);
  Serial.print("z=");
  Serial.println(zValue);
  Serial.println(" $");
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.