Go Down

Topic: Turning on a light bulb with Arduino and XBee (Read 2494 times) previous topic - next topic


I am building a small circuit for turning on a lightbulb with my computer. Besides this the light bulb can be turn on manually by a switch.
For building this, I am using a switch bai ben (Interruptions from two points.) for doing this.

The problems is the following.
The application is working fine, when I send the sign for turning on the lightbulb turnos on, and when I send the sign for turning of, it goes of. But if I manually turn on the switch, and send the sign of turning of from the application, it doesn't work.

This is my arduino code. I have a transformer (converts 110V to 5V) connected to the PIN 12. This way I know when the lightbulb is ON or OFF.

Code: [Select]

int LED = 11;               
int debugLED = 13;           
int packet;                 
int analogValue;
int PIN=12;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(PIN, OUTPUT);
  pinMode(debugLED, OUTPUT);


void loop() {
if(Serial.available() >= 16){       
   if(Serial.read() == 0x7E){         //Look for starting byte
     digitalWrite(debugLED, HIGH);   
     digitalWrite(debugLED, LOW);
     for(int i = 0; i <15; i++){     
       byte discard = Serial.read();
     packet = Serial.read();         

if(packet == 0x01){                  //If a '1' is pressed on keyboard side
     digitalWrite(LED, HIGH);              //turn on red LED
     Serial.println("Recibi 1 voy a encender");
     digitalWrite(debugLED, LOW);
else if(packet == 0x00){            //If a '0' was pressed on keyboard side
     digitalWrite(LED, LOW);      //turn off red LED
     Serial.println("Recibi 0 voy apagar");
     digitalWrite(debugLED, HIGH);
else{   //Little debug flashing incase something other than
   Serial.println("Recibi otra cosa: "+packet);
   for(int i = 0; i < 10; i++)           //'1' or '0' is rx'd.
     digitalWrite(LED, HIGH);
     digitalWrite(LED, LOW);

Any idea of this problem?


Hola, me paso porque me intereso... Me gustaria saber si sirve la arduino para conectar cosas de 220v o 110v


Go Up