XBee tutorial: Turning on an LED wirelessly using Arduino via XBee radios

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024

ความคิดเห็น • 58

  • @mosleyau
    @mosleyau 5 ปีที่แล้ว +1

    Thank you! Im No longer scared of Xbee

    • @mosleyau
      @mosleyau 5 ปีที่แล้ว

      Do u recommend having a 1k resisitor between rx and tx pins instead of direct connection like you show?

    • @mujtech4887
      @mujtech4887  5 ปีที่แล้ว

      Austin Mosley if you’re using a shield then you don’t need a resistor otherwise yes

  • @user-xb9vu9pg3h
    @user-xb9vu9pg3h 8 หลายเดือนก่อน

    Coordinator (Transmitter) Code:
    #include
    #include
    // constants won't change. They're used here to set pin numbers:
    const int buttonPin = 7; // the number of the pushbutton pin
    const int ledPin = 13; // the number of the LED pin
    // Variables will change:
    int ledState = HIGH; // the current state of the output pin
    int buttonState; // the current reading from the input pin
    int lastButtonState = LOW; // the previous reading from the input pin
    // the following variables are unsigned longs because the time, measured in
    // milliseconds, will quickly become a bigger number than can be stored in an int.
    unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
    unsigned long debounceDelay = 50; // the debounce time; increase if the output flickers
    SoftwareSerial Xbee(2, 3); // RX, TX
    //----------------------------------------------------
    void setup()
    {
    pinMode(buttonPin, INPUT);
    pinMode(ledPin, OUTPUT);
    Serial.begin(9600);
    Xbee.begin (9600);
    // set initial LED state
    digitalWrite(ledPin, ledState);
    }
    //----------------------------------------------------
    void loop()
    {
    // read the state of the switch into a local variable:
    int reading = digitalRead(buttonPin);
    // check to see if you just pressed the button
    // (i.e. the input went from LOW to HIGH), and you've waited long enough
    // since the last press to ignore any noise:
    // If the switch changed, due to noise or pressing:
    if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
    }
    if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:
    // if the button state has changed:
    if (reading != buttonState) {
    buttonState = reading;
    // only toggle the LED if the new button state is HIGH
    if (buttonState == HIGH) {
    ledState = !ledState;
    }
    }
    }
    // set the LED:
    digitalWrite(ledPin, ledState);
    Xbee.write(ledState);
    Serial.println(ledState);
    // save the reading. Next time through the loop, it'll be the lastButtonState:
    lastButtonState = reading;
    }
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    End Device (Receiver) code:
    #include
    #include
    SoftwareSerial Xbee(2, 3);
    int data = 0;
    //----------------------------------------------------
    void setup()
    {
    Serial.begin(9600);
    Xbee.begin(9600);
    pinMode(7, OUTPUT);
    }
    //----------------------------------------------------
    void loop()
    {
    while(Xbee.available())
    {
    data=Xbee.read();
    Serial.print(data);
    }
    if(data==0)
    {
    digitalWrite(7, LOW);
    }
    if(data==1)
    {
    digitalWrite(7, HIGH);
    }
    }

  • @patrolman53
    @patrolman53 3 ปีที่แล้ว

    For those who have a shield with an XBEE/USB switch, mine only worked on the USB setting. Took like 6 hours to figure that out

  • @sendoutalerts4537
    @sendoutalerts4537 6 ปีที่แล้ว +1

    nice job! very understandable and i liked the step by step setup and visible code - maybe make your code downloadable? i hope you do some more! thx

  • @USMan21
    @USMan21 ปีที่แล้ว

    Thank you!

  • @mohammadatieh2156
    @mohammadatieh2156 2 ปีที่แล้ว

    Why you did a software serial. Why you didn’t connect them directly to pins tx rx (0,1)

  • @mitkosokolov9382
    @mitkosokolov9382 5 ปีที่แล้ว +1

    Hi. I'm trying to run this kid - digi xk-z11-t-w. But i receive the next error. I work with digi esp for python, and i'm trying to use digi tank solution simulation.
    Any help?

    XTankSensor: DoCommandRequestForMiscSensorInformation -> START!
    XTankSensor: DoCommandRequestForMiscSensorInformation -> REQUEST SENT!
    XTankSensor: scheduling a state machine callback of 20 seconds and a backup callback of 30 seconds.

  • @scottturner1900
    @scottturner1900 6 ปีที่แล้ว +1

    What is the schematic of the switch? I have hooked it up and programed it exactly like you say but I can not get it to work. Is the 5v and the resistor common and the terminal connected to pin7 make the connection? I think I have my pushbutton set up wrong....Please Help!

  • @elliot1784
    @elliot1784 4 ปีที่แล้ว

    what really changes if I use 2 xbee series2, an Arduino UNO, and a NANO?.. its all I have. thank you so much! Great video. Also its 3 years later so what changes since then?.. if you know. thank you !

  • @rachimaduranga2770
    @rachimaduranga2770 2 ปีที่แล้ว

    Can you do a demo for ultrasonic sensor data transmission using XBEE+Arduino

  • @crpaiva_
    @crpaiva_ 2 ปีที่แล้ว

    Great Man. Congrats for you. Please, Your code when finish the Power Up of the Arduino the X-BEE alrealdy to start to transmit without any command over the pushbutton....Someone here Can help me?

  • @marcienbalouboula2945
    @marcienbalouboula2945 2 ปีที่แล้ว

    Thank you for your helpful video !
    I wanna know how I can send two data in the same time. I’m actually working with Dht22. And I want to send temperature and humidity using 2 xbee s2c pro and two Arduino ! Thank you

  • @diptiprakashpalai
    @diptiprakashpalai 2 ปีที่แล้ว

    Can a Zigbee sensor data be read in XBee module? I have Zigbee PIR Sensor of different make. I want to read its data on my Raspberry Pi. I have an Xbee module with its USB Dongle. Please guide.

  • @AngSu
    @AngSu 6 ปีที่แล้ว

    Hello i'm doing a project with Xbee and i don't know where to start. Basically what i want to do is a wireless object counter.The Xbee must be able send the number of object to the computer wirelessly (with the aid of arduino and ultrasonic sensor) whenever an object passes near the sensor. Any advice on how to do this please? Thank you.

    • @TheShadesOfBlack
      @TheShadesOfBlack 5 ปีที่แล้ว

      Probably a bit late on this but XBee is a radio transmitter. I don't think most computers have radio capabilities. So I suppose you could connect an XBee to your PC. Doesn't Arduino have Bluetooth? If not I'm sure there's a shield for that. I feel like that might work. But who knows.
      I'm curious what you ended up doing though.

  • @Time4yes
    @Time4yes 2 ปีที่แล้ว

    What is the range of these radio communication components?

  • @vigneshpr.5814
    @vigneshpr.5814 5 ปีที่แล้ว

    Hey I have a doubt ...I have configured both the radios to be end user, actr the transmitter is supposed to be coordinator and the receive is supposed to be the end-user right ??

  • @marksncubejr1755
    @marksncubejr1755 5 ปีที่แล้ว

    Hi, im trying to do this but I have xbee series 2, do I have to configure it differently? When I was configuring them, there was no MY section

  • @mathsolvertech6711
    @mathsolvertech6711 2 ปีที่แล้ว

    How long( in meters) they can communicate?

  • @mujtech4887
    @mujtech4887  4 ปีที่แล้ว

    UPDATE: New video posted (Wireless and Hands-free Prototype Light Switch)
    It uses the same XBee radios shown in this video
    Link: th-cam.com/video/A8MTWsSVoEQ/w-d-xo.html

  • @sithlord6613
    @sithlord6613 6 ปีที่แล้ว

    Like your videos great work and now my question is I have xbee mod sheild and one xbee Bluetooth wireless module so my question is would it still work or I need to get the same cuz talking to the people at this electronic store they said it will because they the same xbee but the other xbee said xbee Bluetooth module and the other day xbee sheild module

  • @graceb2404
    @graceb2404 6 ปีที่แล้ว

    Unfortunately Adapter is no longer for purchase

  • @madihael-nagar2829
    @madihael-nagar2829 7 ปีที่แล้ว

    hello...your work is very interesting
    Well I did everything on your tutorial.... but unfortunately it is not working with me
    I did all the checks....both Xbees are communicating with each other...the codes are same as yours....I just don't know what is the problem
    Any Advice??
    Thanx in advance

  • @luxisbritish1386
    @luxisbritish1386 5 ปีที่แล้ว

    how to order a robot with 4 button pussoire transmitter (arduino1) / receiver (arduino2) with this principle of Xbee as on the example of led please answer me ?????

    • @mujtech4887
      @mujtech4887  5 ปีที่แล้ว

      yougourthene brinis You can use the same principle shown in this video but instead of having the receiver XBee controlling an LED have it control a motor driver

  • @KTAB-xt6vz
    @KTAB-xt6vz 6 ปีที่แล้ว +2

    i need links for arduino programming

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      I posted the code in the comments

  • @fredjr26
    @fredjr26 5 ปีที่แล้ว

    Hey can you send me the link to the project? THANKS

  • @scottturner1900
    @scottturner1900 6 ปีที่แล้ว

    This is perfect for my application! Great job! Can you please post the Arduino code in the coments or provide a link to the code please? Thank you so much!

  • @michaelnathaniel2385
    @michaelnathaniel2385 4 ปีที่แล้ว

    why is the TX and RX goes to pin 2 and 3 in the arduino? the RX and TX text in arduino is on pin 0 and 1. i really new to xbee, pls help me
    Thank you in advance

    • @michaelnathaniel2385
      @michaelnathaniel2385 4 ปีที่แล้ว

      im using xbee shield v03. so what pin shall i use on the SoftwareSerial Xbee(?,?); ?

    • @mujtech4887
      @mujtech4887  4 ปีที่แล้ว

      Michael Nathaniel Hi Michael. At that time, I encountered some issues when I used the hardware serial ports of the arduino (pins 0 and 1) with the XBEE shield. Hence I used the “softwareserial” library to configure pins 2 and 3 to act as TX and RX so that I can receive serial data from the XBee radios. With the softwareserial library, you can configure any digital pin on the arduino to function as TX and RX, similarly to pins 0 and 1 and in this case I used pins 2 and 3.

    • @michaelnathaniel2385
      @michaelnathaniel2385 4 ปีที่แล้ว

      @@mujtech4887 Thank you for replying.
      i use pin 0 and 1 for the RX and TX, and i think it works. But something is wrong when i receive the data i send. when i print the received data, i got a bunch of number and i don't know what it is. here is my code for send data.
      #include
      #include
      #include
      SoftwareSerial XBee(0,1);
      String data;
      void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      XBee.begin(9600);
      data = "test send data";
      }
      void loop() {
      delay(3000);
      // put your main code here, to run repeatedly:
      static char *dataSend = data.c_str();
      // need to use c_str() because the write function don't accept String
      XBee.write(dataSend);
      }
      and her is the receive code
      #include
      #include
      #include
      SoftwareSerial XBee(0,1);
      String data;
      void setup() {
      // put your setup code here, to run once:
      Serial.begin(9600);
      XBee.begin(9600);
      }
      void loop() {
      delay(3000);
      // put your main code here, to run repeatedly:
      while(XBee.available())
      {
      data = XBee.read();
      Serial.print(data);
      // Serial.print((char)data);
      Serial.print(" ");
      }
      Serial.println();
      Serial.println("====================");
      }
      can you help me?
      in your tutorial, you just send a number(1 or 0). can you tell me how to send a String? or there is another way? i need to send some datas from sensors.

    • @mujtech4887
      @mujtech4887  4 ปีที่แล้ว

      Michael Nathaniel I still haven’t tried to send string data via arduino. From what you’re telling me, the numbers that you are receiving are the ASCI codes of the characters that are sent from the transmitter and it’s showing like that because you’re printing them at the receiver using “serial.print”. Perhaps if you change it to “serial.write” it might work?

  • @niconiconi4105
    @niconiconi4105 2 ปีที่แล้ว

    why my xctu cannot discover my xbee S2C module

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      Have you tried using the XCTU software to "Recover" your Xbee? It resets all the settings back to default and will bring your Xbee back to life :)

  • @hanifassyarify8639
    @hanifassyarify8639 6 ปีที่แล้ว

    I have a question, why you use pin 2 and 3 in arduino for RX, TX from xbee?
    it is possible if I use pin RX, TX in arduino directly to connect TX,RX from xbee?

    • @mujtech4887
      @mujtech4887  6 ปีที่แล้ว

      Pins 0 and 1 are hardware serial ports that can only transmit and receive to one device at a time. Since we are using the serial commands in this code, we are communicating the Arduino with the computer via these pins so we can't also use them to communicate it with the XBee radios. Hence, the digital pins are used.
      In the Arduino Mega however, you are given 3 hardware serial ports to choose from so you can use two ports at the same time without the need of using the digital pins like I did in this video.

    • @hanifassyarify8639
      @hanifassyarify8639 6 ปีที่แล้ว

      mujTech ooh ok, I got it! Thankyou dude👍

    • @hanifassyarify8639
      @hanifassyarify8639 6 ปีที่แล้ว

      ooh sir, i have another question. i wonder if i want to controll the LED intensity with potensiometer, can you explain it?
      i've tried but still failed. thanks

  • @feliwein_cc
    @feliwein_cc 4 ปีที่แล้ว

    which xbee library did u use?

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      Xbee.h (Arduino library)

  • @chanduvali645
    @chanduvali645 5 ปีที่แล้ว

    Can I have the Code link please......

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      Check the comments, I posted the code

  • @kryptocat4240
    @kryptocat4240 4 ปีที่แล้ว +1

    Whats the range

    • @mujtech4887
      @mujtech4887  4 ปีที่แล้ว

      KRYPTONITE TEC Approximately 10 meters inside buildings and 20 meters outside. The signal will reach between 20 to 30 meters but there will be a delay

    • @jigmie1797
      @jigmie1797 4 ปีที่แล้ว

      75m to 100m

    • @jigmie1797
      @jigmie1797 4 ปีที่แล้ว

      @@mujtech4887
      Can you help me with coding?

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      @@jigmie1797 Code has been posted in the comments

  • @sharanappabyali8212
    @sharanappabyali8212 5 ปีที่แล้ว

    I need aurdino code

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      It's been posted in the comments

  • @omaralshareef8313
    @omaralshareef8313 6 ปีที่แล้ว

    i need the codes

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      I posted the code in the comments

  • @the-beneficiary1809
    @the-beneficiary1809 2 ปีที่แล้ว

    You have womens hands F’kn Panzy

    • @user-xb9vu9pg3h
      @user-xb9vu9pg3h 8 หลายเดือนก่อน

      And you have sh*t for brains, whats your point?