Search the Blog

Arduino Project

Arduino UNO Board Projects Code

In this post i will show the code of various school based and college and engineering and techfast based code and project with Youtube Video.
Most of the example code  are tested and run on arduino

Introduction of Arduino:-

 Arduino is an open-source prototyping platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online. You can tell your board what to do by sending a set of instructions to the micro controller on the board. It is like the brain of a project.

PIN Diagram of Arduino Board-
PIN Diagram of Arduino Board





Project 1:-



RGB Colour Intensity Reading of Any Object

Sensor Name:- TCS3200

Tis post have the code for reading the color intensity RGB color of any object.

To demonstrate this i use a color sensor and ardunio uno board

Arduino code for reading the color of any object.

Pin Details:-
   Pin 4 Ardunio uno board is connect to RED line of Sensor 
   Pin 5 Ardunio uno board is connect to GREEN line of Sensor
   Pin 6 Ardunio uno board is connect to BLUE line of Sensor




#define Red 4
#define Green 5
#define Blue 6
char inputs [20];
char oldInputs [20];

void setup()
{
  Serial.begin(9600);
}
void getInputs()
{
sprintf(inputs,"SS:%03X:%03X:03X",analogRead(Red),analogRead(Green),analogRead(Blue));
}


TCS3200 Sensor


void loop()
{
getInputs();
if(strcmp(inputs,oldInputs)!=0)
      {
      strcpy(oldInputs,inputs);
      Serial.println(inputs);
      }
      if(Serial.available())
      {
      int ind=0;
      char buff[5];
      while(Serial.available())
      {
        unsigned char c=Serial.read();
        buff[ind]=c;
        if(ind++>4)
        break;
        }
      }
}



See Also-





Project 2:-



Ultrasonic RADAR Demo Project


Ultrasonic Sensor:


An ultrasonic sensor is an instrument that measures the distance to an object using ultrasonic sound waves.
An ultrasonic sensor uses a transducer to send and receive ultrasonic pulses that relay back information about an object’s proximity.  
High-frequency sound waves reflect from boundaries to produce distinct echo patterns
Arduino code ultrasonic sensor with processing code



Processing Application :

Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping.



#define echoPin 7

#define trigPin 8
#define LEDPin 13
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance

void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
 pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)
}

void loop() {
/* The following trigPin/echoPin cycle is used to determine the
 distance of the nearest object by bouncing soundwaves off of it. */
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);

 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.
 distance = duration/58.2;

 if (distance >= maximumRange || distance <= minimumRange){
 /* Send a negative number to computer and Turn LED ON
 to indicate "out of range" */
 Serial.println("-1");
 digitalWrite(LEDPin, HIGH);
 }
 else {
 /* Send the distance to the computer using Serial protocol, and
 turn LED OFF to indicate successful reading. */
 Serial.println(distance);
 digitalWrite(LEDPin, LOW);
 }

 //Delay 50ms before next reading.
 delay(50);
}

Arduino UNO Board

Please See- In this Project i use 5 Ultrsonic Sensor



Processing code Application Code :-

import processing.serial.*;


int numOfShapes = 60; // Number of squares to display on screen
int shapeSpeed = 2; // Speed at which the shapes move to new position
 // 2 = Fastest, Larger numbers are slower

//Global Variables
Square[] mySquares = new Square[numOfShapes];
int shapeSize, distance;
String comPortString;
Serial myPort;

/* -----------------------Setup ---------------------------*/
void setup(){
 size(displayWidth,displayHeight); //Use entire screen size.
 smooth(); // draws all shapes with smooth edges.

 /* Calculate the size of the squares and initialise the Squares array */
 shapeSize = (width/numOfShapes);
 for(int i = 0; i<numOfShapes; i++){
 mySquares[i]=new Square(int(shapeSize*i),height-40);
 }

 /*Open the serial port for communication with the Arduino
 Make sure the COM port is correct - I am using COM port 8 */
 myPort = new Serial(this, "COM8", 9600);
 myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
}

/* ------------------------Draw -----------------------------*/
void draw(){
 background(0); //Make the background BLACK
 delay(50); //Delay used to refresh screen
 drawSquares(); //Draw the pattern of squares
}


/* ---------------------serialEvent ---------------------------*/
void serialEvent(Serial cPort){
 comPortString = cPort.readStringUntil('\n');
 if(comPortString != null) {
 comPortString=trim(comPortString);

 /* Use the distance received by the Arduino to modify the y position
 of the first square (others will follow). Should match the
 code settings on the Arduino. In this case 200 is the maximum
 distance expected. The distance is then mapped to a value
 between 1 and the height of your screen */
 distance = int(map(Integer.parseInt(comPortString),1,200,1,height));
 if(distance<0){
 /*If computer receives a negative number (-1), then the
 sensor is reporting an "out of range" error. Convert all
 of these to a distance of 0. */
 distance = 0;
 }
 }
}
Arduino code ultrasonic sensor with processing code




/* ---------------------drawSquares ---------------------------*/
void drawSquares(){
 int oldY, newY, targetY, redVal, blueVal;

 /* Set the Y position of the 1st square based on
 sensor value received */
 mySquares[0].setY((height-shapeSize)-distance);

 /* Update the position and colour of each of the squares */
 for(int i = numOfShapes-1; i>0; i--){
 /* Use the previous square's position as a target */
 targetY=mySquares[i-1].getY();
 oldY=mySquares[i].getY();

 if(abs(oldY-targetY)<2){
 newY=targetY; //This helps to line them up
 }else{
 //calculate the new position of the square
 newY=oldY-((oldY-targetY)/shapeSpeed);
 }
 //Set the new position of the square
 mySquares[i].setY(newY);

 /*Calculate the colour of the square based on its
 position on the screen */
 blueVal = int(map(newY,0,height,0,255));
 redVal = 255-blueVal;
 fill(redVal,0,blueVal);

 /* Draw the square on the screen */
 rect(mySquares[i].getX(), mySquares[i].getY(),shapeSize,shapeSize);
 }
}

/* ---------------------sketchFullScreen---------------------------*/
// This puts processing into Full Screen Mode
boolean sketchFullScreen() {
 return true;
}

/* ---------------------CLASS: Square ---------------------------*/
class Square{
 int xPosition, yPosition;

 Square(int xPos, int yPos){
 xPosition = xPos;
 yPosition = yPos;
 }

 int getX(){
 return xPosition;
 }

 int getY(){
 return yPosition;
 }

 void setY(int yPos){
 yPosition = yPos;
 }
}

See Also:-





Project 3:- Arduino Uno board code for Road crossing system

This project is used to control the road accident when a driver jump the red light with high speed then ultrasonic sensor will identify the object and a horn will start blowing.


>>Project PIN
     Following pin of arduino uno board is used in this project
#define echoPin 7
#define trigPin 8
#define LEDPin 13
int relay1=2;
int relay2=3;
int relay3=4;
int relay4=5;
int maximumRange = 200;
int minimumRange = 0;
long duration, distance;

>> Continuous PIN Setup 
void setup() {
 Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin,  INPUT);
    pinMode(relay1,  OUTPUT);
    pinMode(relay2,  OUTPUT);
    pinMode(relay3,  OUTPUT);
    pinMode(relay4, OUTPUT);
}
>> 
void loop() {

 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);

 digitalWrite(trigPin, HIGH);
 delayMicroseconds(10);

 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);


 distance = duration/58.2;

 if (distance >25)

 {
   digitalWrite(relay1,HIGH);
   delay(110);
   digitalWrite(relay1,LOW);
   digitalWrite(relay2,HIGH);
   delay(110);

   digitalWrite(relay2,LOW);
   digitalWrite(relay3,HIGH);
   delay(110);

   digitalWrite(relay3,LOW);
   digitalWrite(relay4,HIGH);
   delay(110);

   digitalWrite(relay4,LOW);

   delay(110);

 }

 delay(110);
}





Project 4:-Arduino uno board code for  gas leakage cylender

Arduino uno board code for  gas leakage cylender

#include <LiquidCrystal.h>
LiquidCrystal lcd(3, 2, 4, 5, 6, 7);

#define lpg_sensor 18
#define buzzer 13

void setup()
{
  pinMode(lpg_sensor, INPUT);
  pinMode(buzzer, OUTPUT);
  lcd.begin(16, 2);
  lcd.print("LPG Gas Detector");
  lcd.setCursor(0,1);
  lcd.print("Circuit Digest");
  delay(2000);
}

void loop()
{
  if(digitalRead(lpg_sensor))
  {
    digitalWrite(buzzer, HIGH);
    lcd.clear();
    lcd.print("LPG Gas Leakage");
    lcd.setCursor(0, 1);
    lcd.print("     Alert     ");
    delay(400);
    digitalWrite(buzzer, LOW);
    delay(500);
  }

  else
  {
    digitalWrite(buzzer, LOW);
    lcd.clear();
    lcd.print("  No LPG Gas ");
    lcd.setCursor(0,1);
    lcd.print("   Leakage   ");
    delay(1000);
  }
}





Project 5:-PIC and Place ROBOT




This project is developed and designed in arduino and mobile key operation frequency based.
This project is dummy model of digital crane systems which can be operated remotely in any conditions.

#define m11 1
#define m12 0
#define m21 7
#define m22 6
#define m31 3
#define m32 2
#define m41 4
#define m42 5

#define D0 19
#define D1 18
#define D2 17
#define D3 16

void forward()
{
   digitalWrite(m11, LOW);
   digitalWrite(m12, HIGH);
   digitalWrite(m21, LOW);
   digitalWrite(m22, HIGH);
   digitalWrite(m31, LOW);
   digitalWrite(m32, HIGH);
   digitalWrite(m41, LOW);
   digitalWrite(m42, HIGH);
}


Pic and Place ROBOT

void backward()
{
   digitalWrite(m11, HIGH);
   digitalWrite(m12, LOW);
   digitalWrite(m21, HIGH);
   digitalWrite(m22, LOW);
   digitalWrite(m31, HIGH);
   digitalWrite(m32, LOW);
   digitalWrite(m41, HIGH);
   digitalWrite(m42, LOW);
}

void left()
{
   digitalWrite(m11, LOW);
   digitalWrite(m12, HIGH);
   digitalWrite(m21, HIGH);
   digitalWrite(m22, HIGH);
   digitalWrite(m31, LOW);
   digitalWrite(m32, HIGH);
   digitalWrite(m41, HIGH);
   digitalWrite(m42, HIGH);
}

void right()
{
   digitalWrite(m11, HIGH);
   digitalWrite(m12, HIGH);
   digitalWrite(m21, LOW);
   digitalWrite(m22, HIGH);
    digitalWrite(m31, HIGH);
   digitalWrite(m32, HIGH);
   digitalWrite(m41, LOW);
   digitalWrite(m42, HIGH);
}

void Stop()
{
   digitalWrite(m11, HIGH);
   digitalWrite(m12, HIGH);
   digitalWrite(m21, HIGH);
   digitalWrite(m22, HIGH);
   digitalWrite(m31, HIGH);
   digitalWrite(m32, HIGH);
   digitalWrite(m41, HIGH);
   digitalWrite(m42, HIGH);
}

void setup()
{
  pinMode(D0, INPUT);
  pinMode(D1, INPUT);
  pinMode(D2, INPUT);
  pinMode(D3, INPUT);

  pinMode(m11, OUTPUT);
  pinMode(m12, OUTPUT);
  pinMode(m21, OUTPUT);
  pinMode(m22, OUTPUT);
  pinMode(m31, OUTPUT);
  pinMode(m32, OUTPUT);
  pinMode(m41, OUTPUT);
  pinMode(m42, OUTPUT);
}

void loop()
{

  int temp1=digitalRead(D0);
  int temp2=digitalRead(D1);
  int temp3=digitalRead(D2);
  int temp4=digitalRead(D3);

  if(temp1==1 && temp2==0 && temp3==0 && temp4==0)
  forward();

  else if(temp1==0 && temp2==1 && temp3==0 && temp4==0)
  left();

  else if(temp1==1 && temp2==1 && temp3==0 && temp4==0)
  right();

  else if(temp1==0 && temp2==0 && temp3==1 && temp4==0)
  backward();

   else if(temp1==1 && temp2==0 && temp3==1 && temp4==0)
  Stop();
}




No comments:

Post a Comment

Translate