Search the Blog

Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. 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 code ultrasonic sensor with processing code


Ultrasonic RADAR Demo Project

Ultrasonic Sensor:


An ultrasonic sensor is an instrument that measure 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 and return in varoius direction
Arduino code ultrasonic sensor with processing code


Processing Application :

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

Please Visit this for more Information
#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 via some mathmatical formuls

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 the 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 and time.
 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;
 }
}

More than 20 aurduino Project

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





Arduino Code for ultrsonic RADAR

Micocontroller,  ROBOTICS,  Arduino Uno Board Project Example fro School and Science exibiation and College Projects.

Micocontroller,  ROBOTICS,  Arduino Uno Board Project Example fro School and Science exibiation.

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

void setup() {
 Serial.begin (9600);
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin,  OUTPUT);
  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(5000);
   digitalWrite(relay1,LOW);
   digitalWrite(relay2,HIGH);
   delay(5000);
 
   digitalWrite(relay2,LOW);
   digitalWrite(relay3,HIGH);
   delay(5000);
 
   digitalWrite(relay3,LOW);
   digitalWrite(relay4,HIGH);
   delay(5000);
 
   digitalWrite(relay4,LOW);

   delay(5000);
 
 }

 delay(50);
}


JAVA Sequence Pattern Program with * pattern Programming Logic and Code with Syntax

Wednesday, August 14, 2019

Arduino Code for to read three sensor reading

Arduino Code for reading the sensor data and print and test

void setup()
{
Serial.begin(9600);
}

void loop()
{
  int state = analog Read(A0) ;
  int state2 = analog Read(A1) ;
  int state3 = analog Read(A3) ;
Serial. println ( state ) ;
delay ( 1000);
Serial. println ( state2 ) ;
delay ( 1000 );
Serial. println ( state3 ) ;
delay ( 1000 )  ;
}


JavaScript Object and XML interactively methods




More popular Sites -

Arduino Uno Code for lover robot


Arduino Uno Board Based project pof Lover Robot Code with Pin Digram and Details

Youtube Video for Demo

#include<Servo.h>
#define echoPin1 3
#define trigPin1 4
#define echoPin2 10
#define trigPin2 11
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
Servo servo5;
int amsl=5;
int amsr=6;
int amkl=7;
int amkr=8;
int head=9;
int aamsl;
int aamsr;
int aamkl;
int aamkr;
int ahead;
int Maximum=200;
int Minimum=0;
long duration1,distance1,duration2,distance2;

void setup()
{
  Serial.begin(9600);
  servo1.attach(amsl);
  servo2.attach(amsr);
  servo3.attach(amkl);
  servo4.attach(amkr);
  servo5.attach(head);
pinMode(trigPin1,OUTPUT);
pinMode(echoPin1,INPUT);
pinMode(trigPin2,OUTPUT);
pinMode(echoPin2,INPUT);
}


void loop()
{
  digitalWrite(trigPin1,LOW);
  digitalWrite(trigPin2,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin1,HIGH);
    digitalWrite(trigPin2,HIGH);
    delayMicroseconds(10);
      digitalWrite(trigPin1,LOW);
        digitalWrite(trigPin2,LOW);
        duration1=pulseIn(echoPin1,HIGH);
     
        duration2=pulseIn(echoPin2,HIGH);
        distance1=duration1/58.2;
        distance2=duration2/58.2;
 if((duration1<40)&&(duration2<40))
 {
  for(aamsl=0;aamsl<90;aamsl++)
  {
    servo1.write(aamsl);
    servo2.write(aamsl);
  delay(15);
  }

  for(aamsl=0;aamsl<90;aamsl++)
  {
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }
  delay(10000);
  for(aamsl=90;aamsl>0;aamsl--)
  {
 
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }
  for(aamsl=90;aamsl>0;aamsl--)
  {
 
    servo3.write(aamsl);
    servo4.write(aamsl);
  delay(15);
  }

 }

}

Arduino uno code for Automatic ZCB operated by mobile Key pad

Arduino UNO Based Project Complete Code or Mobile Oprated JCB Demo. In this Project all the JCB can be operated directly via the Mobile Keypads and Or via a call and Key pad in the same way currently automatic call system of various serivce provider used to encode or pressed key frequecy.




int mot1=3;
int mot2=4;
int mot3=5;
int mot4=6;
int mot5=7;
int mot6=8;

void setup()
{
  Serial.begin(9600);
  pinMode(mot1,OUTPUT);
  pinMode(mot2,OUTPUT);
  pinMode(mot3,OUTPUT);
  pinMode(mot4,OUTPUT);
  pinMode(mot5,OUTPUT);
  pinMode(mot6,OUTPUT);
  }
  void loop()
  {
    digitalWrite(mot2,LOW);
    digitalWrite(mot3,LOW);
    digitalWrite(mot6,LOW);
    digitalWrite(mot1,HIGH);
    digitalWrite(mot4,HIGH);
    digitalWrite(mot5,HIGH);
    delay(1000);
    digitalWrite(mot1,LOW);
    digitalWrite(mot4,LOW);
    digitalWrite(mot5,LOW);
    digitalWrite(mot2,HIGH);
    digitalWrite(mot3,HIGH);
    digitalWrite(mot6,HIGH);
    delay(1000);
    }

Translate