Got the Motion Sensor working and also the Light Sensor
Started playing with the Distance Sensor and it’s blowing up the serial console:
[code]Open ping reading pipe: 255
Tx: fr=255,to=255,la=255,ne=255,ci=255,mt=4,ty=9,cr=184:
Sent successfully
Message available on pipe 7
Message available on pipe 7
(imagine a hundred or so of these here…)
Message available on pipe 7
Message available on pipe 7
No relay nodes was found. Trying again in 10 seconds.[/code]
That just keeps repeating in the console…I haven’t tried to include it to the Vera yet since this does not look like proper output.
Here’s the sketch from the MySensors library…just to verify it is correct:
[code]#include <Sleep_n0m1.h>
#include <SPI.h>
#include <EEPROM.h>
#include <RF24.h>
#include <Sensor.h>
#include <NewPing.h>
#define TRIGGER_PIN 6 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 5 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
unsigned long SLEEP_TIME = 5; // Sleep time between reads (in seconds)
Sensor gw;
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Sleep sleep;
int lastDist;
boolean metric = true;
void setup()
{
gw.begin();
// Register all sensors to gw (they will be created as child devices)
gw.sendSensorPresentation(0, S_DISTANCE);
metric = gw.isMetricSystem();
}
void loop()
{
gw.powerUp(); // Power up radio
int dist = metric?sonar.ping_cm():sonar.ping_in();
Serial.print(“Ping: “);
Serial.print(dist); // Convert ping time to distance in cm and print result (0 = outside set distance range)
Serial.println(metric?” cm”:" in");
if (dist != lastDist) {
gw.sendVariable(0, V_DISTANCE, dist);
lastDist = dist;
}
// Power down the radio. Note that the radio will get powered back up
// on the next write() call.
delay(1000); //delay to allow serial to fully print before sleep
gw.powerDown();
sleep.pwrDownMode(); //set sleep mode
sleep.sleepDelay(SLEEP_TIME * 1000); //sleep for: sleepTime
}[/code]
And here is a sketch that does work with the same Nano + Sensor:
[code]/*
- //////////////////////////////////////////////////
- //making sense of the Parallax PIR sensor’s output
- //////////////////////////////////////////////////
-
- Switches a LED according to the state of the sensors output pin.
- Determines the beginning and end of continuous motion sequences.
-
-
@author: Kristian Gohlke / krigoo () gmail () com / http://krx.at
-
@date: 3. September 2006
-
- kr1 (cleft) 2006
- released under a creative commons “Attribution-NonCommercial-ShareAlike 2.0” license
- Creative Commons — Namensnennung - Nicht-kommerziell - Weitergabe unter gleichen Bedingungen 2.0 Deutschland — CC BY-NC-SA 2.0 DE
-
-
- The Parallax PIR Sensor is an easy to use digital infrared motion sensor module.
- (http://www.parallax.com/detail.asp?product_id=555-28027)
-
- The sensor’s output pin goes to HIGH if motion is present.
- However, even if motion is present it goes to LOW from time to time,
- which might give the impression no motion is present.
- This program deals with this issue by ignoring LOW-phases shorter than a given time,
- assuming continuous motion is present during these phases.
-
*/
/////////////////////////////
//VARS
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
long unsigned int pause = 5000;
boolean lockLow = true;
boolean takeLowTime;
int pirPin = 3; //the digital pin connected to the PIR sensor’s output
int ledPin = 7;
/////////////////////////////
//SETUP
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);
}
////////////////////////////
//LOOP
void loop(){
if(digitalRead(pirPin) == HIGH){
digitalWrite(ledPin, LOW); //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 at ");
Serial.print(millis()/1000);
Serial.println(" sec");
delay(50);
}
takeLowTime = true;
}
if(digitalRead(pirPin) == LOW){
digitalWrite(ledPin, HIGH); //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 ended at "); //output
Serial.print((millis() - pause)/1000);
Serial.println(" sec");
delay(50);
}
}
}[/code]
Any ideas?