In this article we take a look at a shield that has many useful components on it from open-smart, its known as the Starter kit Rich Shield
This Rich Shield has many basic components onboard such as LED, button, buzzer. It is a very good shield for beginners.
It has 2 I2C ports for you to connect an external I2C device. There is also a UART port which allows you to connect a serial controlled device. Here is an image of the shield
Features
DHt11 temperature and humidity sensor
2 push buttons
4 coloured LEDs (yellow, blue, green , red)
Light dependent resistor
NTC thermistor
Infrared reciever
A buzzer
A knob (potentiometer)
24C02 eeprom
4 digit display which is controlled by a TM1637 integrated circuit
I2C connector
UART connector
Standard Arduino expansion board interface, compatible with Arduino UNO, Arduino MEGA2560 and or arduino compatible boards;
Operating voltage: 3.3V – 5.5V
Operating current: 100mA (MAX)
EEPROM size: 2K bit(256Byte)
Parts List
Name | Link |
Arduino Uno | UNO R3 CH340G/ATmega328P, compatible for Arduino UNO |
Starter kit Rich Shield | Starter kit Rich Shield for Arduino UNO R3 |
Code examples
We have various code examples, there is a sample library with examples. Some of the libraries are basic and I decided to also use existing libraries.
LED example
#define LED1 7
#define LED2 6
#define LED3 5
#define LED4 4
uint8_t led[4];
void setup()
{
led[0] = LED1;
led[1] = LED2;
led[2] = LED3;
led[3] = LED4;
for(unsigned int i=0; i < 4; i++)
{
pinMode(led[i], OUTPUT);
LEDoff(i+1);
}
}
void loop()
{
for(uint8_t i=1;i < 5; i++)
{
LEDon(i);//turn on LED i
delay(500);
LEDoff(i);//turn off it.
}
}
void LEDon(uint8_t num)//num = 1, 2, 3, 4
{
if((num > 0) && (num < 5))
digitalWrite(led[num-1], HIGH);
}
void LEDoff(uint8_t num)//num = 1, 2, 3, 4
{
if((num > 0) && (num < 5))
digitalWrite(led[num-1], LOW);
}
LDR example
#include <math.h>
#define LIGHTSENSOR_PIN A2
void setup()
{
Serial.begin(9600);
pinMode(LIGHTSENSOR_PIN, INPUT);
}
void loop()
{
float Rsensor = getRes();//if Rsensor is larger than 40 KOhm, the ambient light is very dark.
//if Rsensor is smaller than 10 KOhm, the ambient light is bright.
Serial.println("The resistance of the Light sensor is ");
Serial.print(Rsensor,1);
Serial.println(" KOhm");
float lux;
lux = 325*pow(Rsensor,-1.4);
Serial.print("Illuminance is ");
Serial.print(lux,1);
Serial.println(" lux");
delay(1000);
}
float getRes()
{
int sensorValue = analogRead(LIGHTSENSOR_PIN);
float Rsensor;
Rsensor=(float)(1023-sensorValue)*10/sensorValue;
return Rsensor;//unit is KOhm
}
Button example
#define KEY1_PIN 9//
#define KEY2_PIN 8//
uint8_t out[2];
int count = 0;
void setup()
{
Serial.begin(9600);
out[0] = KEY1_PIN;
out[1] = KEY2_PIN;
for(uint8_t i=0; i < 2; i++)
{
pinMode(out[i], INPUT);
digitalWrite(out[i], HIGH);
}
}
void loop()
{
int keynum;
keynum = get();
if(keynum == 1) //if you press K1
{
delay(10);//delay for 10ms
if(get() == 1)//check it again
{
count++;
Serial.println(count);
}
while(get() == 1);//Wait for the button to be released
}
}
uint8_t get()
{
for(uint8_t i=0; i < 2; i++)
{
if(!digitalRead(out[i]))
{
delay(10);
if(!digitalRead(out[i])) return i+1;
}
}
return 0;
}
EEPROM example
#include <Wire.h>
void EEwrite(byte data_addr, byte data, byte address=0x57)
{
Wire.beginTransmission(address);
Wire.write(data_addr);
Wire.write(data);
Wire.endTransmission();
}
byte EEread(int data_addr, byte address=0x57)
{
Wire.beginTransmission(address);
Wire.write(data_addr);
Wire.endTransmission();
Wire.requestFrom(address, 1);
if(Wire.available())
return Wire.read();
else
return 0xFF;
}
void setup()
{
Wire.begin();
Serial.begin(9600);
for(int addr = 0; addr < 10; addr++)
{
EEwrite(addr, 10+addr);
delay(100);
}
Serial.println("Have writen to memory!");
for(int addr = 0; addr < 10; addr++)
{
byte r = EEread(addr);
Serial.print("address = ");
Serial.print(addr);
Serial.print(" - ");
Serial.print("number = ");
Serial.print(r);
Serial.print("\n");
delay(1000);
}
Serial.println("Have read 10 number from AT24C02!");
}
void loop() {
}
Voltage example
#define VOL_SENSOR A3
#define GAIN 0.18// Vread = VIN * GAIN
#define ADC_REF 5 //reference voltage of ADC is 5v
uint8_t samples = 10;
void setup(){
Serial.begin(9600);
}
void loop(){
float vol;
vol = readValue();
Serial.println(vol);
delay(1000);
}
float readValue()
{
int sensorValue;
long sum=0;
for(uint8_t i = 0;i < samples;i ++)
{
sensorValue=analogRead(VOL_SENSOR);
sum += sensorValue;
delay(2);
}
sensorValue = sum / samples;//Calculate the average
float vol = sensorValue*ADC_REF/1023.00/GAIN;
return vol;
}
NTC thermistor example
#define NTC_PIN A1 //SIG pin of NTC module connect to A1 of IO Shield, that is pin A1 of OPEN-SMART UNO R3
#define SAMPLING_RESISTOR 10000//the sampling resistor is 10k ohm
#define NTC_R25 10000//the resistance of the NTC at 25'C is 10k ohm
#define NTC_B 3950
void setup()
{
Serial.begin(9600);
delay(1000);//
}
void loop()
{
float celsius;
celsius = getTemperature();//get temperature
Serial.println((int8_t)celsius);//
delay(1000);//delay 1000ms
}
float getTemperature()
{
float temperature,resistance;
int a;
a = analogRead(NTC_PIN);
resistance = (float)a*SAMPLING_RESISTOR/(1024-a); //Calculate the resistance of the thermistor
/*Calculate the temperature according to the following formula.*/
temperature = 1/(log(resistance/NTC_R25)/NTC_B+1/298.15)-273.15;
return temperature;
}
DHT11 example
I used the adafruit library – https://github.com/adafruit/Adafruit_DHT_Unified
/ DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.
// Depends on the following Arduino libraries:
// - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN 12 // Pin which is connected to the DHT sensor.
#define DHTTYPE DHT11 // DHT 11
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup()
{
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println("DHTxx Unified Sensor Example");
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
void loop()
{
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature))
{
Serial.println("Error reading temperature!");
}
else
{
Serial.print("Temperature: ");
Serial.print(event.temperature);
Serial.println(" *C");
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity))
{
Serial.println("Error reading humidity!");
}
else
{
Serial.print("Humidity: ");
Serial.print(event.relative_humidity);
Serial.println("%");
}
}
Display example
I used the following library – https://github.com/avishorp/TM1637
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 10
#define DIO 11
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 2000
const uint8_t SEG_DONE[] = {
SEG_B | SEG_C | SEG_D | SEG_E | SEG_G, // d
SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F, // O
SEG_C | SEG_E | SEG_G, // n
SEG_A | SEG_D | SEG_E | SEG_F | SEG_G // E
};
TM1637Display display(CLK, DIO);
void setup()
{
}
void loop()
{
int k;
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setBrightness(0x0f);
// All segments on
display.setSegments(data);
delay(TEST_DELAY);
// Selectively set different digits
data[0] = 0b01001001;
data[1] = display.encodeDigit(1);
data[2] = display.encodeDigit(2);
data[3] = display.encodeDigit(3);
for(k = 3; k >= 0; k--) {
display.setSegments(data, 1, k);
delay(TEST_DELAY);
}
display.setSegments(data+2, 2, 2);
delay(TEST_DELAY);
display.setSegments(data+2, 2, 1);
delay(TEST_DELAY);
display.setSegments(data+1, 3, 1);
delay(TEST_DELAY);
// Show decimal numbers with/without leading zeros
bool lz = false;
for (uint8_t z = 0; z < 2; z++) {
for(k = 0; k < 10000; k += k*4 + 7) {
display.showNumberDec(k, lz);
delay(TEST_DELAY);
}
lz = true;
}
// Show decimal number whose length is smaller than 4
for(k = 0; k < 4; k++)
data[k] = 0;
display.setSegments(data);
// Run through all the dots
for(k=0; k <= 4; k++) {
display.showNumberDecEx(0, (0x80 >> k), true);
delay(TEST_DELAY);
}
display.showNumberDec(153, false, 3, 1);
delay(TEST_DELAY);
display.showNumberDec(22, false, 2, 2);
delay(TEST_DELAY);
display.showNumberDec(0, true, 1, 3);
delay(TEST_DELAY);
display.showNumberDec(0, true, 1, 2);
delay(TEST_DELAY);
display.showNumberDec(0, true, 1, 1);
delay(TEST_DELAY);
display.showNumberDec(0, true, 1, 0);
delay(TEST_DELAY);
// Brightness Test
for(k = 0; k < 4; k++)
data[k] = 0xff;
for(k = 0; k < 7; k++) {
display.setBrightness(k);
display.setSegments(data);
delay(TEST_DELAY);
}
// On/Off test
for(k = 0; k < 4; k++) {
display.setBrightness(7, false); // Turn off
display.setSegments(data);
delay(TEST_DELAY);
display.setBrightness(7, true); // Turn on
display.setSegments(data);
delay(TEST_DELAY);
}
// Done!
display.setSegments(SEG_DONE);
while(1);
}
Links
Here is the schematic and also as I stated the library for the board with examples if you wanted to use it