Saturday, November 28, 2015

USING RF433MHz WEATHER STATION WITH ARDUINO

A weather station is a facility, in land or sea.If we want to know that the actual condition of weather.The measurement which taken by it temperature, barometric pressure, humidity, wind speed, wind direction and precipitation amount. Manual observations are taken daily,while automated measurements are taken atleast once an hour.






In this project I will show you how make two Arduino talk to each other using RF frequency (wireless).
In the past I published four instructables that lead to this one.
The first two are about connecting a serial LCD with I2C to an Arduino UNO and a NANO.
Another one showing how to use an LM35 temperature sensor with Arduino and an LCD.
And the last one is about using an LM35 temperature sensor without an LCD.
Now I will use the knowledge in all these project and improve on them by making one Arduino send data to another Arduino wirelessly using an RF433 module and displaying it on I2C serial LCD.

Step 1: What is needed for this project



Project component which we need:
1.    2 Arduinos, I am using an UNO and a NANO
2.    2 Solderless breadboards
3.    A pair of RF433 Wireless TX-RX
5.    An I2C serial LCD
6.    And a bunch of jumper wires
The RF433 Wireless TX+RX Pair are ideal for this project because they have a good range about 14 meters or 47 feet without antenna and 31 meters or 102 feet if you attach a 17.4cm antenna on both modules.Those numbers are in theory, real life result may vary according to voltage,temperature,walls etc....but the idea is that they are great for a 1$ piece of electronics.

Step 2: Connect the Uno, LM35 and the transmitter




I selected the UNO for this part because it can be powered by an external source.
  1. First connect the GND and the VCC from the Arduino to the bread board
  2. Insert the LM35 on the breadboard and connect the GND and the VCC (see picture for the location of the VCC and the GND pin on the LM35).The middle prong connects to PIN A0 on the Arduino.
  3. If you reverse the GND and the VCC on the LM35, it will heat up and produce readings in the range of 300 to 500 degrees C. (if this happens avoid touching it with your hands)
  4. Insert the RF433-TX module, place it facing you and Pins should be DATA, VCC, GND from left to right (see picture)
  5. Connect the VCC and the GND to the +/- rails on the breadboard and the Data pin connects on digital pin 12 on the Arduino.

This is it for this part, next I will discuss the transmitter sketch.
Step 3: Transmitter Sketch
Start by loading the Virtual Wire library which is responsible for communication between the RF433 TX and RX modules
#include <VirtualWire.h>
 I will define few variables.
float temp;        This will be the variable I will use to store the temperature reading<br>int sensor = 0;    This is the A0 where the LM35 data pin is connected                   char msg[6];    This is a Char array called msg that I will use to transmit the data with
Here I will define the TX pin is on digital pin 12 on the Arduino and set the transfer rate to 2000 bps.
vw_set_tx_pin(12);          // Sets pin D12 as the TX pin<br>vw_setup(2000);         // Bits per sec
In the void loop I read the temperature from the sensor and store it in the variable temp then convert it to Celsius by multiplying the result with 0.48828125
temp = analogRead(sensor);
temp = temp * 0.48828125;
Then I change the type of the variable temp from float to char and store the values in an array called msg to transmit it to the RF433-RX.
dtostrf(temp, 6,2,msg);
Theen I transmit the data over to the RX.
vw_send((uint8_t *)msg, strlen(msg)); <br>vw_wait_tx();                                                                            delay(200);

Step 4: Connect the NANO, the Receiver and the I2C LCD




In this section I will connect the NANO with the LCD and the RF433-RX module
·        Plug in the NANO on the breadboard
·        Then insert the RF433-RX module
Connect the VCC and the GND from the RF433-RX to the NANO GND and VCC and connect the Data PIN (left most pin) to the digital pin 12 on the NANO.
Connect the GND and the VCC from the I2C serial LCD to the GND and the VCC pins on the NANO, and then connect the SDA to analog pin 4 on the NANO and the SCL to analog pin 5 on the NANO.

Step 5: Receiver sketch

There is more action in this sketch:
First load the libraries:
#include <VirtualWire.h>
#include<Wire.h> 
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
Then define the variables: and initialize the LCD
#define I2C_ADDR          0x27        //Define I2C Address where the PCF8574A is<br>#define BACKLIGHT_PIN      3
#define En_pin             2
#define Rw_pin             1
#define Rs_pin             0
#define D4_pin             4
#define D5_pin             5
#define D6_pin             6
#define D7_pin             7
int I;
//Initialise the LCD
LiquidCrystal_I2C      lcd(I2C_ADDR, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
In the void setup I define the LCD, turn on the backlight, set the RX pin on digital 12 on the NANO, set the transfer rate to 2000bps and tell the receiver to listen for incoming transmission.
//Define the LCD as 16 column by 2 rows <br>    lcd.begin (16,2);
    
//Switch on the backlight
    lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
    lcd.setBacklight(HIGH);
    
//Define the receiver pin and rate
    vw_set_rx_pin(12);       //Sets pin D12 as the RX Pin
    vw_setup(2000);          // Bits per sec
    vw_rx_start();           // Start the receiver PLL running
In the void loop, the NANO checks for transmission,and if it receives one, it prints "The temp is" on the first line on the LCD and then prints the value with degrees Celsius on the second line.
uint8_t buf[VW_MAX_MESSAGE_LEN];<br>   uint8_t buflen = VW_MAX_MESSAGE_LEN;
   
   if( vw_get_message(buf, &buflen) )
      {
        lcd.setCursor(0, 0);
        lcd.print("Temp inside is:");    
        lcd.setCursor(3,1);  
        
       for (i = 0; i < buflen; i++)
         { 
           lcd.write(buf[i]); 
                    
         }
        
           lcd.print((char)223);
           lcd.print("C");
 
 
 
 
CONCLUSION
 
Now my project is ready for working.But in this my personal experience is so good but some time codes irritate me.So in this main focus on the code.

Friday, November 27, 2015

USING (WS2801+ ARDUINO)AMBILIGHT SYSTEM

Ambilight system create a light effects in television that correspond to the video content.Ambilight is a lighting system that adjust the brightness and colour based upon picture content.content. Ambilight system works by projecting light from the back. Viewers can choose ambilight follow brightness and colors in the change of program content.
The colors in reality are 99% true, the whites in this video were more purple since recording using my iphone.
so, here it's guys, the ultimate ambilight clone you can make.
what are we trying to accomplish is scanning the edges of a screen and determining the average color of those spots, then apply those colors to the led’s, in a fast way that we shouldn't notice any delay while watching a videos
To make this possible we need.
·        Addressable led’s, to be exact we need the ws2801, they come in many shapes, I got the 5m strip from:
·        Arduino uno micro-controller with usb cable, u can find it easily, no need to buy it online)
·        A windows pc,I have tested this only on windows 8.1 pro x64, and lately with windows 10 pro x64
·        A power supply to power the leds, in this case I am using the pc power supply to get the 5 volts, don’t use the power from the arduino or usb, it wouldn't work.
·        the whole project normally costs around 70$, if you are getting the whole 5m of the led strip.
let's connect those wires)



Step 1: Wires connections diagram





Connect everything from the IN side on led strip and not the out side, since this strip is not analog, it's digital, direction of data is important.

The ws2801 has 4 wires to be connected, let's start with the ground, ground the led strip GND to the arduino and the powers supply ground, very important to prevent flickering.
Next thing is connecting the arduino to pc, easy, using a usb cable.
To power the led strip we need 5v, tab into any not used molex connecter in your power supply, usually 5v is the red wire, check it with a volt meter, if it's, connect it to the 5v in the led strip.
Two wires are lift, the SD is the data, connect it pin 11 on the arduino.
Last wire is the ck wire, which is the clock wire, connect it to pin 13 on arduino.
That’s about all about the connections.
NOTE:
setup your led strip around the screen, You can either have it go all around the screen, or just the main 2 sides and the top as I did, since usually the bottom of the screen isn't far from a table, it would look much better if your screen is on a wall, the closer to the wall the better.

Step 2: Code, software and downloads

You need to know what com port your arduino is connected to, you can find that using the device manager.
Download the sketch and upload it.
On pc, we need the capturing program, I have tested 3 programs, ambibox is the best so far, specially if you are on windows 10, it has the ability to capture your desktop and full screen apps and games, so no worries.
Last thing is to install ambibox, select ad alight as a device, select your com port.
Count how many led’s you have used around your screen, setup your scanning box, and you are good to go.
Note that some strips have different color orders, the one I got is BGR so you can select that also.
Also note that the arduino sketch isn't the same as the one on ad alight site, I found this modified faster version that works with me flawlessly.
For capturing method select windows 8, even if you are on windows 10.
You can modify you color settings such as gamma and saturation to make the colors match the screen.
Ambibox has many other features such as constant color and mobile control along with creating profiles for certain moods such as letterbox movies and full screen videos.
That’s about all, don't forget to comment and give feed back.

 CONCLUSION



This is the picture of ambilight system you can change brightness and colors in the change of coding accordingly.

Post your comments and changes in the section below.




USING ARDUINO UNO AND 8×8 LED MATRIX 2PLAYER PONG GAME

In this project we discuses in which type we create a game using 8×8 matrix of Led. In this the player control sticks by potentiometer if he want to try go left than turn the potentiometer to the left.
In this the game speed increases by time. And after each game, the score is shown on the screen for 2 seconds and after that a new game starts. Here there aris simple audio effects like ball bouncing and a game over tune. You can see the game in action in this short video.
Tech details Considering the fact that Arduino Uno has only 14 digital output pins, I decided to use a 74HC154 4-to-16 decoder to control 8x8 Led Matrix. While 8 digital pins directly control 8 rows of the led matrix(anode), 4 digital pins select the column over 74HC154 decoder(cathode).
I tried to draw the circuit schema using Fritzing, but I gave up realizing that Fritzing doesn't have built-in 8x8 Led Matrix and 4-to-16 decoder tools yet.
This project is the result of my first experiments by arduino uno considering this fact arduino uno has 14 digital output pins, than I decide to use 74HC154   4 TO 16  decoder to control the 8×8 Led matrix.

Now below given the decoder diagram graphically all details mention over there.


CODING:
/**
 * Ping Pong with 8x8 Led Dot Matrix on Arduino
 *
 * @author  Bruno Soares
 * @website www.bsoares.com.br
 */


#include "TimerOne.h"

#define PIN_LEFT 4
#define PIN_RIGHT 5

unsigned int left = 0;
unsigned int right = 0;
int angle = 0;
int radians;

byte rows[
8] = {9, 14, 8, 12, 1, 7, 2, 5};
byte cols[
8] = {13, 3, 4, 10, 6, 11, 15, 16};
byte pins[
16] = {5, 4, 3, 2, 14, 15, 16, 17, 13, 12, 11, 10, 9, 8, 7, 6};
byte screen[
8] = {0, 0, 0, 0, 0, 0, 0, 0};
volatile byte screenRow = 0;
volatile byte screenCol = 0;

int _angle;
int _px;
int _py;
int _w = 7;
int _h = 7;
int _wall[] = {3, 3};
int _count = 0;
int _speed = 3;
int _countPoints = 0;


void setup() {
  Timer1.
initialize(100);
  
for (int i = 2; i <= 17; i++)
    pinMode(i, OUTPUT);
  Timer1.
attachInterrupt(doubleBuffer);
  
  Serial.
begin(9600);
  
  face();
  reset();
}

void doubleBuffer() {
  digitalWrite(translatePin(rows[screenRow]), LOW);
  digitalWrite(translatePin(cols[screenCol]), HIGH);
  
  screenCol++;
  
if (screenCol >= 8) {
    screenCol 
= 0;
    screenRow++;
    
if (screenRow >= 8) {
      screenRow 
= 0;
    }
  }
  
  
if((screen[screenRow] >> screenCol) & B1 == B1) {
    digitalWrite(translatePin(rows[screenRow]), HIGH);
    digitalWrite(translatePin(cols[screenCol]), LOW);
  } 
else {
    digitalWrite(translatePin(rows[screenRow]), LOW);
    digitalWrite(translatePin(cols[screenCol]), HIGH);
  }
}

byte translatePin(byte original) {
  
return pins[original - 1];
}

void allOFF() {
  
for (int i = 0; i < 8; i++)
    screen[i] 
= 0;
}

void on(byte row, byte column) {
    screen[column-
1] |= (B1 << (row - 1));
}

void off(byte row, byte column) {
    screen[column-
1] &= ~(B1 << (row - 1));
}

void calcWall()
{
  left 
= analogRead(PIN_LEFT);
  right 
= analogRead(PIN_RIGHT);
  left 
= constrain(map(left, 223, 800, 0, 6), 0, 6);
  right 
= constrain(map(right, 223, 800, 6, 0), 0, 6);
  
  clearWall();
  
  on(
1, left + 1);
  on(
1, left + 2);
  on(
8, right + 1);
  on(
8, right + 2);
  
  _wall[
0] = left;
  _wall[
1] = right;
  show();
}

void clearWall()
{
  
for (int i = 0; i < 8; i++)
    screen[i] &
= B01111110;
}

void clearGame()
{
  
for (int i = 0; i < 8; i++)
    screen[i] &
= B10000001;
}

void loop() {
  calcWall();
  enterFrameHandler();
  delay(
50);
}

void enterFrameHandler()
{
  
if (_count++ < _speed)
    
return;
  
  _count 
= 0;
  checkCollision();
  calcAngleIncrement();
  show();
}

void retorted(int angle)
{
  Serial.
println(angle);
  _angle 
= angle;
  
  
if (++_countPoints % 5 == 0 && _speed > 1)
    _speed--;
}

void resetAnim()
{
  
for (int i = 0; i < 8; i++)
  {
    screen[i] 
= B11111111;
    delay(
25);
  }
  
for (int i = 0; i < 8; i++)
  {
    screen[i] 
= B00000000;
    delay(
25);
  }
}

void face()
{
  on(
1, 1);
  on(
1, 2);
  on(
2, 1);
  on(
2, 2);
  on(
7, 1);
  on(
7, 2);
  on(
8, 1);
  on(
8, 2);
  on(
1, 1);
  on(
1, 2);
  on(
4, 4);
  on(
4, 5);
  on(
5, 4);
  on(
5, 5);
  on(
2, 7);
  on(
7, 7);
  on(
3, 8);
  on(
4, 8);
  on(
5, 8);
  on(
6, 8);
  delay(
5000);
}

void reset()
{
  resetAnim();
  
  _px 
= random(3, 5);
  _py 
= random(3, 5);
  _angle 
= random(0, 2) == 0 ? 0 : 180;
  _speed 
= 5;
  _countPoints 
= 0;
  
  show();
  delay(
500);
}

void show()
{
  clearGame();
  on(_px + 
1, _py + 1);
}

void checkCollision()
{
  
if (_px == _w - 1)
  {
    
if (_angle == 315 || _angle == 0 || _angle == 45)
    {
      
if (_py == _wall[1] || _py == _wall[1] + 1)
      {
        
if (_angle == 0 && _py == _wall[1])
          retorted(
225);
        
else if (_angle == 0 && _py == _wall[1] + 1)
          retorted(
135);
        
else if (_angle == 45 && _py == _wall[1])
          retorted(
135);
        
else if (_angle == 45 && _py == _wall[1] + 1)
          retorted(
180);
        
else if (_angle == 315 && _py == _wall[1])
          retorted(
180);
        
else if (_angle == 315 && _py == _wall[1] + 1)
          retorted(
225);
      }
    }
  }
  
else if (_px == 1)
  {
    
if (_angle == 225 || _angle == 180 || _angle == 135)
    {
      
if (_py == _wall[0] || _py == _wall[0] + 1)
      {
        
if (_angle == 180 && _py == _wall[0])
          retorted(
315);
        
else if (_angle == 180 && _py == _wall[0] + 1)
          retorted(
45);
        
else if (_angle == 135 && _py == _wall[0])
          retorted(
45);
        
else if (_angle == 135 && _py == _wall[0] + 1)
          retorted(
0);
        
else if (_angle == 225 && _py == _wall[0])
          retorted(
0);
        
else if (_angle == 225 && _py == _wall[0] + 1)
          retorted(
315);
      }
    }
  }
  
  
if (_px == _w)
  {
    reset();
  }
  
else if (_px == 0)
  {
    reset();
  }
  
else if (_py == _h)
  {
    
if (_angle == 45)
      _angle 
= 315;
    
else if (_angle == 135)
      _angle 
= 225;
  }
  
else if (_py == 0)
  {
    
if (_angle == 225)
      _angle 
= 135;
    
else if (_angle == 315)
      _angle 
= 45;
  }
}

void calcAngleIncrement()
{
  
if (_angle == 0 || _angle == 360)
  {
    _px +
= 1;
  }
  
else if (_angle == 45)
  {
    _px +
= 1;
    _py +
= 1;
  }
  
else if (_angle == 135)
  {
    _px -
= 1;
    _py +
= 1;
  }
  
else if (_angle == 180)
  {
    _px -
= 1;
  }
  
else if (_angle == 225)
  {
    _px -
= 1;
    _py -
= 1;
  }
  
else if (_angle == 315)
  {
    _px +
= 1;
    _py -
= 1;
  }
}
This coading related to the game you can use it in your game if you create any change in this coading than your game action also change.