Patel Darshil
Published

Arduino Mini Shields Construction

Presented here are the Arduino Mini Shields. These shields are very easy and fun to make, and you can make your own custom shield from this.

BeginnerFull instructions provided2 hours3,698
Arduino Mini Shields Construction

Things used in this project

Hardware components

Resistor 221 ohm
Resistor 221 ohm
×1
LED (generic)
LED (generic)
×2
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 100 ohm
Resistor 100 ohm
×1
SparkFun 7-Segment Serial Display - Red
SparkFun 7-Segment Serial Display - Red
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1
1N4148 – General Purpose Fast Switching
1N4148 – General Purpose Fast Switching
×1
BC 547
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Tactile Switches
×5
LDR
×1
TSOP 1738
×1
IR LED
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

D-Pad Button Sheild

Here one terminal of all 4 Buttons are connected to Ground.
UPPER BUTTON is connected to pin no. 2 of Arduino.
RIGHT BUTTON is connected to pin no. 3 of Arduino.
LEFT BUTTON is connected to pin no. 4 of Arduino.
DOWN BUTTON is connected to pin no. 5 of Arduino.

Relay Shield

Debouncing a button Shield

Seven Segment Display Shield

Connections of Seven Segment Display are as follows:
PIN 1 to PIN 6 of Arduino Uno
PIN 2 to PIN 5
PIN 4 C to PIN 4
PIN 6 to PIN 3
PIN 7 to PIN 2
PIN 9 to PIN 7
PIN 10 PIN 8
PIN 3 to ground through 100Ω resistor.

Light Sensing Shield

IR Communication Shield

Here the positive terminal of the IR LED is connected to pin no. 3 of the Arduino through 100 ohm Resistor. A switch is connected between GND and Vin Pin of the Arduino.
3rd Pin of TSOP is connected to VCC of Arduino.
2nd Pin of TSOP is connected to -ve of Arduino.
1st pin of TSOP is connected to 11 pin of Arduino.

Code

Code For D-Pad Shield

C/C++
#include <SPI.h>
#include <Adb.h>

#define  BUTTON_LEFT  2
#define  BUTTON_UP    3
#define  BUTTON_DOWN  4
#define  BUTTON_RIGHT  5

Connection * connection;

// Bytes for each button state
byte b1, b2, b3, b4;

// Event handler for shell connection; called whenever data sent from Android to Microcontroller
void adbEventHandler(Connection * connection, adb_eventType event, uint16_t length, uint8_t * data)
{
  if (event == ADB_CONNECTION_RECEIVE)
  {
    // Unused in this case
  }
}

void setup()
{
  // Set pins as input
  pinMode(BUTTON_UP, INPUT);
  pinMode(BUTTON_LEFT, INPUT);
  pinMode(BUTTON_DOWN, INPUT);
  pinMode(BUTTON_RIGHT, INPUT);

  // Enable the internal pullups
  digitalWrite(BUTTON_UP, HIGH);
  digitalWrite(BUTTON_LEFT, HIGH);
  digitalWrite(BUTTON_DOWN, HIGH);
  digitalWrite(BUTTON_RIGHT, HIGH);

  // Init serial port for debugging
  Serial.begin(57600);

  // Init the ADB subsystem.  
  ADB::init();

  // Open an ADB stream to the phone's shell. Auto-reconnect. Use port number 4568
  connection = ADB::addConnection("tcp:4567", true, adbEventHandler);  
}

void loop()
{
  byte b;
  byte msg[2];

  b = digitalRead(BUTTON_UP);
  if (b != b1) {
    msg[0] = BUTTON_UP;
    msg[1] = b ? 0 : 1;
    Serial.println(msg[0],DEC);
    connection->write(2, (uint8_t*)&msg);
    b1 = b;
  }

  b = digitalRead(BUTTON_LEFT);
  if (b != b2) {
    msg[0] = BUTTON_LEFT;
    msg[1] = b ? 0 : 1;
    Serial.println(msg[0],DEC);
    connection->write(2, (uint8_t*)&msg);
    b2 = b;
  }

  b = digitalRead(BUTTON_DOWN);
  if (b != b3) {
    msg[0] = BUTTON_DOWN;
    msg[1] = b ? 0 : 1;
    Serial.println(msg[0],DEC);
    connection->write(2, (uint8_t*)&msg);
    b3 = b;
  }

  b = digitalRead(BUTTON_RIGHT);
  if (b != b4) {
    msg[0] = BUTTON_RIGHT;
    msg[1] = b ? 0 : 1;
    Serial.println(msg[0],DEC);
    connection->write(2, (uint8_t*)&msg);
    b4 = b;
  }
  // Poll the ADB subsystem.
  ADB::poll();
}

Code For Light Sensing Shield

C/C++
/*
SparkFun Inventor's Kit 
Example sketch 06

PHOTORESISTOR

  Use a photoresistor (light sensor) to control the brightness
  of a LED.

Hardware connections:

  Photo resistor:

    Connect one side of the photoresistor to 5 Volts (5V).
    Connect the other side of the photoresistor to ANALOG pin 0.
    Connect a 10K resistor between ANALOG pin 0 and GND.

    This creates a voltage divider, with the photoresistor one
    of the two resistors. The output of the voltage divider
    (connected to A0) will vary with the light level.

  LED:

    Connect the positive side (long leg) of the LED to
    digital pin 9. (To vary the brightness, this pin must
    support PWM, which is indicated by "~" or "PWM" on the
    Arduino itself.)

    Connect the negative side of the LED (short leg) to a
    330 Ohm resistor.

    Connect the other side of the resistor to GND.

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit http://learn.sparkfun.com/products/2 for SIK information.
Visit http://www.arduino.cc to learn about the Arduino.

Version 2.0 6/2012 MDG
*/


// As usual, we'll create constants to name the pins we're using.
// This will make it easier to follow the code below.

const int sensorPin = 0;
const int ledPin = 9;

// We'll also set up some global variables for the light level:

int lightLevel, high = 0, low = 1023;


void setup()
{
  // We'll set up the LED pin to be an output.
  // (We don't need to do anything special to use the analog input.)

  pinMode(ledPin, OUTPUT);
}


void loop()
{
  // Just as we've done in the past, we'll use the analogRead()
  // function to measure the voltage coming from the photoresistor
  // resistor pair. This number can range between 0 (0 Volts) and
  // 1023 (5 Volts), but this circuit will have a smaller range
  // between dark and light.

  lightLevel = analogRead(sensorPin);

  // We now want to use this number to control the brightness of
  // the LED. But we have a problem: the analogRead() function
  // returns values between 0 and 1023, and the analogWrite()
  // function wants values from 0 to 255.

  // We can solve this by using two handy functions called map()
  // and constrain(). Map will change one range of values into
  // another range. If we tell map() our "from" range is 0-1023,
  // and our "to" range is 0-255, map() will squeeze the larger
  // range into the smaller. (It can do this for any two ranges.)

  // lightLevel = map(lightLevel, 0, 1023, 0, 255);

  // Because map() could still return numbers outside the "to" 
  // range, (if they're outside the "from" range), we'll also use
  // a function called constrain() that will "clip" numbers into
  // a given range. If the number is above the range, it will reset
  // it to be the highest number in the range. If the number is
  // below the range, it will reset it to the lowest number.
  // If the number is within the range, it will stay the same.

  // lightLevel = constrain(lightLevel, 0, 255);

  // Here's one last thing to think about. The circuit we made
  // won't have a range all the way from 0 to 5 Volts. It will
  // be a smaller range, such as 300 (dark) to 800 (light).
  // If we just pass this number directly to map(), the LED will
  // change brightness, but it will never be completely off or
  // completely on.

  // You can fix this two ways, each of which we'll show
  // in the functions below. Uncomment ONE of them to
  // try it out:

  manualTune();  // manually change the range from light to dark

  //autoTune();  // have the Arduino do the work for us!

  // The above functions will alter lightLevel to be cover the
  // range from full-on to full-off. Now we can adjust the
  // brightness of the LED:

  analogWrite(ledPin, lightLevel);

  // The above statement will brighten the LED along with the
  // light level. To do the opposite, replace "lightLevel" in the
  // above analogWrite() statement with "255-lightLevel".
  // Now you've created a night-light!
}


void manualTune()
{
  // As we mentioned above, the light-sensing circuit we built
  // won't have a range all the way from 0 to 1023. It will likely
  // be more like 300 (dark) to 800 (light). If you run this sketch
  // as-is, the LED won't fully turn off, even in the dark.

  // You can accommodate the reduced range by manually 
  // tweaking the "from" range numbers in the map() function.
  // Here we're using the full range of 0 to 1023.
  // Try manually changing this to a smaller range (300 to 800
  // is a good guess), and try it out again. If the LED doesn't
  // go completely out, make the low number larger. If the LED
  // is always too bright, make the high number smaller.

  // Remember you're JUST changing the 0, 1023 in the line below!

  lightLevel = map(lightLevel, 0, 1023, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);

  // Now we'll return to the main loop(), and send lightLevel
  // to the LED.
} 


void autoTune()
{
  // As we mentioned above, the light-sensing circuit we built
  // won't have a range all the way from 0 to 1023. It will likely
  // be more like 300 (dark) to 800 (light).

  // In the manualTune() function above, you need to repeatedly
  // change the values and try the program again until it works.
  // But why should you have to do that work? You've got a
  // computer in your hands that can figure things out for itself!

  // In this function, the Arduino will keep track of the highest
  // and lowest values that we're reading from analogRead().

  // If you look at the top of the sketch, you'll see that we've
  // initialized "low" to be 1023. We'll save anything we read
  // that's lower than that:

  if (lightLevel < low)
  {
    low = lightLevel;
  }

  // We also initialized "high" to be 0. We'll save anything
  // we read that's higher than that:

  if (lightLevel > high)
  {
    high = lightLevel;
  }

  // Once we have the highest and lowest values, we can stick them
  // directly into the map() function. No manual tweaking needed!

  // One trick we'll do is to add a small offset to low and high,
  // to ensure that the LED is fully-off and fully-on at the limits
  // (otherwise it might flicker a little bit).

  lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);

  // Now we'll return to the main loop(), and send lightLevel
  // to the LED.
}

Code For Debouncing A Button Shield

C/C++
Code For Debouncing A Button Shield
//initialize and declare variables
const int ledPin = 13; //led attached to this pin
const int buttonPin = 2; //push button attached to this pin
 
int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
 
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers
 
 
void setup() {
 
  //set the mode of the pins...
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);
 
}//close void setup
 
 
void loop() {
 
  //sample the state of the button - is it pressed or not?
  buttonState = digitalRead(buttonPin);
 
  //filter out any noise by setting a time buffer
  if ( (millis() - lastDebounceTime) > debounceDelay) {
 
    //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
    if ( (buttonState == HIGH) && (ledState < 0) ) {
 
      digitalWrite(ledPin, HIGH); //turn LED on
      ledState = -ledState; //now the LED is on, we need to change the state
      lastDebounceTime = millis(); //set the current time
    }
    else if ( (buttonState == HIGH) && (ledState > 0) ) {
 
      digitalWrite(ledPin, LOW); //turn LED off
      ledState = -ledState; //now the LED is off, we need to change the state
      lastDebounceTime = millis(); //set the current time
    }//close if/else
 
  }//close if(time buffer)
 
}//close void loop

Code For Seven Segment Display Shield

C/C++
#define segA 2//connecting segment A to PIN2
#define segB 3// connecting segment B to PIN3

#define segC 4// connecting segment C to PIN4

#define segD 5// connecting segment D to PIN5

#define segE 6// connecting segment E to PIN6

#define segF 7// connecting segment F to PIN7

#define segG 8// connecting segment G to PIN8

int COUNT=0;//count integer for 0-9 increment

void setup()

{

for (int i=2;i<9;i++)

{

pinMode(i, OUTPUT);// taking all pins from 2-8 as output

}

}

void loop()

{

switch (COUNT)

{

case 0://when count value is zero show”0” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, HIGH);

digitalWrite(segG, LOW);

break;

case 1:// when count value is 1 show”1” on disp

digitalWrite(segA, LOW);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, LOW);

digitalWrite(segE, LOW);

digitalWrite(segF, LOW);

digitalWrite(segG, LOW);

break;

case 2:// when count value is 2 show”2” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, LOW);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, LOW);

digitalWrite(segG, HIGH);

break;

case 3:// when count value is 3 show”3” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, LOW);

digitalWrite(segG, HIGH);

break;

case 4:// when count value is 4 show”4” on disp

digitalWrite(segA, LOW);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, LOW);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 5:// when count value is 5 show”5” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, LOW);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 6:// when count value is 6 show”6” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, LOW);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 7:// when count value is 7 show”7” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, LOW);

digitalWrite(segE, LOW);

digitalWrite(segF, LOW);

digitalWrite(segG, LOW);

break;

case 8:// when count value is 8 show”8” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, HIGH);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

case 9:// when count value is 9 show”9” on disp

digitalWrite(segA, HIGH);

digitalWrite(segB, HIGH);

digitalWrite(segC, HIGH);

digitalWrite(segD, HIGH);

digitalWrite(segE, LOW);

digitalWrite(segF, HIGH);

digitalWrite(segG, HIGH);

break;

break;

}

if (COUNT<10)

{

COUNT++;

delay(1000);///increment count integer for every second

}

if (COUNT==10)

{

COUNT=0;// if count integer value is equal to 10, reset it to zero.

delay(1000);

}

}

Credits

Patel Darshil

Patel Darshil

29 projects • 165 followers
I am an Electronics Hobbyist pursuing my BE in Electronics and communication

Comments