Monday, March 30, 2020

Arduino Controller using smart phone


Circuit Diagram:



Arduino Source Code

const int redLed=12;
const int greenLed=11;
int state = 0;
//String s;
void setup() {
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 digitalWrite(redLed, LOW);
 digitalWrite(greenLed, LOW);
 Serial.begin(9600); // Default communication rate of the Bluetooth module
}
void loop() {
  
 if(Serial.available() > 0){ // Checks whether data is comming from the serial port
 state = Serial.read(); // Reads the data from the serial port
 if (state==0)
   digitalWrite(redLed, LOW);
 else if (state==1)
   digitalWrite(redLed, HIGH);
 if (state==2)
   digitalWrite(greenLed, LOW);
 else if (state==3)
   digitalWrite(greenLed, HIGH); 
 Serial.println(state); // Send back, to the phone, the String "LED: ON"

 }
}

Download Smartphone App


Wednesday, March 25, 2020

Octal encoder using Arduino and 7 segment display

Octal Encoder using Arduino and 7 segment display


Circuit diagram for Octal Encoder

















Source Code for Octal Encoder

const int ledPin=13;
const int ledPin2=12; 
const int ledPin3=8;
const int buttonPin=2;
const int buttonPin2=3;
const int buttonPin3=7;
boolean lastButton=LOW;
boolean currentButton=LOW;
boolean ledOn=false;
boolean lastButton2=LOW;
boolean currentButton2=LOW;
boolean ledOn2=false;
boolean lastButton3=LOW;
boolean currentButton3=LOW;
boolean ledOn3=false;
int b3=0,b2=0,b1=0;
void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(buttonPin3, INPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(14, OUTPUT);
  //digitalWrite(14 , HIGH);
  Serial.begin(9600);
}
boolean debounce(boolean last,int bp)
{
  boolean current=digitalRead(bp);
   if (last!=current)
  {
    current=digitalRead(bp);
  }
  return current;
  
}
void switchOffLED()
{
      digitalWrite(5 , false);//a
      digitalWrite(4 , false);//b     
      digitalWrite(14 , false);//c 
      digitalWrite(6 , false); //d
      digitalWrite(9 , false); //e
      digitalWrite(10 , false); //f 
      digitalWrite(11 , false);//g
}
void loop() 
{
  
  //Code for the first button from right to left
  /*int bs=digitalRead(buttonPin);
  Serial.println(bs);*/
  //b1=b2=b3=0;
  //b1=1;
  currentButton=debounce(lastButton,buttonPin);
  if (lastButton==LOW && currentButton==HIGH)
  {
      ledOn=!ledOn;     
     // Serial.println(ledOn);
      //digitalWrite(ledPin, ledOn);
     //digitalWrite(4 , ledOn);   
     // digitalWrite(2 , ledOn);
     if (b1==0)
       b1=1;  
      else
      b1=0;
    }
    
    
  
  lastButton=currentButton;
  digitalWrite(ledPin, ledOn);
  //Code for the second button from right to left
  currentButton2=debounce(lastButton2,buttonPin2);
  if (lastButton2==LOW && currentButton2==HIGH)
  {
    ledOn2=!ledOn2;
    if (b2==0)
      b2=1;
     else
       b2=0;
  }
  
  lastButton2=currentButton2;
  digitalWrite(ledPin2, ledOn2);
  //Code for the third button from right to left
  currentButton3=debounce(lastButton3,buttonPin3);
  if (lastButton3==LOW && currentButton3==HIGH)
  {
    ledOn3=!ledOn3;
    if(b3==0)
    b3=1;
    else
    b3=0;
  }
  
  lastButton3=currentButton3;
  digitalWrite(ledPin3, ledOn3);
  
  if(b3==0 && b2==0 && b1==0)  //0 Output
  {
      switchOffLED();
      digitalWrite(5 , true);
      digitalWrite(4 , true);     
      digitalWrite(14 , true); 
      digitalWrite(6 , true); 
      digitalWrite(9 , true); 
      digitalWrite(10 , true); 
  }
  else if(b3==0 && b2==0 && b1==1)  //1 Output
  {
      switchOffLED();
      digitalWrite(4 , true);     
      digitalWrite(14 , true); 
   }
   
   
   if(b3==0 && b2==1 && b1==0)   //2 Output
  {
      switchOffLED();
      digitalWrite(5, true);     
      digitalWrite(4 , true); 
      digitalWrite(11 , true);     
      digitalWrite(9 , true); 
      digitalWrite(6 , true);     
     
   }
   if (b3==0 && b2==1 && b1==1)
   {
     switchOffLED();
     digitalWrite(5, true);  
     digitalWrite(4, true);  
     digitalWrite(14, true);  
     digitalWrite(6, true);  
     digitalWrite(11, true);  
   }
   if (b3==1 && b2==0 && b1==0)
   {
      switchOffLED();
     digitalWrite(4, true);  
     digitalWrite(14, true);  
     digitalWrite(10, true);  
     digitalWrite(11, true);  
   }
   if (b3==1 && b2==0 && b1==1)
   {
      switchOffLED();
     digitalWrite(5, true);  
     digitalWrite(14, true);  
     digitalWrite(6, true);  
     digitalWrite(10, true);  
     digitalWrite(11, true);  
   }
   if (b3==1 && b2==1 && b1==0)
   {
      switchOffLED();
     digitalWrite(14, true);  
     digitalWrite(6, true);  
     digitalWrite(9, true);  
     digitalWrite(10, true);  
     digitalWrite(11, true);  
   }
   if (b3==1 && b2==1 && b1==1)
   {
      switchOffLED();
     digitalWrite(5, true);  
     digitalWrite(4, true);  
     digitalWrite(14, true);  
   }
}

3 Push Button(Toggle) Control using Arduino

Circuit for using 3 Push buttons controls















Source Code for controlling the push Buttons

const int ledPin=13;
const int ledPin2=12; 
const int ledPin3=8;
const int buttonPin=2;
const int buttonPin2=3;
const int buttonPin3=7;
boolean lastButton=LOW;
boolean currentButton=LOW;
boolean ledOn=false;
boolean lastButton2=LOW;
boolean currentButton2=LOW;
boolean ledOn2=false;
boolean lastButton3=LOW;
boolean currentButton3=LOW;
boolean ledOn3=false;

void setup() 
{
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(buttonPin3, INPUT);
  Serial.begin(9600);
}
boolean debounce(boolean last,int bp)
{
  boolean current=digitalRead(bp);
   if (last!=current)
  {
    current=digitalRead(bp);
  }
  return current;
}
void loop() 
{
  currentButton=debounce(lastButton,buttonPin);
  if (lastButton==LOW && currentButton==HIGH)
  {
      ledOn=!ledOn;     
  }
  lastButton=currentButton;
  digitalWrite(ledPin, ledOn);
  currentButton2=debounce(lastButton2,buttonPin2);
  if (lastButton2==LOW && currentButton2==HIGH)
  {
    ledOn2=!ledOn2;
  }
  lastButton2=currentButton2;
  digitalWrite(ledPin2, ledOn2);
  currentButton3=debounce(lastButton3,buttonPin3);
  if (lastButton3==LOW && currentButton3==HIGH)
  {
    ledOn3=!ledOn3;
  }
  lastButton3=currentButton3;
  digitalWrite(ledPin3, ledOn3);
}

  Source Code for :   Displaying all possible fangs of a Vampire Number in Java import java.util.*; class Number {     public static void ma...