i attached my code and i cant make all sensors work at same time but individualy they works good
can anyone help me to resolve
// fire sensor
int sensorPin = A0; // select the input pin for the fire
int sensorValue = 10; // variable to store the value coming from the sensor
int led1 = 9; // Output pin for LED
// tilt sensor
const byte Button1 = A1;
const byte led2= 10;
byte ButtonState;
byte lastState = LOW;
byte count = 0;
// door sensor
const int Button2 = 2;
const int led3 = 13; // the number of the LED pin
int buttonState = 0;
// car sensor
const byte Button3 = A0;
const byte led4 = 11;
const byte led5 = 12;
byte ButtonState1;
byte lastState1 = LOW;
byte count1 = 0;
void setup() {
Serial.begin(9600);
// fire sensor
pinMode(led1, OUTPUT);
// tilt sensor
pinMode(led2, OUTPUT);
pinMode(Button1, INPUT);
// door sensor
pinMode(led3, OUTPUT);
pinMode(Button2, INPUT);
// car sensor
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(Button3, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
// fire sensor
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
if (sensorValue < 100){
Serial.println("Fire Detected");
Serial.println("LED1 on");
digitalWrite(led1,HIGH);
digitalWrite(led1, HIGH);
delay (1000);
digitalWrite(led1, LOW);
delay (1000);
digitalWrite(led1, HIGH);
delay (1000);
digitalWrite(led1, LOW);
delay (1000);
digitalWrite(led1, HIGH);
delay (1000);
digitalWrite(led1, LOW);
delay (1000);
digitalWrite(led1, HIGH);
delay (1000);
digitalWrite(led1, LOW); }}
// tilt sensor
{
ButtonState = digitalRead(Button1);
if(ButtonState && ButtonState != lastState){ // button latch, no debounce needed.
if(count < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count += 255; // same as count = count + 5;
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);
delay (1000);
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);
delay (1000);
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);
delay (1000);
digitalWrite(led2, HIGH);
delay (1000);
digitalWrite(led2, LOW);}
lastState = ButtonState;}
// door sensor
{
buttonState = digitalRead(Button2);
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
delay (1000);
digitalWrite(led3, HIGH);
delay (1000);
digitalWrite(led3, LOW);
delay (1000); } }
// car sensor
{
ButtonState1 = digitalRead(Button3);
if(ButtonState1 && ButtonState1 != lastState1) // button latch, no debounce needed.
{
if(count1 < 255) // This will check to see if the count is within a range of 0 - 255, and anything over that, it will reset count back to 0. Of course, this will happen anyways because count is a BYTE, and not an int or any other type.
count1 += 255; // same as count = count + 5;
else
count1 = 0;
Serial.print(".");
analogWrite(led4, count1);
delay(500);
analogWrite(led5, count1);
delay(500);
analogWrite(led5, LOW);
Serial.println(count1);}
lastState1 = ButtonState1;}
}
total.ino (3.51 KB)