controlling a light

Hi everyone, I am developing an android to switch on and off a lamp using of course an arduino. the connection between the android and the arduino is done by a Bluetooth module. I found this code I am not sure if is the best option, so if someone could give me some ideas, it would be much appreciated.
Code:
int led = 13; //attributing name to the pin 13

void setup()
{
Serial.begin(9600); // initialize serial connection
pinMode(led, OUTPUT); // declare the pin led as an OUTPUT
}

void loop()
{
char caracter = Serial.read(); // variable that is responsible for reading the information received from the Bluetooth

if(caracter == 'a' )
{
digitalWrite(led, HIGH); // if the value of the variable equals a the led will be turn on
}
if(caracter == 'b' )
{
digitalWrite(led, LOW); // if the value of the variable equals b the led will be turn off
}
}

Please help me guys!!!!

If you build and upload that code and then open the monitor, type a or b in lower case and press send the built in LED should go on and off.

Of course if you want to use bluetooth you will need extra hardware and software.

Mark

I have a Bluetooth module and have design an app, to switch on and off the light.
i am also using a power relay but I am having problems with the power relay because as soon as I turn on the arduino the relay goes on, and should be off until I use the app. do not why this is happening,

Code tags, please.

Read this before posting a programming question

You should test for Serial.available before reading from Serial.

Hi... i am trying to control a light (ON/OFF) by using an android app and android. the communication is done by using a Bluetooth module. the code for the arduino that I am using is this:
int led = 13; //attributing name to the pin 13

void setup()
{
Serial.begin(9600); // initialize serial connection
pinMode(led, OUTPUT); // declare the pin led as an OUTPUT
}

void loop()
{
char caracter = Serial.read(); // variable that is responsible for reading the information received from the Bluetooth

if(caracter == 'a' )
{
digitalWrite(led, HIGH); // if the value of the variable equals a the led will be turn on
}
if(caracter == 'b' )
{
digitalWrite(led, LOW); // if the value of the variable equals b the led will be turn off
}
}

When I open the serial monitor I am able to control the light. the light should come off but it is one. but when I connect the Bluetooth module I am not able to control the light anymore. Does anyone knows why?
this is my first project, so i am new with arduino

Please do not cross-post. This wastes time and resources as people attempt to answer your question on multiple threads.

Threads merged.

"controlling a light" and "light control" are hardly different topics.

I notice you have chosen to ignore my request to use code tags.

Did you read this?

Read this before posting a programming question

How to use this forum

  • Moderator

but when I connect the Bluetooth module

Ebay lists about 140 bazillion bluetooth modules, even when you search for "the bluetooth module".

Of course, even if you could be bothered to tell us which bluetooth module you were talking about, you've said nothing about how it is connected to the Arduino.

Absent any useful information, all we can offer is sympathy.

this is the module that i am using: http://www.ebay.co.uk/itm/1pcs-Arduino-Wireless-Serial-4Pin-Bluetooth-RF-Transceiver-Module-Assemblies-Hot-/181205119968?pt=UK_BOI_Electrical_Components_Supplies_ET&hash=item2a30aab3e0

THE 5 V of the arduino are connected to the breadboard
one of the GND are connected to the GND on the power Relay
the Second GND are connected to the breadboard
the VCC of the bluethoot is connected to the breadboard so does the GNF
the TXD of the Bluetooth is connected to the rx of the arduino
the rxd of the bluethoot is connected to tx of the arduino

I dont know what else to say

hello everyone...im a new person for arduino..can someone tell me about the theory for my final year project..i am going to switch on the lamp at my living room using android-based smart phone to switchthe lamp..

i proposed to use arduino uno and ethernet shield

Hi, yagos7,

Can you please post a copy of your sketch, using code tags?
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png or pdf?

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Tom.... :slight_smile: