Wednesday, 26 April 2017

Android meeting Arduino

Hardware required


  1. Arduino uno-1 pcs.
  2. Android phone or Tablet.
  3. Bluetooth adapter HC 06-1pcs.
  4. LEDs - 3 nos.
  5. Jumper wires - 7 nos.

HC06 Bluetooth Device

Project description


I am going to control 3 LEDs by using a mobile phone which is running in Android OS. Here, i am using android phone as remote to control led. I can switch on and switch off light and control the brightness of one led also. I made android app by MIT app inventor. You can download android app by searching "light" in MIT app inventor gallery after log on to this site or you can download by link https://drive.google.com/file/d/0B_w5O5-1CXjJU3hCcHoyempBREk/view?usp=sharing.

For installing this app, don't forget to enable phone to install app from Unknown sources. For this go to Settings~Security~Unknown sources and enable Allow installation of apps from unknown sources


Circuit Diagram


HC06 Connection 
Connect Vcc of HC06 to +5v of Arduino.
Connect Gnd of HC06 to Gnd of Arduino.
Connect Tx of HC06 to pin 10 of arduino.
Connect Rx of HC06 to pin 11 of arduino.


Video




Arduino Script


#include <SoftwareSerial.h>
SoftwareSerial Bt(10,11);//Rx of HC06 to 11 & Tx to 10
int val;
// recieving value as intiger from HC06 bluetooth device


void setup() 
{
 Bt.begin(9600);
 pinMode(7,OUTPUT);//pin 7,8 & 9 as output
 pinMode(8,OUTPUT);
 pinMode(9,OUTPUT);//pin 9 is also using as PWM output to //controll brightness
}

void loop() 
{
  if(Bt.available()>0)
  {
    val=Bt.read();
  }
  
  if(val>100)
  {
    switch(val)
    {
      case 101:
      {
        digitalWrite(7,1);
        break;
      }
      case 102:
      {
        digitalWrite(7,0);
        break;
      }
      case 103:
      {
        digitalWrite(8,1);
        break;
      }
      case 104:
      {
        digitalWrite(8,0);
        break;
      }
      case 105:
      {
        digitalWrite(9,1);
        break;
      }
      case 106:
      {
        digitalWrite(9,0);
        break;
      }
      case 107:
      {
        digitalWrite(7,1);
        digitalWrite(8,1);
        digitalWrite(9,1);
        break;
      }
      case 108:
      {
        digitalWrite(7,0);
        digitalWrite(8,0);
        digitalWrite(9,0);
        break;
      }
      
    }
  }
  else
  {
    //maping value to 0 to 255 from 0 to 255
    int mod_val=map(val,0,100,0,255);
    analogWrite(9,mod_val);
  }


}



Friday, 7 April 2017

Arduino I2C communication and Light meter with Nokia 5110 and LDR

Hardware required

1. Arduino UNO  - 2pcs.
2. Nokia 5110 LCD display  - 1pcs.
3. LDR  - 1pcs.
4. Resistor 10 Kohm - 6pcs.
5. Resistor 1 Kohm  -1 pcs.
6 Jumper wires - 15 pcs.
7.Breadboard  -1pcs.

Project description

In this project, I am going to make one Light meter by using light depended resistor (LDR) and showing Arduino to Arduino I2C communication through wire library. For light measurement display, I am using Nokia 5110 LCD display and library is using for that one is pcd8544 library, you can download it from internet by searching in google.

Connection Diagram





Program

1. Program for Master Arduino.



// Wire Master Writer

#include <Wire.h>
float light;
int x;

void setup() 
{
  Wire.begin();
  Serial.begin(9600);
  // join i2c bus (address optional for master)
}


void loop() 
{
// connect LDR to analog A0 input by using 10 k ohm resistance as pull up resistor as shown in
// connection digram.
  light=analogRead(A0);
  x=map(light,0,1024,0,255);
  Serial.println(x);
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("light intensity");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  
  delay(500);
}

2. Program for Slave Arduino.


// Wire Slave Receiver

#include <Wire.h>
// Using wire library it is inbuilt in arduino IDE

#include <PCD8544.h>
// Library for nokia 5110 display. download it from internet

// Nokia 5110 lcd connection
// Nokia 5110 lcd is working wit 3.3 VDC so need to reduce +5v of arduino to 3.3V
// connect 10 k ohm resistance with every connection except vcc, Gnd and BL
// RST connect to 10 k-Ohm resistance series and pin no 6 of Arduino
// CE connect to 10 k-Ohm resistance series and pin no 7 of Arduino
// DC connect to 10 k-Ohm resistance series and pin no 5 of arduino
// Din connect to 10 k-Ohm resistance series and  pin no 4 of arduino
// Clk connect to 10 k-Ohm resistance series and pin no 3 of arduino
// Vcc to +5v of arduino directly
// BL connect with 1k ohm  to arduino pin +5v
// Gnd to Gnd of arduino



static const byte glyph[] = { B00010000, B00110100, B00110000, B00110100, B00010000 };
int x;

static PCD8544 lcd;

void setup()
{  
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(9600); // start serial for output
  lcd.begin(84, 48);
}

void loop() 
{
  delay(100);
  lcd.setCursor(0, 0);
  lcd.print("Light in % ");
  lcd.setCursor(0,1);
  lcd.print("    ");
  lcd.setCursor(0,2);
  lcd.print("     "+String(x)+"%");
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()

void receiveEvent(int howMany) 
{
  while (1 < Wire.available()) 
  { 
    // loop through all but the last
    char c = Wire.read(); // receive byte as a character
   }

   x = Wire.read(); // receive byte as an integer
   x=map(x,0,255,0,100); //mapping for getting percentage

}

Video