four PIR senor with Four Servo motor.
the each sensor will count the motion like 1 and 3 will be count and sum and then compare to the 2 and 4 counted data .
if the 1 and 3 have high counter then 2 and 4 so the servo 1 and 3 will be open in 90 degree and the 2 and 4 will be stay on 0 degree and then the 2 and 4 will be open same as .
like 4 way traffic line the opposite side opens same here...
need the code for this ... i have a lot of confusion.... thanks
You won't find the complete code here for your project.
So my suggestion is to start learning Arduino. Divide your project in parts i.e. for your project, you should first learn How to interface PIR sensor HC-SR501 with Arduino. Make a search for Serial Terminal in Arduino, which is used for debugging purposes.
Once you are done with PIR, then make a search for How to interface Servo Motor with Arduino. You will find all the codes on google and helping videos so its not a big deal.
Once you are done with that, post here and we will move forward.
hi I'm working on a small project ..
i have big confusion on code
i wanna make a small mini intelligence system for traffic .
we have 4 way traffic .
each way have a pir sensor and a servo motor . all the pir sensor will count the car passed through the way and will take decision on high count so the road will be open like 1 and 3 or 2 and 4 .. same as the opposite side will both open.
the pir sensors are set on 100m far from each gate(servo) .
this is i write for one side way i need to make a code for all 4 side ....thanks
// Include the Servo library
#include <Servo.h>
// Declare the Servo pin
int pir1 = 2;
int pir2 = 3;
int pir3 = 4;
int pir4 = 5;
int servoA = 6;
int servoB = 7;
int servoC = 8;
int servoD = 9;
int pirState = LOW; // we start, assuming no motion detected
int val = 0;
int counter=0;
int currentState=0;
int previousState=0;
Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
void setup() {
// put your setup code here, to run once:
pinMode(servoA, OUTPUT);
pinMode(servoB, OUTPUT);
pinMode(servoC, OUTPUT);
pinMode(servoD, OUTPUT);
// We need to attach the servo to the used pin number
Servo1.attach(servoA);
Servo2.attach(servoB);
Servo3.attach(servoC);
Servo4.attach(servoD);
Serial.println("counter");
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
val = digitalRead(pir1);
if(val == HIGH){
digitalWrite(servoA, HIGH);
Servo1.write(90);
}
if(pirState == LOW){
currentState =1;
pirState=HIGH;
delay(500);
}
else {
digitalWrite(servoA, LOW);
}
if(pirState == HIGH){
currentState = 0;
pirState = LOW;
}
if(currentState != previousState){
if(currentState == 1){
counter = counter +1;
Serial.println("counter");
delay(200);
}
}
}
what's the pirState
variable supposed to be ?
Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code]
.
It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)
digitalWrite(servoA, HIGH);
What is this supposed to do? That's not how you control servos.
Steve
hi i'm new here..
how i could count the detection of 4 PIR sensor and to open the servo motor on on each way of PIR senor.
like 4 way traffic road and each road have PIR sensor and servo motors gate
all will count the detection and like 1 and 3 will sum the count and then compare to 2 and 4 if high then at will open the gate of 1 and 3. and the other will remain closed till the time 1 minute then the other side will open
in new cycle again will check and then open the high count... thanks
To count activations of the PIR sensors, see File->Examples->02.Digital->StateChangeDetection. Each time through loop(), get the current state of each PIR input pin. Compare the new state to the old state. If the new state is "sensing something" and the old state is "not sensing something" then increment the counter for that PIR sensor. Set the old state to the new state.
For timing, set an unsigned long variable to millis() when you want to start a timer. Use (millis()-variable >= timeLimit) when you want to know if the timeLimit has expired.
For comparison, use an 'if' statement: if - Arduino Reference
hi.
i'm try to use 4 pir sensor in one time and also wana get the reading of the sensors all time ...
like i have 4 pir sensor and i want that the each sensor is send the data always..
.. i have try but i can't get the same out put as i wish..
thanks ...
Please post your code
i wanna get the reading of all pir sensor as the get detection ...
but i only get one side of detection..
how i would make the all pir sensor active and to read the detection from all the sensor on one time if there is detection...
below is code of .
dht11 sensor
mq2 smoke sensor.
LDR sensor
servo motor and pir
.
if there is any detection on pir sensor so the servo will move..
like if on 1 and 3 have detection and the same time the 2 and 4 also have detection..
i wanna take the detection from the alll four sensor on a time as they get detection...
//Libraries
#include <dht.h>
#define MQ2 (15)
#include <Servo.h>
#define ldr 24 //lDR +LED
#define led 25 //lDR +LED
#define ledA1 2 //LED A
#define ledA2 3 //LED A
#define ledA3 4 //LED A
#define ledB1 5 //LED B
#define ledB2 6 //LED B
#define ledB3 7 //LED B
#define ledC1 8
#define ledC2 9
#define ledC3 10
#define ledD1 12
#define ledD2 11
#define ledD3 13
// Declare the Servo pin
int servoA = 28;
int servoB = 29;
int servoC = 30;
int servoD = 31;
dht DHT;
//Constants
#define dht 27 // DHT 22 (AM2302) - what pin we're connected to
// Create a servo object
Servo Servo1;
Servo Servo2;
Servo Servo3;
Servo Servo4;
//Variables
float hum; //Stores humidity value
float temp; //Stores temperature value
float sensorValue; //Gas Sensor variable to store sensor value
void setup() {
// put your setup code here, to run once:
pinMode(dht, INPUT);
pinMode(MQ2, INPUT);
pinMode(ldr, INPUT);
pinMode(led, OUTPUT);
pinMode(ledA1, OUTPUT);
pinMode(ledA2, OUTPUT);
pinMode(ledA3, OUTPUT);
pinMode(ledB1, OUTPUT);
pinMode(ledB2, OUTPUT);
pinMode(ledB3, OUTPUT);
pinMode(ledC1, OUTPUT);
pinMode(ledC2, OUTPUT);
pinMode(ledC3, OUTPUT);
pinMode(ledD1, OUTPUT);
pinMode(ledD2, OUTPUT);
pinMode(ledD3, OUTPUT);
pinMode(servoA, OUTPUT);
pinMode(servoB, OUTPUT);
pinMode(servoC, OUTPUT);
pinMode(servoD, OUTPUT);
// We need to attach the servo to the used pin number
Servo1.attach(servoA);
Servo2.attach(servoB);
Servo3.attach(servoC);
Servo4.attach(servoD);
Serial.println("Gas sensor warming up!");
Serial.begin(9600);
}
void loop() // put your main code here, to run repeatedly:
{
//roadAopen();
//roadCopen();
//void servo13();
//roadBopen();
//roadDopen();
//void servo24();
dht11();
mq2();
LDR();
delay(1000);
}
void dht11() // humidity and temprature sensor
{
int chk = DHT.read11(dht);
//Read data and store it to variables hum and temp
hum = DHT.humidity;
temp= DHT.temperature;
//Print temp and humidity values to serial monitor
Serial.print("Humidity: ");
Serial.print(hum);
Serial.print(" %, Temp: ");
Serial.print(temp);
Serial.println(" Celsius");
delay(100); //Delay 2 sec.
}
void mq2() //MQ2 Gas Sensor Function
{
sensorValue = analogRead(MQ2); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.print(sensorValue);
if(sensorValue < 400)
{
Serial.print(" |NO Smoke detected!");
}
if((sensorValue > 400)&&(sensorValue < 800))
{
Serial.print(" | Smoke detected!");
}
if(sensorValue > 800)
{
Serial.print(" |Alert High Smoke detected!");
}
Serial.println("");
delay(100); // wait 2s for next reading
}
void LDR() //Function of LDR sensor to a temporary variable
{
int temp=digitalRead(24); //assign value of LDR sensor to a temporary variable
Serial.println("Intensity="); //print on serial monitor using ""
Serial.println(temp); //display output on serial monitor
delay(100);
if(temp==HIGH) //HIGH means,light got blocked
digitalWrite(25,HIGH); //if light is not present,LED on
else
digitalWrite(25,LOW); //if light is present,LED off
}
void roadAopen()
{
digitalWrite(ledA3, LOW);
digitalWrite(ledA1, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(1000);
digitalWrite(ledA1, LOW);
digitalWrite(ledA2, HIGH);
delay(1000);
digitalWrite(ledA2, LOW);
}
void roadBopen()
{
digitalWrite(ledB3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB1, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD3, HIGH);
delay(1000);
digitalWrite(ledB1, LOW);
digitalWrite(ledB2, HIGH);
delay(1000);
digitalWrite(ledB2, LOW);
}
void roadCopen()
{
digitalWrite(ledC3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC1, HIGH);
digitalWrite(ledD3, HIGH);
delay(1000);
digitalWrite(ledC1, LOW);
digitalWrite(ledC2, HIGH);
delay(1000);
digitalWrite(ledC2, LOW);
}
void roadDopen()
{
digitalWrite(ledD3, LOW);
digitalWrite(ledA3, HIGH);
digitalWrite(ledB3, HIGH);
digitalWrite(ledC3, HIGH);
digitalWrite(ledD1, HIGH);
delay(1000);
digitalWrite(ledD1, LOW);
digitalWrite(ledD2, HIGH);
delay(1000);
digitalWrite(ledD2, LOW);
}
void servo13(){
Serial.println("Motion detected! on 1 or 3");
// Make servo go to 0 degrees
Servo1.write(0);
Servo3.write(0);
delay(2000);
// Make servo go to 90 degrees
Servo1.write(90);
Servo3.write(90);
delay(200);
}
void servo24(){
Serial.println("Motion detected! on 2 or 4");
// Make servo go to 0 degrees
Servo2.write(0);
Servo4.write(0);
delay(2000);
// Make servo go to 90 degrees
Servo2.write(90);
Servo3.write(90);
delay(200);
}
thanks....
Maybe you should start by actually reading the PIR sensor's output in the code, as you don't appear to do this. I don't see any reference to actually reading a PIR sensor in that sketch.
There are two functions, servo13() and servo24() which are never called; print statements in those functions suggest they will be called when a PIR sensor is triggered, but they're never called in that code.
Five crossposts spanning the last 1.5 months merged. Over and over again people have tried to help you, but instead of responding, you just go and post the same thing over again.
Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.
Repeated cross posting will result in a suspension from the forum.
In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
pert:
Five crossposts spanning the last 1.5 months merged. Over and over again people have tried to help you, but instead of responding, you just go and post the same thing over again.Cross posting is against the rules of the forum. The reason is that duplicate posts can waste the time of the people trying to help. Someone might spend 15 minutes writing a detailed answer on this thread, without knowing that someone else already did the same in the other thread.
Repeated cross posting will result in a suspension from the forum.
In the future, please take some time to pick the forum section that best suits the topic of your question and then only post once to that forum section. This is basic forum etiquette, as explained in the sticky "How to use this forum - please read." post you will find at the top of every forum section. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
okay dear sorry i'm new here and didn't have more info about this at all...
thanks for your advice..
Asad_Ullah019:
okay dear sorry i'm new here and didn't have more info about this at all...
Come on.. Being new is a poor excuse for basic respect of people you are expecting help from...
And you have those two links at the top of the forum... The Titles are pretty self explanatory
suggest you read them twice...