Monday, October 8, 2018

Arduino Seven Segment Display Interface

Today, we will see how we can use a common cathode seven segment display with an Arduino UNO.


The Circuit - 

The Code - 

int top = 8;
int mid = 6;
int bot = 4;
int dot = 2;
int top_left = 7;
int bot_left = 5;
int top_right = 9;
int bot_right = 3;

void setup(){
  pinMode(top, OUTPUT);
  pinMode(mid, OUTPUT);
  pinMode(bot, OUTPUT);
  pinMode(dot, OUTPUT);
  pinMode(top_left, OUTPUT);
  pinMode(bot_left, OUTPUT);
  pinMode(top_right, OUTPUT);
  pinMode(bot_right, OUTPUT);
}

void loop(){
  zero();
  delay(1000);
  blank();
  delay(1000);
  
  one();
  delay(1000);
  blank();
  delay(1000);
  
  two();
  delay(1000);
  blank();
  delay(1000);
  
  three();
  delay(1000);
  blank();
  delay(1000);
  
  four();
  delay(1000);
  blank();
  delay(1000);
  
  five();
  delay(1000);
  blank();
  delay(1000);

  six();
  delay(1000);
  blank();
  delay(1000);

  seven();
  delay(1000);
  blank();
  delay(1000);

  eight();
  delay(1000);
  blank();
  delay(1000);

  nine();
  delay(1000);
  blank();
  delay(1000);
}

void blank(){
  digitalWrite(top, LOW);
  digitalWrite(mid, LOW);
  digitalWrite(bot, LOW);
  digitalWrite(dot, LOW);
  digitalWrite(top_left, LOW);
  digitalWrite(bot_left, LOW);
  digitalWrite(top_right, LOW);
  digitalWrite(bot_right, LOW);
}

void zero(){
  digitalWrite(top, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_left, HIGH);
  digitalWrite(bot_left, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
}

void one(){
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
  digitalWrite(dot, HIGH);
}

void two(){
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_left, HIGH);
}

void three(){
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
}

void four(){
  digitalWrite(top_left, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(dot, HIGH);
}

void five(){
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_left, HIGH);
  digitalWrite(bot_right, HIGH);
}

void six(){
  digitalWrite(dot, HIGH);
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(top_left, HIGH);
  digitalWrite(bot_left, HIGH);
  digitalWrite(bot_right, HIGH);
}

void seven(){
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
  digitalWrite(top, HIGH);
  digitalWrite(dot, HIGH);
}

void eight(){
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_left, HIGH);
  digitalWrite(bot_left, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
}

void nine(){
  digitalWrite(top, HIGH);
  digitalWrite(mid, HIGH);
  digitalWrite(bot, HIGH);
  digitalWrite(dot, HIGH);
  digitalWrite(top_left, HIGH);
  digitalWrite(top_right, HIGH);
  digitalWrite(bot_right, HIGH);
}

The Video - 


Sunday, October 7, 2018

Arduino 16 X 2 Character LCD Display Interface

Today, we will see how we can use a 16X2 character LCD display with Arduino. Here is a link to the site if you want to buy one -

Character LCD Display - Amazon.in


The Circuit - 



The Program - 

#include <LiquidCrystal.h>

// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello world!");
}

void loop() {
}

Here Is A Video - 


Using A Servo Motor Using Arduino

Today we will see, how we can use a Servo Motor with Arduino UNO. We will be using a TowerPro 9g Servo Motor. Here is a link if you want to buy one -

Tower Pro 9g Servo Motor - Amazon.in

The Circuit - 


The Program - 

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(6);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
}

Here Is A Video -