How to setup Arduino with wireless communication

Posted by Mohammed 30/10/2016 0 Comment(s) Microcontrollers,Electronic components and parts,

Welcome to Zeroohm Arduino Training series. In this series of Arduino Training, Zeroohm will focus its efforts on helping the community learn more about Arduino fundamentals and basics starting with basic control of LED's, motors, sensors and utilizing of wirless communication. We hope that you find this useful, Please, leave a comment for any questions or comments or reviews!

We provide all our trainings for groups from schools, universities, public sector and private sector in Abu Dhabi, Dubai, Sharjah, Fujirah, RAK or anywhere in UAE. Please,click here to contact us directly for any training inquires.

We are also an authorized Arduino distributor for the UAE, Oman, Qatar, Saudi, Kuwait and Bahrain. We can provide you with any product of your choice. Please, contact us for inquires.

 

Our Arduino training series:

1. Start with Arduino - Zeroohm Arduino Training

2. Start with Arduino - Arduino with Motors and sensors

3. Start with Arduino - Wireless communication

4. How to setup Arduino with room temperature monitoring using LM36 sensor

5. Introduction to IoT using Arduino

5. Introduction to IoT using Arduino

6. IoT: Humidity and Temperature Sensor

7. ADXL345 Module Communication with Arduino UNO Board

 

 

 

   This tutorial aims to provide teach about:
-    Wireless Communication technologies.
-    How to use some of those technologies.
-    How to use Arduino in building your own wireless devices.
    
    Experiment 1: Remote Control
IR receiver (infrared receiver) is hardware that sends information from an infrared remote control to another device by receiving and decoding signals.
In this Task, you are going to switch on and off a LED using your own remote control.
1.    Connect the following Circuit using the shown components in Fig.1.


Components Required:
a.    1x LED
b.    1x Resistor 330Ω
c.    6x Jumper Wires
d.    1x IR Receiver Diode

 

 

2.    Open Arduino IDE software and start writing the following code:
#include <IRremote.h>

int IRpin = 11;                  // pin for the IR sensor
int LED = 9;                    // LED pin  
IRrecv irrecv(IRpin);
decode_results results;

boolean LEDon = true;         // initializing LEDon as true

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn();       // Start the receiver
  pinMode(LED, OUTPUT);
}

void loop()
{
  if (irrecv.decode(&results))
    {
      Serial.println(results.value, DEC);
      irrecv.resume();     // Receive the next value
    }
 
  switch(results.value)
 {

  case 16769055:         // Change this value to the one corrosponding to your remote button.
  digitalWrite(LED, LOW);
  delay(1000);
  break;
 
  case 16760895:        // Change this value to the one corrosponding to your remote button.
  digitalWrite(LED, HIGH);
  delay(1000);
  break;
 
  case 16728255:        // Change this value to the one corrosponding to your remote button.
  digitalWrite(LED, HIGH);
  delay(1000);
  digitalWrite(LED, LOW);
  delay(1000);
  break;  
 
  }
}

3.    Check that your code is correct and upload it to the RedBoard.
4.    Open the serial monitor and click any button on the remote control, copy the number of that button and change it in the code ( in the case structure).
5.    Re-upload the new code to the RedBoard.
6.    Notice what happens to the LED when you click your remote.

    Discussion:
-    In order to use the IR communication, you should download the IR library for Arduino from the following link:
-    https://drive.google.com/file/d/0B8Mk44FinGalQzJPYllTeXl6RUk/view?usp=sharing
-    To control the LED through any remote control you should first know the decimal  code of each button of the remote, which is the number appearing in the serial monitor.
-    Modify the number next to each CASE depending on the button you want to make the controlling from, and notice what happens to the LED when you click that button.

    Experiment 2: Smart Room
Bluetooth is a protocol for wireless communication. Devices such as mobile phones, laptops, PCs, printers, digital cameras and video game consoles can connect to each other, and exchange information. This is done using radio waves. It can be done securely.
In this Task, you are going to control the status of a LED via Bluetooth technology, by following these steps:
2.    Connect the following Circuit using the shown components in Fig.2.


Components Required:
a.    1x LED
b.    1x Resistor 330Ω
c.    3x Jumper Wires
d.    1x Bluetooth Shield
 
Fig. 2: Experiment 2 Circuit
Open Arduino IDE software and start writing the following code:
int led = 9;
void setup()
{
pinMode(led,OUTPUT);
Serial.begin(9600);
}

void loop()
{
    if (Serial.available())
    {
      char c = Serial.read();
 
      switch (c)
      {
        case '1':                              // Led ON              
        Serial.println("1");
        digitalWrite(led, HIGH);   
        break;
        
        case '2':                              // Led OFF               
        Serial.println("2");
        digitalWrite(led, LOW);   
        break;  
      }
    
    }
}

3.    Change the selection switch to “Soft Serial”
 

4.    Check that your code is correct and upload it to the RedBoard.
5.    Return the selection switch shown above to “Direct” mode
6.    Pair your laptop with your board, and check the COM port of the Bluetooth.
7.    Change the COM port in the Arduino IDE and open the serial monitor screen.
8.    Notice the status of the LED when you input the case value( 1 or 2). .

   Discussion:

-    This code switch a LED on and OFF when either the '1' letter or the '2' letter are sent to the serial port.

-    Like if statements, switch...case controls the flow of programs by allowing programmers to specify different code that should be executed in various conditions. In particular, a switch statement compares the value of a variable to the values specified in case statements.
-    When a case statement is found whose value matches that of the variable, the code in that case statement is run.

-    The break keyword exits the switch statement, and is typically used at the end of each case. Without a break statement, the switch statement will continue executing the following expressions ("falling-through") until a break, or the end of the switch statement is reached.

    Experiment 3: Wireless Wheel
A motor is a mechanical or electrical device that creates motion. An electrical motor is an electrical machine that converts electrical energy into mechanical energy.
In this task you will control the speed of a DC motor using the RedBoard by following these steps:
1.    Connect the following Circuit using the shown components in Fig.3.


Components Required:
a.    1x Transistor (2N2222)
b.    1x Resistor 330Ω
c.    1x Diode
d.    1x DC Motor
e.    6x Jumper Wires
 
Fig. 3: Experiment 3 circuit
2.    Open Arduino IDE software and start writing the following code:
int motorPin = 9;

void setup()
{
Serial.begin(9600);
}

void loop()
{
    if (Serial.available())
    {
      char c = Serial.read();
     
      switch (c)
      {
        case 'o':                                  // Motor ON              
        Serial.println("o");
        analogWrite(motorPin, 100);  
        break;
        
        case 'f':                                  // Motor OFF              
        Serial.println("f");
        analogWrite(motorPin, 0);  
        break;
      }
    
    }
}

3.    Change the COM port in the Arduino IDE and open the serial monitor screen.
4.    Notice the motor when you input the case value( o or f). .

   Experiment 4: Temperature Monitor
XBee is a family of small, cost effective radios that enable low power/low bandwidth simple wireless communication.
In this Task, you are going to monitor the room temperature wirelessly, by following these steps:
1.    Connect the following Circuit using the shown components in Fig.4.


Components Required:
a.    1x Temperature Sensor (TMP36)
b.    1x Piezo Buzzer
c.    1x XBee Shield for Arduino
d.    2x XBee S1 Modules
e.    1x USB to XBee adapter
f.    5x Jumper Wire
 
Fig. 4: Experiment 4 circuit

2.    Open Arduino IDE software and start writing the following code:

const int sensorPin = 0;
const int buzzerPin = 9;

void setup()
{
  Serial.begin(9600);
}


void loop()
{  
  float voltage, degreesC, degreesF;
 
  voltage = getVoltage(sensorPin);
  degreesC = (voltage - 0.5) * 100.0; // from datasheet
  degreesF = degreesC * (9.0/5.0) + 32.0;

  Serial.print("voltage: ");
  Serial.print(voltage);
  Serial.print("  deg C: ");
  Serial.print(degreesC);
  Serial.print("  deg F: ");
  Serial.println(degreesF);
  delay(1000);

  if (degreesC > 25)
  {
    tone(buzzerPin,1000);
  }
  else
   noTone(buzzerPin);

}


float getVoltage(int pin)
{
  return (analogRead(pin) * 0.004882814); // 5/1024
}

3.    Change the selection switch to “DLINE”
4.    Check that your code is correct and upload it to the RedBoard.
5.    Change the selection switch back to “UART”
6.    Check the COM port of your XBee Explorer Dongle.
7.    Change the COM port in the Arduino IDE and open the serial monitor screen.
8.    Both the C and F temperature would appear on the screen.

   Discussion:

-    getVoltage function saves the value of the sensor pin and display it on the serial monitor. Functions help the programmer stay organized, and codify one action in one place so that the function only has to be thought out and debugged once.

-    Functions can either be written before the loop function of after it.

-    In this code we’re converting the voltage we’re getting from the sensor to a temperature value using a mathematical formula that differs from one sensor to another. This formula can be found in the datasheet of the sensor.

-    By using the if statement, we turn the buzzer on when temperature is higher than 25C and turn it off otherwise.

 


    Experiment 5: Smart LCD
LCD (liquid crystal display) is the technology used for displays in notebook and other smaller computers.
In this Task, you are going to write anything on the LCD wirelessly by following these steps:
1.    Connect the following Circuit using the shown components in Fig.5.


Components Required:
a.    1x 16x2 LCD (with pins soldered)
b.    1x Potentiometer
c.    16x Jumper Wires
 
Fig. 5: Experiment 5 circuit

2.    Open Arduino IDE software and start writing the following code:

#include <LiquidCrystal.h>                        // include the library code:
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);             // initialize the library with the numbers of the    
         interface pins
void setup()
{
  lcd.begin(16, 2);                               // set up the LCD's number of columns and rows
  Serial.begin(9600);                            // initialize the serial communications
}

void loop()
{
  if (Serial.available())                                 // when characters arrive over the serial port...
  {
    delay(100);                                      // wait a bit for the entire message to arrive
    lcd.clear();                                    // clear the screen
    while (Serial.available() > 0)               // read all the available characters
    {
      lcd.write(Serial.read());               // display each character to the LCD
    }
  }
}

3.    Change the COM port in the Arduino IDE and open the serial monitor screen.
4.    Write anything in the serial monitor and notice what appears on the LCD.

    Discussion:

-    In order for the LCD to work probably, you should include the LCD library in your code using  the line #include <LiquidCrystal.h> then initialize the pins by LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

-    lcd.begin(16, 2) is used to set up the LCD's number of columns and rows, where it has 16 columns and 2 rows.

-    lcd.write() is used to  write character to the display.

Leave a Comment