Bitten off more than I can chew..?

Hi guys,

I've been working on a project recently and it's due in 2 weeks time. I'm wondering if it is possible to pay someone or possible software to help write the code. I've checked with my lecturers if this is OK and it's fine as the project marked on it's physical appearance and functionality.

Basically, I have a motor.. The arduino has a PIR sensor, a temperature sensor and a microphone as the inputs. I want these to activate the motor through a relay which I will connect a few other outputs to. I know exactly what I want but I can't for the life of me write the code. It's too complex as I want it to register an input and then wait for 10 seconds, if another input is registered within that time, it gives an output to the relay.

I've got 3 sketches already (PIR, temp sensor and mic) that I found online and I've had them all working. I've been trying to put them all into one but to no avail.

Having a nightmare. Would appreciate any help.

Thank you.

Ask the moderator to move this to: "Gigs and Collaborations".

Don't forget to throw in your existing attempt at coding - so we can evaluate your level of 'awareness' of the tools needed.

#include <dht.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println("DHT11 Humidity & temperature Sensor\n\n");
delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print("Current humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop()

int ledPin = 13; // choose the pin for the LED
int inputPin = 2; // choose the input pin (for PIR sensor)
int pirState = LOW; // we start, assuming no motion detected
int val = 0; // variable for reading the pin status

void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare sensor as input

Serial.begin(9600);
}

void loop(){
val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, HIGH); // turn LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion detected!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}

int ledPin=13;
int sensorPin=7;
boolean val =0;

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(sensorPin, INPUT);
Serial.begin (9600);
}

void loop (){
val =digitalRead(sensorPin);
Serial.println (val);
// when the sensor detects a signal above the threshold value, LED flashes
if (val==HIGH) {
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
}

That's all 3 sketches together. I'm utterly clueless, hence my need for some help off someone, even if I have to pay.

Thank you.

Loz2212:
I've checked with my lecturers if this is OK and it's fine as the project marked on it's physical appearance and functionality.

And you expect us to believe that? It looks pretty clear that you weren't paying attention when it came to merging programmes, and now you want to pay someone to do your homework. You will get help, and there are plenty of examples of merging around here, but your approach is pretty suss.

I'm not here to justify my point and make you believe me Nick. No matter what I say, it won't matter to you. I've not come on here claiming to know what I'm doing. I've chosen this project off my own bat and as the title says.. Clearly bitten off more than I can chew. You can either be a great help and offer me assistance or continue trying to educate me in the error of my ways. You won't get much response with the latter.

The 3 sketches were just the 3 sketches copy and pasted. That wasn't my attempt. Just a few pointers would be nice.

Did you ask the moderator to move this thread?

I have done yeah :slight_smile:

Thread moved as requested.

So, you want the output pin to go HIGH when there is ANY input? There will ALWAYS be input from the temperature and humidity sensor, so you can skip reading them.

const byte relayPin = 2; // Change to whatever pin the relay is connected to

void setup()
{
   pinMode(relayPin, OUTPUT);

   digitalWrite(relayPin, LOW); // Change to HIGH is LOW doesn't activate the relay
}

void loop()
{
   // Nothing to do here, since there would ALWAYS be input, so the relay would always be on
}

That code meets your stated requirements. You owe me a beer.

I want it to register an input A and then wait for 10 seconds, if another input B is registered within that time, it gives an output to the relay.

How long is the relay to be closed?

anyway:

long mostRecentInputA = millis() - 10000; 

void loop() {
  if(there's an input A) {
    mostRecentInputA = millis();  
  }

  if(theres an input B) {
    if(millis() - mostRecentInputA <= 10000) {
      send output to relay;
    }
  }
}