Search the Blog

Showing posts with label Microcontroller. Show all posts
Showing posts with label Microcontroller. Show all posts

Thursday, August 15, 2019

Arduino code for reading the color of any object.

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 demonstarte this i use a color sensor and ardunio uno board

Arduino code for reading the color of any object.

All Project of Arduino UNO Board

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

Arduino Uno Board Pin Diagram


#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-

Check Also This post:-SQL BETWEEN OPERATOR Programming Logic and Code with Syntax


Arduino uno board Code of Pic and Place ROBOT

Pic And Place ROBOT is work like Automatic Creane System







#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);
}

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();
}

Arduino uno board complete code of ROBOT

Arduino Uno board Code for maze robot for path ROBOT

Arduino uno board complete code of ROBOT


#include<Servo.h>


Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

int amsr=9;
int amsl=7;
int amskr=10;
int amskl=8;




int aamsl;


void setup()
{


  servo2.attach(amsr);
  servo1.attach(amskr);
  servo3.attach(amsl);
  servo4.attach(amskl);

}


void loop()
{

 {
  for(aamsl=150;aamsl>30;aamsl--)
  {
    int ab=180-aamsl;
    servo2.write(aamsl);
    servo3.write(ab);
  delay(3);
  }
  delay(1000);
  for(int i=1;i<=3;i++)
  {
  for(aamsl=150;aamsl>60;aamsl--)
  {
    int fg=aamsl-50;
    servo1.write(aamsl);
    servo4.write(fg);
  delay(20);
  }
  delay(1000);
  for(aamsl=60;aamsl<150;aamsl++)
  {
    int fd=aamsl+50;
    servo1.write(aamsl);
    servo4.write(fd);
  delay(20);
  }
  }
  delay(1000);
  for(aamsl=30;aamsl<150;aamsl++)
  {
    int cd=180-aamsl;
    servo2.write(aamsl);
    servo3.write(cd);
  delay(20);
  }
  delay(1000);

 }
}


JAVA Triangle * Pattern Program Logic one Programming Logic and Code with Syntax

Arduino Uno board with servo test

Arduino Uno board with servo test with actual and tested example

Arduino Uno board with servo test with actual and tested example Varified

#include <Servo.h>

Servo myservo3;

Servo myservo5;

Servo myservo6;

int potpin = 0;
int potpin2 = 1;

int potpin3 = 2;

int val = 0;
int val2 = 0;

int val3 = 0;

void setup()
{

myservo3.attach(9);
myservo5.attach(10);

myservo6.attach(11);

}

void loop()
{

val = analogRead(potpin);
val = map(val, 3, 1023, 0, 176);

myservo3.write(val);

delay(25);

val2 = analogRead(potpin2);
val2 = map(val2, 3, 1023, 0, 176);

myservo5.write(val2);

delay(25);

val3 = analogRead(potpin3);
val3 = map(val3, 3, 1023, 0, 175);

myservo6.write(val3);

delay(25);

}


JAVA Sequence Pattern Program Programming Logic and Code with Syntax

Arduino uno board Code for Ultrasonic sensor with relay

Arduino UNO Board Code For Ultrsonic Sensor with Realy and LED Pin for High and LOW Demo

Arduino uno board Code for Ultrasonic sensor with relay and Demo Example

#define echoPin 7
#define trigPin 8
#define LEDPin 12
int relay1=2;
int relay2=3;
int relay3=4;
int relay4=5;
int i=1,s;
int a=10,b=10,c=10,d=10;
int maximumRange = 200;
int minimumRange = 0;
long duration, distance;

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;
switch(i)
{
  case 1:
  {
    while(a<1000)
      {
        digitalWrite(relay4,LOW);
         digitalWrite(relay1,HIGH);
       
         while(distance<5)
         {
           digitalWrite(relay1,LOW);
           delay(1000);
           s=2;
           a=1000;
             break;
         }
         delay(100);
         a=a+100;
      }
      s=2;
      a=100;
      break;
  }
      case 2:
   { 
      while(b<1000)
      {
        digitalWrite(relay1,LOW);
         digitalWrite(relay2,HIGH);
         delay(100);
         while(distance<5)
         {
           digitalWrite(relay2,LOW);
           delay(1000);
           s=3;
           b=1000;
             break;
         }
        delay(100);
         b=b+100;
      }
      s=3;
      b=100;
      break;
   
   }
   case 3:
   { 
      while(c<1000)
      {
         digitalWrite(relay2,LOW);
         digitalWrite(relay3,HIGH);
       
         while(distance<5)
         {
           digitalWrite(relay3,LOW);
           delay(1000);
           s=4;
           c=1000;
             break;
         }
         delay(100);
         c=c+100;
      }
      s=4;
      c=100;
      break;
   }
   case 4:
 {   
      while(d<1000)
      {
        digitalWrite(relay3,LOW);
         digitalWrite(relay4,HIGH);
       
         while(distance<5)
         {
           digitalWrite(relay4,LOW);
           delay(1000);
           s=1;
           d=1000;
             break;
         }
         delay(100);
         d=d+100;
      }
      s=1;
      d=100;
      break;
 }
}
delay(1000);
i=s;
}


SQL Query for Purchase Order details Programming Logic and Code with Syntax





Wednesday, August 14, 2019

Arduino uno board of servo motor

Servo Motor Rotation For Perticular length

Servo Motor Rotation For Perticular length and Stop

#include <Servo.h>

Servo myservo;


int pos = 0; 

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);
}

void loop()
{
  int sensorValue = analogRead(A0);

Serial.println(sensorValue);
  if(sensorValue>850)
  {
    myservo.write(0); 
      delay(5000);                               
  }
 else
 {
  myservo.write(90);
           
}
}


Arduino Uno board code for moving bridge with for rail road and river

Arduino Uno board code for moving bridge fro railway , Road, and River Project. This kind of project is generally used in all over the world and live running. So this is good project for Science and Engineeing Students, For Submitting the educational project.





#include <Servo.h>
Servo myservo;


int val,val2,val3;
int m; 

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);
}

void loop()
{sawan:
  val = analogRead(A0);
  val2 = analogRead(A1);
  val3 = analogRead(A2);
 
  Serial.println(val);
   Serial.println(val2);
    Serial.println(val3);
    if((val>val2)&&(val>val3))
    {
      m=val;
      }
      else
      {

        if(val2>val3)
        m=val2;
        else
        m=val3;
        }
  int c=m/50;
  Serial.println(c);
  if(c>10&&c<12)
  {
    goto sawan;
    }
  else
  {
  switch(c)
  {
    case 1:
myservo.write(180);
delay(2000);
break;
    case 2:
myservo.write(180);
delay(2000);
break;

     case 3:
myservo.write(180);
delay(2000);
break;
    case 4:
myservo.write(180);
delay(2000);
break;
    case 5:
myservo.write(180);
delay(2000);
break;
   case 6:
myservo.write(180);
delay(2000);
break;
   case 7:
myservo.write(180);
delay(2000);
break;
   case 8:
myservo.write(180);
delay(2000);
break;
   case 9:
myservo.write(180);
delay(2000);
break;
   case 10:
myservo.write(90);
delay(2000);
break;
   case 11:
myservo.write(90);
delay(2000);
break;
   case 12:
myservo.write(90);
delay(2000);
break;
   case 13:
myservo.write(180);
delay(2000);
break;
   case 14:
myservo.write(180);
delay(2000);
break;
   case 15:
myservo.write(180);
delay(2000);
break;
   case 16:
myservo.write(180);
delay(2000);
break;
   case 17:
myservo.write(180);
delay(2000);
break;
   case 18:
myservo.write(180);
delay(2000);
break;
   case 19:
myservo.write(180);
delay(2000);
break;
   case 20:
myservo.write(180);
delay(2000);
break;
default :
myservo.write(90);
}
  }
}


Second Program For the Same Problem

#define motor 9
#define e1 7
#define e2 6
void setup()
{
  pinMode(8,INPUT);
  Serial.begin(9600);
  pinMode(motor,OUTPUT);
  pinMode(e1,OUTPUT);
  pinMode(e2,OUTPUT);
  }


  void loop()
  {   delay(1000);
    int sensor=digitalRead(8);
 
    Serial.println(sensor);
    if(sensor==1)
    {
          analogWrite(motor,1000);
          analogWrite(e1,0);
          analogWrite(e2,0);
    }
     else
       {
           for(int i=1;i<=10;i++)
               {
                   analogWrite(motor,1000);
                   analogWrite(e1,0);
                   analogWrite(e2,255);
                   delay(100);
              }
                   analogWrite(motor,0);
                   analogWrite(e1,0);
                   analogWrite(e2,0);
 
                   sawan();
       }
   
   
       delay(1000);
   
  }
void train()
    {

           for(int i=1;i<=17;i++)
               {
                   analogWrite(motor,1000);
                   analogWrite(e1,0);
                   analogWrite(e2,255);
                   delay(100);
              }
           analogWrite(motor,0);
           analogWrite(e1,0);
                   analogWrite(e2,0);
             vivek();
      }

void vivek()

{
  delay(10000);
         for(int i=1;i<=27;i++)
               {
                   analogWrite(motor,1000);
                   analogWrite(e1,255);
                   analogWrite(e2,0);
                   delay(100);
              }
           analogWrite(motor,0);
           analogWrite(e1,0);
                   analogWrite(e2,0);
               

  }
   void sawan()
         {
          int s=100;
          while(s<3000)
          {
            delay(100);
          int sensor=digitalRead(8);
          Serial.println(sensor);
          if(sensor==0)
          {
          train();
          }
          else
          {
          s=s+100;
          }
       
          delay(100);
          }
          delay(7000);
          for(int i=1;i<=10;i++)
               {
                   analogWrite(motor,1000);
                   analogWrite(e1,255);
                   analogWrite(e2,0);
                   delay(100);
              }
                   analogWrite(motor,0);
                   analogWrite(e1,0);
                   analogWrite(e2,0);
                   loop();
        }



Arduino Uno Code for E- Dustbin

E - Dustibin is the future of world, So every developing country is now finding the ways of collecting the garbage according to their category, like plastic garbage , metallic garbage, or biodegardable and not degradable items saparately.
So to have this thing in mind we have develop a science project of moving and auto open close and E- dustbin. Which will move at predefine path and collect the garbage and also automatically opens when user comes in near to that. 


#include <Servo.h>

Servo myservo;
int arr[9];

int punnu; 

void setup()
{
  Serial.begin(9600);
  myservo.attach(9);
  pinMode(8,INPUT);
   pinMode(10,INPUT);
    pinMode(11,INPUT);
}
int sawan()
{
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A1);
int sensorValue3 = analogRead(A2);
return sensorValue1+sensorValue2+sensorValue3/6;

  }
void loop()
{
  int sum=0;

  for(int i=0;i<9;i++)
    {
         arr[i]=sawan();
    }
     for(int i=0;i<9;i++)
      {
         sum=sum+arr[i];
         sum=sum/9;
         punnu=sum;
    }
 chauhan: 
  int sensorValue1 = analogRead(A0);
  int sensorValue2 = analogRead(A1);
  int sensorValue3 = analogRead(A2);
    if((sensorValue1>punnu)||(sensorValue2>punnu)||(sensorValue3>punnu))
    {
      for (int pos = 0; pos <= 180; pos += 1)
      {
        myservo.write(180);           
        delay(500);                     
      }
    }
  else
   {
     for (int pos = 180; pos >= 0; pos -= 1)
     {
       myservo.write(pos);           
      delay(5000);                   
     }
   }
goto chauhan;
}

Translate