hi
i’m new in both programming and arduino. I have uploaded this code to detect motion thru arduino. I need to store the outputs in excel using PLX-DAQ. But when i connect the code with PLX-DAQ, no output appear. currently, my arduino circuit contain pir sensor and real time clock device. can someone help me ?
#include
#include “RTClib.h”
#define DS32321_ADDRESS 0x68
byte zero = 0x00;
int ledPin = 13;
int inputPin = 2;
int pirState = LOW;
int val = 0;
long unsigned int pause = 5000;
RTC_DS3231 rtc;
char daysOfTheWeek[7][12] = {“Sunday”, “Monday”, “Tuesday”, “Wednesday”, “Thursday”, “Friday”, “Saturday”};
void setup(){
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
Serial.begin(9600);
#ifndef ESP8266
while (!Serial); // for Leonardo/Micro/Zero
#endif
delay(3000); // wait for console opening
if (! rtc.begin()) {
Serial.println(“Couldn’t find RTC”);
while (1);
}
if (rtc.lostPower()) {
Serial.println(“RTC lost power, lets set the time!”);
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop(){
val = digitalRead(inputPin); // read sensor value
if (val == HIGH) { // check if the sensor is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
delay(100); // delay 100 milliseconds
if (pirState == LOW) {
Serial.println(“Motion detected!”);
printDate();
pirState = HIGH; // update variable state to HIGH
}
}
else {
digitalWrite(ledPin, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
if (pirState == HIGH){
pirState = LOW; // update variable state to LOW
}
}
}
void printDate(){
DateTime now = rtc.now();
Serial.print(now.year(), DEC);
Serial.print(‘/’);
Serial.print(now.month(), DEC);
Serial.print(‘/’);
Serial.print(now.day(), DEC);
Serial.print(” (“);
Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
Serial.print(“) “);
Serial.print(now.hour(), DEC);
Serial.print(‘:’);
Serial.print(now.minute(), DEC);
Serial.print(‘:’);
Serial.print(now.second(), DEC);
Serial.println();
delay(3000);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.