Wednesday, April 27, 2016

Engr. Aneel Kumar

ARDUINO BASED WIRELESS LED ACTIVATION

In this mini-project, you’ll create two identical assemblies, each consisting of an Arduino and XBee, along with a button and a LED. When you press the button on one assembly, the LED on the other one lights up, and vice versa.
Figure 1: Control LEDs with XBee-equipped Arduinos.

Parts Required:

You’ll be making two assemblies, so you need two of everything!
  1. Arduinos (x2)
  2. XBees (x2)
  3. Breakout boards (x2)
  4. Pushbuttons (x2)
  5. Breadboards (x2)
  6. LEDs (x2)
  7. Jumpers
Project Description:

Follow these steps to assemble the XBee test platform: 


1. Solder the breakout boards:

Solder up your XBee breakout boards if you haven’t already. Depending on your kit, this could mean simply soldering in some header pins. 
On other kits, however, you must solder in LEDs, capacitors, and so on. 


2. Connect the XBees to the breakout boards:

Attach the XBees to their respective breakout boards. This typically involves simply plugging in the XBees’ pins to the appropriate holes in the breakout board. Just follow the directions that accompany your kit. 


3. Attach to breadboards:

Plug the breakout boards and XBees into the breadboards. You can see where to place it in Figure 2.
Figure 2: This diagram shows you how to create these XBee test modules.

4. Attach the pushbuttons, LEDs, and jumpers:

Attach these items as follows (also shown in Figure 2): 

A. GND on the XBee goes to GND on the breadboard. Connect the GND bus of the breadboard to the GND port of the Arduino. 
B. +5V on the XBee goes to 5V on the Arduino. 
C. TX on the XBee goes to RX on the Arduino. 
D. RX on the XBee goes to TX on the Arduino. 
E. Connect a button to pin 8 on the Arduino; the other end connects to the GND bus. 

You should end up with two identical units, and if you upload the Arduino code to both of them, they should work identically. Even cooler, the way the networks are set up, you could actually create three or more of these assemblies and they’ll all work the way you would expect. Press the button on one, and the LEDs on all the others will light up! It’s not super practical, to be sure, but it shows how easily you can set up an XBee network.


Wireless LED Code:

Upload the following code to both Arduinos. Remember, both modules are identical, down to the software. 

#include <Wire.h> 
const int buttonPin = 8; 
const int ledPin = 13; 
int buttonState = 0; 
void setup() 
Serial.begin(9600); 
pinMode(ledPin, OUTPUT); 
pinMode(buttonPin, INPUT_PULLUP); 
void process_incoming_command(char cmd) 
int speed = 0; 
switch (cmd) 
case ‘1’: 
case 1: 
digitalWrite(ledPin, LOW); 
break; 
case ‘0’: 
case 0: 
digitalWrite(ledPin, HIGH); 
break; 
void loop() { 
if (Serial.available() >= 2) 
char start = Serial.read(); 
if (start != ‘*’) 
return; 
char cmd = Serial.read(); 
process_incoming_command(cmd); 
buttonState = digitalRead(buttonPin); 
if (buttonState == HIGH) { 
Serial.write(‘*’); 
Serial.write(1); 
else { 
Serial.write(‘*’); 
Serial.write(0); 
delay(50); //limit how fast we update 
}
Download Project Code Click Here

Engr. Aneel Kumar -

Subscribe to this Blog via Email :