Hi, my name is Daniel,
I have a problem trying to turn off the led when i turn it on with my mobile.
This is what im doing:
Turning on the led with my mobile, but when i try to turn it off with a PIR sensor the led just low the intensity and come back again the intesity.
This is what i am using:
char val;
int led = 8;
int sensor = 7;
int calibrationTime = 30;
void setup() {
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
delay(1000);
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
delay(50);
pinMode(led,OUTPUT);
pinMode(sensor,INPUT);
Serial.begin(9600);
}
void loop() {
if(Serial.available())
val = Serial.read();
if(val == '1')
{
digitalWrite(led,HIGH);
}
if (digitalRead(sensor))
digitalWrite(led,LOW);
}
A good suggestion someone gave me before was to use print statements while debugging. You know what you're expecting your variables to be doing, print statements can show you what your program is actually doing. That being said, I'm definitely not an expert and there are definitely smarter people than me on here. I would try changing your if statement to an if else statement and add a delay at the end.
Thank you, i tried that too and the result is the same.
I am using App inventor to control the arduino with a usb module.
do you have another suggestions? that would be very helpful, thank you very much.
Or can you send me a corrected sketch of my "program" with what you are saying? please
Aarduino ONE
PIR sensor
HC 06 bluetooth Module
LED
i am using app inventor to communicate with arduino
LAST NIGHT I DID IT! BUT BELIEVE IT OR NOT I ACCIDENTLY ERASED IT
BUT THE ONLY THING THAT I DID WAS TO ENTER THE COMMAND SERIAL.END() TO THE SKETCH,
i am trying to remember where did i put it correctly, but i cant repeat it, i couldnt sleep.
OH!! Theres a lot of things i dont understand,
IT WORKS, the led completely turn off, but turns back on a few seconds later
i dont want that the led turns back on
Im starting to think that is something about the sensor PIR?
Sorry for the drawing, i made it quickly
im trying to en the loop but i cant, when i do that, i cant turn the led with my phone.
Hope you can keep helping,