Hello,
I am trying to get an LED to light up in response to a PIR motion sensor being triggered. I am using a Arduino trinket to do this.
When I checked the code I had with an Arduino Uno board selected the code was fine. However, when I selected The Arduino Gemma as the board, (this is what the adafruit website suggested as arduino trinket does not show on my list of boards)the board showed me this error message:
Arduino: 1.6.9 (Windows 10), Board: "Arduino Gemma"
In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:224,
from C:\Users\Noelle\Documents\Arduino\IronMan_s_eyes\IronMan_s_eyes.ino:1:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:32:0: warning: "BIN" redefined [enabled by default]
#define BIN 2
^
In file included from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iotn85.h:38:0,
from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\io.h:428,
from c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\pgmspace.h:88,
from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:28,
from C:\Users\Noelle\Documents\Arduino\IronMan_s_eyes\IronMan_s_eyes.ino:1:
c:\program files (x86)\arduino\hardware\tools\avr\avr\include\avr\iotnx5.h:55:0: note: this is the location of the previous definition
#define BIN 7
^
C:\Users\Noelle\Documents\Arduino\IronMan_s_eyes\IronMan_s_eyes.ino: In function 'void setup()':
IronMan_s_eyes:14: error: 'Serial' was not declared in this scope
Serial.begin(9600);
^
exit status 1
'Serial' was not declared in this scope
I have looked on several websites and forums and I can not find anyone trying to use an arduino trinket with the Adafruit PIR motion sensor. Here is the code that I am working with:
#include <Arduino.h>
int calibrationTime = 30; //the time we give the sensor to calibrate itself (10-60 secs according to the datasheet)
long unsigned int lowIn; //the time when the sensor outputs a low impulse
long unsigned int pause = 5000; //the amount of milliseconds the sensor has to be low before we assume all motion has stopped
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 2; //the digital pin connected to the PIR sensor's output
int ledPin = 1;
void setup()
{
Serial.begin(9600);
pinMode(pirPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating sensor ");
for(int i = 0; i < calibrationTime; i++)
{
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
}
void loop()
{
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, HIGH); //the led visualizes the sensors output pin state
if(lockLow){
//makes sure we wait for a transition to LOW before any further output is made:
lockLow = false;
Serial.println("---");
Serial.print("motion detected");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, LOW); //the led visualizes the sensors output pin state
if(takeLowTime){
lowIn = millis(); //save the time of the transition from high to LOW
takeLowTime = false; //make sure this is only done at the start of a LOW phase
}
//if the sensor is low for more than the given pause,
//we assume that no more motion is going to happen
if(!lockLow && millis() - lowIn > pause){
//makes sure this block of code is only executed again after
//a new motion sequence has been detected
lockLow = true;
//Serial.print("motion ends"); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}
If anyone can help me fix this problem I would be very grateful.
Thanks