hi,
i want to make android as most priority who can control my lamp...
i have 2 controller android and sensor..
so i make muy program like this
#define echoPin 9 // Echo Pin
#define trigPin 10 // Trigger Pin
int LDR = 0; //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRValue = 0; //that’s a variable to store LDR values
int light_sensitivity = 40; //This is the approx value of light surrounding your LDR
int maximumRange = 300; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
int ledPins[] = {3,4};
int lamp = 5;
int x = 0;
int j = 0;
int i = 0;
void setup() {
Serial.begin (115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
if (Serial.available()){
char input = Serial.read();
switch (input){
case '6':
i =0;
break;
case '7':
i =1;
break;
pinMode(ledPins*,OUTPUT);}*
-
pinMode(lamp,OUTPUT);*
}}
void loop() { -
if (Serial.available()){*
-
char input = Serial.read();*
-
switch (input){*
-
case '6':*
-
i =0;*
_ digitalWrite (ledPins*, LOW);_
_ delay(500);_
_ break;_
_ case '7':_
_ i =1;_
_ digitalWrite (ledPins, HIGH);
delay(500);
break;
case '8':
digitalWrite (lamp, LOW);
delay(500);
break;
case '9':
digitalWrite (lamp, HIGH);
delay(500);
break; *_
* }}*
* ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*
* LDRValue = analogRead(LDR); //reads the ldr’s value through LDR which we have set to Analog input 0 “A0?*
* delay(50); //This is the speed by which LDR sends value to arduino*
* if (LDRValue < light_sensitivity)
_ {
digitalWrite(lamp, HIGH);
}
else*
* {
digitalWrite(lamp, LOW);
}*_
* ////////////////////////////////////////////////////////////*
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
///////////////////////////////////////////////////////////////////////////////////////////
if (distance >= 80 || distance <= 1){
/* Send a negative number to computer and Turn LED ON
to indicate "out of range" */
Serial.println("----");
j++;
if (j >2 ){
* i = 0;*
digitalWrite (ledPins*, LOW);*
j = 0;
}
}
else if (distance >= 1 && distance <= 80){
/* Send the distance to the computer using Serial protocol, and
turn LED OFF to indicate successful reading. */
x=1;
j = 0;
* i = 0;*
Serial.print(distance);
Serial.print(" || ");
Serial.println(LDRValue); //prints the LDR values to serial monitor
* Serial.print(" || ");*
*Serial.println(i); *
digitalWrite (ledPins*, HIGH);*
}
//Delay 50ms before next reading.
delay(500);
}
but it doesn't work..