Get Started with interface of arduino uno with ultrasonic sensor

on Tuesday, February 14, 2017

               
Hi everyone,


I am vigneshraja. here i present the code for interfacing arduino uno with ultrasonic sensor like shown in above video.

The Code for view the value in serial monitor from ultrasonic sensor:



#define trigPin 8
#define echoPin 9


void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

void loop() {
  long duration, distance;
 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);

  distance = duration /74 /2;
 
  Serial.print(distance);
  Serial.println(" inch");
 
 
  delay(500);
}


Code for interface with buzzer and led to notify when the object near to the ultrasonic sensor as in the video:

#define trigPin 8
#define echoPin 9
#define led 13
#define buzzer 12

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(led, OUTPUT);

}

void loop() {
  long duration, distance;
 
  digitalWrite(trigPin, LOW); 
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);

  distance = duration /74 /2;
 
  Serial.print(distance);
  Serial.println(" inch");
 
   if(distance <= 12)
  {
  digitalWrite(buzzer, HIGH);
  digitalWrite(led, HIGH);
  }else
  {
    digitalWrite(buzzer, LOW);
    digitalWrite(led, LOW);
  }
 
  delay(500);
}











                                                       Thank you For Reading

Get Started with bluetooth module and arduino

on Sunday, May 31, 2015





Hi everyone,

I am vigneshraja. here i present the code for interfacing arduino with bluetooth module like shown in above video.


Code for command mode control of arduino from phone:


int led = 13;
void setup()
{
  Serial.begin(9600);
 
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
}
void loop()
{
 if(Serial.available())
 {
   String value = Serial.readStringUntil('\n');
   Serial.println(value);
   if(value == "on")
   {
     digitalWrite(led,HIGH);
   }
   else if(value == "off")
   {
     digitalWrite(led,LOW);
   }
 
 }
}



code for control arduino by voice from your phone:


int led = 13;
void setup()
{
  Serial.begin(9600);
 
  pinMode(led,OUTPUT);
  digitalWrite(led,LOW);
}
void loop()
{
 if(Serial.available())
 {
   String value = Serial.readStringUntil('\n');
   Serial.println(value);
   if(value == "*hello#")
   {
     digitalWrite(led,HIGH);
   }
   else if(value == "*1#")
   {
     digitalWrite(led,LOW);
   }
 
 }
}



                                                      Thank you for reading

Dark detector using low power MSP430

on Sunday, February 22, 2015








circuit diagram:







coding:

int led = P1_6;
void setup()
{
pinMode(led,OUTPUT);
digitalWrite(led,LOW);
}

void loop()
{
  int ldr = analogRead(A5);
  if(ldr < 10)
  {
  digitalWrite(led,HIGH);
  }
  else
  {
   digitalWrite(led,LOW);
  }
}



                                 Thank you for reading.

Touch sensor for MSP430 launchpad

on Tuesday, November 18, 2014



Circuit diagram:








Coding:


Programming code for code composer studio users:





#include  <msp430g2231.h>
#define Key (P1IN & 0X08)
unsigned int i;

void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;    // Stop watchdog timer
  P1DIR |= 0x01;               // Set P1.0 to output direction
  P1OUT &= ~(0x01);
  while(1)
  {
        if(!Key)
        {
            while(!Key);
            P1OUT ^= 0x01;          // Toggle P1.0 using exclusive-OR
        }
  }
}





Programming code for energia software users:





int led = P1_0;
int button = P1_3;
void setup()
{
  pinMode(led,OUTPUT);
  pinMode(button,INPUT);
  digitalWrite(led,LOW);
}

void loop()
{
  int data = digitalRead(button);
 
  if (data == LOW){
  if(digitalRead(led) == HIGH){
  digitalWrite(led,LOW);
 }
if(digitalRead(led) == LOW){

  digitalWrite(led,HIGH);
}
 
  }
 
}

BUILT YOUR OWN H- BRIDGE CIRCUIT USING NPN TRANSISTER

on Thursday, July 17, 2014


            Hi everyone .here i am showing my project building H-bridge circuit to control the dc motor rotation direction. In this circuit i am using 4 NPN TIP122 transistors. here i am using msp430 to produce two control inputs to access the h bridge circuit. you can use what ever micro controller u have. just produce 0,1 bit to rotate motor in clockwise direction. 1,0 bits to rotate in counter clockwise direction and 0,0 bits to stop the motor  and you can use this circuit in robot making,rc,etc to control dc motor direction of rotation.


CIRCUIT:




PROGRAM CODE:

Here is the program for this project. i use energia software to program msp430 launchpad
to download energia software click the link bellow:
http://energia.nu/download/


const int buttonPin = PUSH2;     // the number of the pushbutton pin
const int motorPin1 =  P1_0;
const int motorPin2 =  P1_6;

// the number of the LED pin

// variables will change:

int buttonState = 0;         // variable for reading the pushbutton status

void setup() {

  pinMode(motorPin1, OUTPUT);   
  pinMode(motorPin2, OUTPUT);  
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT_PULLUP);    
}

void loop(){
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    
      
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW); 
  }
  else {
   
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, HIGH);
  }
}

                                                        
DIRECT CIRCUIT USE H BRIDGE WITH OUT PROGRAM:

                 Use the push button to control motor without controller. for that assemble the circuit bellow. for one button push motor rotate clock wise. for another button push motor rotate anti clock wise. don't push two button at same time.




                                                              Thank you for watching.

MSP430 SERIAL COMMUNICATION USING ENERGIA AND PROCESSING -2

on Thursday, July 3, 2014









HI every one . here i achieve serial communication of msp430 launchpad using energia software. here i read the analog value of light intensity from ldr voltage divider circuit. convert the analog value into 10 bit digital value. and print the value in serial port. and finally read the serially printed value for show the value variation graph form using processing software.

to download energia software:
http://energia.nu/download/

to download processing software:
https://www.processing.org/download/?processing


CIRCUIT:




ENERGIA CODING:

void setup() {
  // initialize the serial communication:
  Serial.begin(4800);
}

void loop() {
  // send the value of analog input 3:
  int data = analogRead(A3);
  Serial.println(data);
// serially print the analog value

}











PROCESSING CODE:

import processing.serial.*;

Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph

void setup () {
  // set the window size:
  size(400, 300);
 myPort = new Serial(this, "COM13", 4800);   // select the com port in which port launchpad  
                                                                           //connected in your computer.
  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');
  // set inital background:
  background(0);
}
void draw () {
  // everything happens in the serialEvent()
}

void serialEvent (Serial myPort) {
  // get the ASCII string:
  String inString = myPort.readStringUntil('\n');

  if (inString != null) {
    // trim off any whitespace:
    inString = trim(inString);
    // convert to an int and map to the screen height:
    float inByte = float(inString);
    inByte = map(inByte, 0, 1023, 0, height);

    // draw the line:
    stroke(127,34,255);
    line(xPos, height, xPos, height - inByte);

    // at the edge of the screen, go back to the beginning:
    if (xPos >= width) {
      xPos = 0;
      background(0);
    }
    else {
      // increment the horizontal position:
      xPos++;
    }
  }
}


                                                 Thank you for watching

MSP430 MAGIC CUBE

on Friday, June 27, 2014







Hi everyone . i did led fun project using msp430 launchpad.This project has four leds are triggered by msp430 two get different colors. the colors combination of two led color enhanced by paper cube. the color leds used in this project are red,green,blue,yellow. The color mixing is achieved by  simply glow the two led at same time for example when red and yellow leds glow together it produce orange color.
The software used for program the MSP430 is ENERGIA. you can download energia software at the bellow link:

http://energia.nu/download/

CODING:

In this project i used two kind of program

1. Contionusly change the cube color in certain delay.
2.Change color when we push the push button in msp430 launchpad.

Code for contionusly change the cube color in certain delay:

 const int ledPin = RED_LED;
const int green =P1_4 ;
const int blue = P1_7;
const int yellow = P1_6;
void setup()
{
  pinMode(ledPin, OUTPUT);
   pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
     pinMode(yellow, OUTPUT);
 
}

void loop()
{
 digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
   delay(3000);
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
   delay(3000);
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
   delay(3000);
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, HIGH);
   delay(3000);
  digitalWrite(ledPin, HIGH);
   digitalWrite(green, HIGH);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
  delay(3000);
  digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
   delay(3000);
}



Code for change color when we push the push button in msp430 launchpad:


 const int  buttonPin = PUSH2; 
const int ledPin = RED_LED;
const int green =P1_4 ;
const int blue = P1_7;
const int yellow = P1_6;

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT_PULLUP);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
   pinMode(green, OUTPUT);
    pinMode(blue, OUTPUT);
     pinMode(yellow, OUTPUT);
  // initialize serial communication:

}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
   
    }
 
  }
 
  lastButtonState = buttonState;

 
  if (buttonPushCounter== 2) {
     digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  }else if(buttonPushCounter == 3)
  {
    digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
 
  }else if(buttonPushCounter == 4)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 5)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  }  else if(buttonPushCounter == 7)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  } else if(buttonPushCounter == 6)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, HIGH);
 
  }else if(buttonPushCounter == 8)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, HIGH);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 9)
  {
   digitalWrite(ledPin, HIGH);
   digitalWrite(green, LOW);
   digitalWrite(blue, HIGH);
   digitalWrite(yellow, LOW);
 
  }
  else if(buttonPushCounter == 10)
  {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, HIGH);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, HIGH);
 
  }
 else {
   digitalWrite(ledPin, LOW);
   digitalWrite(green, LOW);
   digitalWrite(blue, LOW);
   digitalWrite(yellow, LOW);
  }
 
}