Learning Kit is a perfect start for beginners of Arduino world. You can learn basic soldering tricks and practice programming principles when learning this kit. Have prepared a detailed soldering guide and a fully supported library of programming examples from easy to difficult, so electronic could be fun even if you have bare technical knowledge. Hope you have fun and gain some knowledge with this kit!
Learning Kit contains some basic electronic resources, like buttons, sensors, buzzer and display. There is a great way to learn how to solder. Learning Kit is a through-hole soldering kit for beginners. After assembling the kit, youâll have mastered the basics of through-hole soldering.
Ingredients:
Preparation Time: 60 minutes
Buy nowThis project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.
Assuming this is your first soldering project, let's gather the tools and components to get started.
Only three basic tools are needed. If you don't already have them on hand, then yo will need to purchase them. They will be used time and time again for your soldering projects, so if you have the available funds, choose tools that are well made.
You will need a basic soldering iron, a base to hold it, and a wet sponge. If possible, a soldering station, as seen in the picture above, is preferable because it includes an iron, a stand, a sponge, and a power unit.
The power unit is nice because you can maintain a constant temperature. At the very least, a soldering iron with a pencil shape and a fine point tip is recommended. Please do not use a soldering gun. These can damage sensitive electronics because they generate an electromagnetic spike.
Solder is to DIY electronics as glue is to paper. It is an alloy used to join two metal surfaces together.
A flush cutter is a nippe/pincer for cutting off excess electronic components leads.
We will go over the contents of your kit in the order that they will be soldered.
The base board is our starting point. The silk screen images indicate where all of the electronic components/parts will be attached to the board.
A resistor is an electrical component that regulates the flow of electricity in a circuit. This project uses three different kinds of resistors which are listed in the chart below.
The color code contains the value or rating of a resistor.
Resistor Type | Location(s) | Qty | Notes |
---|---|---|---|
10k resistor | R3, R4, R5, R6 | 4 | Color code: Brown, Black, Orange, Gold |
220 ohm resistor | R7, R8, R9, R10 | 4 | Color code: Red, Red, Brown, Gold |
4.7k resistor | R11, R12, R14 | 3 | Color code: Yellow, Violet, Red, Gold |
We have 4 LEDs in the first photo. There is one green LED, two red LEDs, and one blue LED. Please note that the leads of an LED are not the same length. The longer one is anode, where the current enters the LED, and the shorter one is cathode, where the current leaves the LED. You will want to be aware of this when inserting them onto the base board as they will not function if inserted the wrong way.
In the second photo, from left to right, are a crystal, a thermistor and a light dependent resistor. They are not polarized, meaning it doesn't matter which way they are inserted into the board.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
Blue LED | D1 | 1 | 3mm, polarized |
Green LED | D2 | 1 | 3mm, polarized |
Red LED | D3, D4 | 2 | 3mm, polarized |
Crystal | X1 | 1 | 32.768k |
Thermistor | RT1 | 1 | |
Light dependet resistor | LDR1 | 1 |
In laymanâs terms a capacitor is like a water tower for electricity. It collects and stores the electrical energy in your circuit. Larger capacitors have their electrical characteristics labeled on them. For example, the black one above has â100uF/16Vâ printed on it. While smaller capacitors have abbreviated characteristics printed on them. In order to decipher a smaller capacitorâs value, you can use the following equation, C = XY x 10z (pF), to calculate it. Where the three digit number printed on the capacitor represents XYZ respectively.
Capacitor type | Board Location(s) | Qty | Notes |
---|---|---|---|
100uF/16V cap | C1 | 1 | Electrolytic capacitor, black one |
100nF cap | C2 | 1 | Ceramic disc capacitors (104) |
1nF ceramic disc capacitors | C3, C4 | 2 | Ceramic disc capacitors (102) |
The round object on the left is a coin cell battery holder. The other two items on the right are IC sockets. They house IC chips and allow them to be easily added or removed from the board.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
8-pin socket | U3â | 1 | To hold the DS1307 RTC chip |
12mm coin cell holder | U4â | 1 | To hold the coin cell battery |
18-pin socket | U5â | 1 | To hold the TM1636 7-seg display driver |
There is one buzzer and three buttons.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
Buzzer | BUZ1 | 1 | 12mm |
Button | K1, K2, K3 | 3 | Temporary tactile button |
There is one 7-segment display and two 6-pin female headers. The headers will enable us to attach the display to the board.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
7-seg display | U2 | 1 | 2ââ 4 digits |
6-pin female header | U2 | 2 |
These headers will be used to stack the shield on top of the Arduino.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
6-pin header | J2, J3 | 2 | |
8-pin header | J4, J5 | 2 | |
ISP female header | J6 | 1 | 2x3 |
The two chips, also known as ICs or integrated circuits, and a battery are added to the board in order to prevent any unintended heat damage from soldering.
Component | Board Location(s) | Qty | Notes |
---|---|---|---|
RTC chip | U3 | 1 | DS1307 |
Lithium coin cell | U4 | 1 | 12mm 3V, CR1220 |
7-segment display driver | U5 | 1 | TM1636 |
We will solder the components in the order they are listed in the Electronic Components section:
Let's start with R3, a 10k resistor. First, insert it into its given location on the base board, marked R3. Bend its lead out so you can hold it in place when soldering.
Flip over the board, and we can solder one lead at a time. Make sure the tip of your soldering iron is shiny. If not, melt some solder on it and quickly wipe it on the wet sponge. Place the solder against the lead you want to solder. Move the tip of soldering iron to the lead and melt the solder. The melted solder should instantly stick to the lead. If not, use the iron tip to draw it there. When finished, it should resemble a volcano in shape and have a shiny surface. If not, wait for the solder to cool and melt the solder again.
We donât need the excess lead (the wire sticking out of the board). So when youâre done, use the flush cutter to cut the excess and make it flush with the board. Be very careful when doing this as the lead will fly off after cutting it. Turn the board to one side to prevent the lead from inadvertently injuring you. It is highly recommended that you wear eye protection during this step.
The directions above relay the basic technique for soldering. You can apply these steps when soldering the remaining components to the board. Now solder the remaining R3 lead and the other resistors. Preform them into U shapes, as depicted below. This will speed up the soldering process.
After youâve completed the steps so far, the front of your Shield will look like the picture below.
Insert the crystal into its location and bend it down until it's close to the board. There is a square locating pad on the board that helps you keep the crystal flush. Melt some solder on the pad first. Then, push down the crystal and add more solder to the locating pad. When cool, the crystal should stick to the pad.
Finally flip over the board and solder the crystal's two leads. Clip of the extra leads just like we did with the resistors.
Remember the LEDs are polarized so make sure to insert them into their correct locations. The longer lead will go into hole marked â+â, and place the shorter one in the other hole.
Just like the resistors, the thermistor and light dependent resistor are not polarized so it doesn't matter which way they are inserted, simply insert both leads into the board.
We have two different kinds of capacitors. The light yellow, disc-shaped capacitors are not polarized. For the square black capacitor, make sure the longer lead goes in the hole marked with a â+â. This is very important as capacitors are polarized just like the LEDs. Then solder them just like you did the other components.
Place the coin cell holder on its printed image on the board. This is the only surface mount component in this kit. Surface mount just means the component is soldered onto the surface of the board as opposed to through hole like the other components. Soldering it is very similar to soldering the crystal to the pad. First, melt some solder on its pads, and add some more solder to attach the holder to the board.
Now letâs move on to the sockets. Search for the half-moon shape on the board. This is the directional indicator for the IC Sockets. It is very important that the orientation of the IC socket is correct. There are eight legs for the U3 socket. Place your finger on the socket to keep it in place when you flip over the board. Quickly spread some solder onto one of the legs. Now you can leisurely continue the soldering the other legs. Repeat these steps for the U5 socket also.
Now itâs time to solder the more advanced parts. Buzzers have longer and shorter legs just like LEDs. Insert the longer leg into the notch marked with the â+â. As for the buttons, just snap them into their locations. You canât fail at this because they are rectangular. After that, the board should resemble the picture below.
Then, flip it over and finish soldering. Soldering should be second nature to you now. Notice again the desired volcano shaped solder points.
Stack the female headers on the 7-segment display. Now insert the 7-segmentdisplay onto the board. Match up the printed side of the 7-segment display with the solid circles on the board. Flip over the board and solder the female headers just like you soldered the IC sockets. Anchor one leg first, and then solder the remaining legs.
To keep the stacking headers vertically straight during soldering, weâll use the Arduino as a guide. Insert all headers including the ISP header. Then stack the Shield on top. Now solder from the top.
We are done soldering.
Now letâs insert the battery and ICs. First, remove the 7-segment display. Insert the U3, U4 and U5 chips into their locations by snapping them into the IC sockets. Itâs very important to align the chips per the half-moon shape on the chip to the half-moon shape on the board. Finally, plug the 7-segment display.
You are supposed to finish the soldering of your Learning Kit Shield before moving on to following demos.
Here we start to present you 7 demos from easy to difficult. They involve usage of all hardware resources on Learning Kit Shield:
Each demo caontains detailed comments in the sketch. To figure out how every line affects the turnout, you have to study the sketch and comments carefully.
This demo only involves the usage of the most basic actuator - LEDs.
Arduino:
//-------pin definition of LEDs---------------// #define LED4 5 #define LED3 4 #define LED2 3 #define LED1 2 void setup() { /*Initialization for the hardware.*/ init_pins(); } void loop() { byte speed = 1; runLED(speed);//Sweeping speed of LEDs, range from 1 to 10. } /*Initialization for the hardware,and should be call first*/ void init_pins() { pinMode(LED4, OUTPUT); pinMode(LED3, OUTPUT); pinMode(LED2, OUTPUT); pinMode(LED1, OUTPUT); turnOffAll();//Turn off all the LEDs first. } /*Turn on one LED*/ inline void turnOn(int pinLED) { digitalWrite(pinLED, HIGH); } /*Turn Off one LED*/ inline void turnOff(int pinLED) { digitalWrite(pinLED, LOW); } /*Turn on all the LEDs*/ inline void turnOnAll() { turnOn(LED4); turnOn(LED3); turnOn(LED2); turnOn(LED1); } /*Turn off all the LEDs*/ inline void turnOffAll() { turnOff(LED4); turnOff(LED3); turnOff(LED2); turnOff(LED1); } /****************************************************************/ /*Function:Sweep all LEDs. */ /*Parameter:byte speed,range from 1 to 10,1 = lowest,10 = fastest*/ /*Return: void */ void runLED(byte speed) { if((speed > 0)&&(speed < 11))//If the value of speed is valid? { uint8_t shifter = 0x01; for(uint8_t i = 0;i < 4;i ++) { if(shifter&0x01)//if the lowest significant bit that represents LED1 is HIGH? turnOn(LED1);//yes, turn on LED1. else turnOff(LED1);//no, turn off LED1. if(shifter&0x02) turnOn(LED2); else turnOff(LED2); if(shifter&0x04) turnOn(LED3); else turnOff(LED3); if(shifter&0x08) turnOn(LED4); else turnOff(LED4); shifter <<= 1;//left shift 1 bit, light up the next LED and put out the current one. delay(500/speed); } turnOffAll();//Turn off all LEDs after running the LEDs } } /*The end of the runLED.ino*/
This demo show you how to control LEDs with the most basic input - buttons.
This demo can turn on or off four LEDs by keys. We set two flags to store the status of this test, TEST_START and TEST_END. Every time the âmenuâ key gets pressed, the status toggles between TEST_START and TEST_END. In the status of TEST_START, "increase" key can turn on one more LED from right to left every time it gets pressed. The "decrease" key has an inverse effect as the "increase" key.
Arduino:
#include <TimerOne.h> #define DEBUG 1//comment out if you don't need debug information //-------pin definition of LEDs---------------// #define LED_CLOCK_ADJUST 5 #define LED_ALARM_ADJUST 4 #define LED_ALARM_ENABLE 3 #define LED_BRIGHTNESS_ADJUST 2 //-------pin definition of keys---------------// #define KEY_MENU 11 #define KEY_UP 10 #define KEY_DOWN 9 //------the status of the test---------------// /*Every time the MENU key pressed, it toggle status between TEST_START and TEST_END */ /*When it is TEST_START, it turns to be TESTING if UP key or DOWN key is pressed.*/ uint8_t status; #define TEST_END 0 //the LEDs are off #define TEST_START 1 //the LEDs blink once per second #define TESTING 2 //UP key or DOWN key can control the LEDs const int LEDS_PIN[] = { LED_BRIGHTNESS_ADJUST, LED_ALARM_ENABLE, LED_ALARM_ADJUST, LED_CLOCK_ADJUST }; /*Store ID of highest ranked lit LED.*/ /*eg:If highest ranked lit LED is LED1, LED_on_number is 0.*/ /* If it is LED2, LED_on_number is 1 and so on.*/ int8_t LED_on_number = -1; /*Toggle the status between TEST_START and TEST_END.*/ /*If flag_test_start is 0, the status is TEST_END.*/ /*Otherwise, the status is TEST_START.*/ boolean flag_test_start;//the initial value is 0 /*If flag_all_on is 0,then turn on all LEDs.*/ /*Otherwise, turn off all LEDs.*/ /*Use only when the status is TEST_START.*/ boolean flag_all_on; void setup() { #ifdef DEBUG//if debug message needed, start serial communication Serial.begin(9600); #endif /*Initialization for the hardware*/ init_pins(); Timer1.initialize(500000); // set a timer of length 500000 microseconds Timer1.attachInterrupt( timer1Isr ); // attach the interrupt service routine to the timer1 } void loop() { int16_t key_pressed = scanKey();//poll status of all keys if(key_pressed == KEY_MENU) { /*Every time the menu key pressed, it toggle status between TEST_START and TEST_END */ flag_test_start = ~flag_test_start; if(flag_test_start)status = TEST_START; else status = TEST_END; } else if(key_pressed == KEY_UP) { /*When it is TESTING, "UP" key can turn on one more LED from right to left*/ /*every time the "UP" key pressed. */ if(status == TEST_START)status = TESTING; if(status == TESTING)turnOnMoreLED(); } else if(key_pressed == KEY_DOWN) { /*When it is TESTING, "DOWN" key can turn off one more LED from left to right*/ /*every time the "DOWN" key pressed. */ if(status == TEST_START)status = TESTING; if(status == TESTING)turnOffMoreLED(); } /*if a key has been pressed, wait for extra 200ms*/ if(key_pressed > 0)delay(200); } /*Initialization for the hardware,and should be called first*/ void init_pins() { /*set keys to be inputs and define the initial status as HIGH*/ pinMode(KEY_MENU, INPUT); digitalWrite(KEY_MENU, HIGH); pinMode(KEY_UP, INPUT); digitalWrite(KEY_UP, HIGH); pinMode(KEY_DOWN, INPUT); digitalWrite(KEY_DOWN, HIGH); /*define the pin mode of LEDs*/ pinMode(LED_CLOCK_ADJUST, OUTPUT); pinMode(LED_ALARM_ADJUST, OUTPUT); pinMode(LED_BRIGHTNESS_ADJUST, OUTPUT); pinMode(LED_ALARM_ENABLE, OUTPUT); turnOffAll();//Turn off all the LEDs first. } /*Turn on one LED*/ inline void turnOn(int pinLED) { digitalWrite(pinLED, HIGH); } /*Turn Off one LED*/ inline void turnOff(int pinLED) { digitalWrite(pinLED, LOW); } /*Turn on all the LEDs*/ inline void turnOnAll() { turnOn(LED_CLOCK_ADJUST); turnOn(LED_ALARM_ADJUST); turnOn(LED_BRIGHTNESS_ADJUST); turnOn(LED_ALARM_ENABLE); } /*Turn off all the LEDs*/ inline void turnOffAll() { turnOff(LED_CLOCK_ADJUST); turnOff(LED_ALARM_ADJUST); turnOff(LED_BRIGHTNESS_ADJUST); turnOff(LED_ALARM_ENABLE); } /*Turn on one more LED*/ void turnOnMoreLED() { if(LED_on_number < 3) //when not all LEDs are on { LED_on_number ++; turnOn(LEDS_PIN[LED_on_number]); for(byte i = LED_on_number + 1;i < 4;i ++) turnOff(LEDS_PIN[i]);//make sure the higher ranked LEDs are off } } /*Turn off one more LED*/ void turnOffMoreLED() { if((LED_on_number > 0) || (LED_on_number == 0))//when not all LEDs are off { turnOff(LEDS_PIN[LED_on_number]); LED_on_number --; } } /*Scan keys and get to know which one is pressed*/ int16_t scanKey() { int16_t pin_number = -1;//define non-existent pin number if(digitalRead(KEY_MENU) == LOW) { delay(20); if(digitalRead(KEY_MENU) == LOW) { pin_number = KEY_MENU; } #ifdef DEBUG //print out the message on serial monitor Serial.println("KEY_MENU is pressed"); #endif } else if(digitalRead(KEY_UP) == LOW) { delay(20); if(digitalRead(KEY_UP) == LOW) { pin_number = KEY_UP; } #ifdef DEBUG Serial.println("KEY_UP is pressed"); #endif } else if(digitalRead(KEY_DOWN) == LOW) { delay(20); if(digitalRead(KEY_DOWN) == LOW) { pin_number = KEY_DOWN; } #ifdef DEBUG Serial.println("KEY_DOWN is pressed"); #endif } return pin_number; } /*Timer one interrupt service routine*/ void timer1Isr() { if(status == TEST_START) { /*if it start, all the LEDs will blink once a second.*/ flag_all_on = ~flag_all_on; if(flag_all_on) { LED_on_number = 3;//no more LED to turn on turnOnAll(); } else { LED_on_number = -1;//no more LED to turn off turnOffAll(); } } else if(status == TEST_END) { turnOffAll(); LED_on_number = -1; } }
This demo involves how to make a sound with buzzer, and because you have already known how to use buttons, in this demo, we use buttons to increase or decrease the pitch of buzzer
Every time the âincreaseâ key gets pressed, the pitch of the buzzer will rise up. And when the âdecreaseâ key gets pressed, the pitch will fall down.
Arduino:
#define DEBUG 1//comment out if you don't need debug information //-------pin definition of keys---------------// #define KEY_UP 10 #define KEY_DOWN 9 //-------pin definition of the buzzer--------// #define ALARM_BUZZER 6 int tempo = 300; /*play a tone, the larger the tone is, the lower the frequency becomes*/ void playTone(int tone, int duration) { for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(ALARM_BUZZER, HIGH); delayMicroseconds(tone); digitalWrite(ALARM_BUZZER, LOW); delayMicroseconds(tone); } } void setup() { #ifdef DEBUG Serial.begin(9600); #endif init_pins(); } void loop() { static int tone = 1000; int16_t key_pressed = scanKey(); if(KEY_UP == key_pressed) { /*Every time the menu key pressed, it will raise the pitch of the */ /*buzzer sound. */ if(tone > 100) tone -= 100; playTone(tone,tempo); #ifdef DEBUG Serial.print("tone"); Serial.println(tone); #endif } else if(KEY_DOWN == key_pressed) { /*Every time the menu key pressed, it will lower the pitch of the */ /*buzzer sound. */ if(tone < 2000) tone += 100; playTone(tone,tempo); #ifdef DEBUG//output debug message Serial.print("tone"); Serial.println(tone); #endif } /*if a key has been pressed, wait for extra 200ms*/ if(key_pressed > 0)delay(200); } /*Initialization for the keys and the buzzer*/ void init_pins() { /*K1 and K2 are set to be input pins*/ pinMode(KEY_UP, INPUT); digitalWrite(KEY_UP, HIGH); pinMode(KEY_DOWN, INPUT); digitalWrite(KEY_DOWN, HIGH); /*The buzzer is set to be output pin*/ pinMode(ALARM_BUZZER, OUTPUT); digitalWrite(ALARM_BUZZER, LOW); } /*Scan keys and get to know which one is pressed*/ /*Return: if no key is pressed, return -1.*/ int16_t scanKey() { int16_t pin_number = -1;//define non-existent pin number if(digitalRead(KEY_UP) == LOW) { delay(20); if(digitalRead(KEY_UP) == LOW)//validate a press that outlasts 20ms { pin_number = KEY_UP; } #ifdef DEBUG Serial.println("KEY_UP is pressed"); #endif } else if(digitalRead(KEY_DOWN) == LOW) { delay(20); if(digitalRead(KEY_DOWN) == LOW) { pin_number = KEY_DOWN; } #ifdef DEBUG Serial.println("KEY_DOWN is pressed"); #endif } return pin_number; }
Get started with sensors. First we have here is the temperature sensor. Try to read its value and display it on the 7 segment display.
The 7-segment Display will display current temperature read from temperature sensor as shown below.
Arduino:
#include "TM1636.h" //--Declare a TM1636 Class object that control the 4-digit display--// TM1636 tm1636(7,8); //-Declare the resistance of the resistor that connects with the temperature sensor-// #define RESISTOR_CONNECT_THERMISTOR 10000//the resistance is 8k ohm //-------pin definition of temperature sensor-------------// #define TEMPERATURE_SENSOR A0 void setup() { init_pins(); /*Set the default brightness is BRIGHT_TYPICAL and clear the display*/ tm1636.init(); } void loop() { int8_t temperature; /*Read the ambient temperature and display on the digital tube.*/ temperature = getTemperature(); displayTemperature(temperature); delay(500); } /*Initialization for the hardware.*/ void init_pins() { /*set the temperature sensor that connects with A0 to be input*/ pinMode(TEMPERATURE_SENSOR, INPUT); } /****************************************************************/ /*Return:int8_t,Temperature that range from -40 to 125 degrees. */ int8_t getTemperature() { float temperature,resistance; int a; a = analogRead(TEMPERATURE_SENSOR); resistance = (float)(1023-a)*RESISTOR_CONNECT_THERMISTOR/a; //Calculate the resistance of the thermistor int B = 3975; /*Calculate the temperature according to the following formula.*/ temperature = 1/(log(resistance/RESISTOR_CONNECT_THERMISTOR)/B+1/298.15)-273.15; return (int8_t)temperature;// the type convert from floating point to 8-bit integer } /*********************************************************************/ /*Function:Display 8-bit integer temperature on the 4-digit display. */ /*Parameter:-int8_t temperature,Temperature that range from -40 to 125 degrees. */ /*Return: void */ void displayTemperature(int8_t temperature) { int8_t temp[4]; if(temperature < 0)//if the temperature is below zero? { /*Yes, then the left-most bit will display "-".*/ temp[0] = INDEX_NEGATIVE_SIGN; temperature = abs(temperature); } else if(temperature < 100)//if temperature >= 0 and temperature < 100? { /*Yes, then the left-most bit will display nothing.*/ temp[0] = INDEX_BLANK; } else //if temperature > 100? { /*Yes, then the left-most bit will normally display.*/ temp[0] = temperature/100; } temperature %= 100; temp[1] = temperature / 10;//index of second bit from left temp[2] = temperature % 10;//index of the third bit from left temp[3] = 12; //index of 'C' for celsius degree symbol. tm1636.display(temp); } /*The end of the "MeasureTemperature.ino"*/
Is it convenient if the brightness of display can auto adjust itself according to the ambient light? This demo shows you how to do this by using a light sensor.
This example can change the brightness of BRIGHT_ADJUST Indicator according to the ambient light intensity. The darker the environment is, the lighter the LED turns.
Arduino:
/*Definition of the LED and the light sensor*/ #define LED2 3 #define LED4 5 #define LIGHT_SENSOR A1 void setup() { Serial.begin(9600); init_pins(); } void loop() { /*The brighter the ambient light intensity, the darker the LED*/ uint8_t light_level,duty_cycle; light_level = getLightLevel();//should be 0~7 duty_cycle = light_level*30; //the duty_cycle of the PWM should be 0~210 /*The LED that is controled by PWM pin should be LED2 or LED4.*/ /*The greater the duty_cycle,the brighter the LED.*/ analogWrite(LED2,duty_cycle); delay(500); } /*Initialization for the hardware.*/ void init_pins() { /*Set LED2 and LED4 to be output.*/ /*The initialization of the output level is LOW.*/ pinMode(LED2, OUTPUT); digitalWrite(LED2, LOW); pinMode(LED4, OUTPUT); digitalWrite(LED4, LOW); /*set the light sensor that connects with A1 to be input*/ pinMode(LIGHT_SENSOR, INPUT); } /****************************************************************/ /*Function:Get the ambient light level. */ /*Parameter:void */ /*Return: uint8_t,range from 0 to 7,0 = brightest,7 = darkest */ uint8_t getLightLevel() { uint16_t resistance; uint8_t light_level; resistance = (uint16_t)getLightIntensity(); Serial.print("resistance = "); Serial.println(resistance); if(resistance < 10) light_level = 0; else if(resistance < 50)light_level = 1; else if(resistance < 80)light_level = 2; else if(resistance < 110)light_level = 3; else if(resistance < 140)light_level = 4; else if(resistance < 170)light_level = 5; else if(resistance < 200)light_level = 6; else light_level = 7; return light_level; } /*********************************************************************/ /*Function:Get the resistance of the light sensor */ /*Parameter:void */ /*Return: float,the resistance of the light sensor,its unit is kohm */ /* The brighter the ambient light intensity,the smaller the */ /* resistance. */ float getLightIntensity() { int sensorValue = analogRead(LIGHT_SENSOR); float rsensor; rsensor=(float)(1023-sensorValue)*10/sensorValue; return rsensor; } /*The end of the file "SensorControlBrightness.ino"*/
This demo shows you how to control the content of 7 segment display.
This example can run numeric characters 0, 1, 2, 3, 4, 5, 6, 7, 8 ,9, A, b, C, d, E, F from right to left.
Arduino:
#include "TM1636.h" //--Declare a TM1636 Class object that control the 4-digit display--// TM1636 tm1636(7,8); void setup() { /*Set the default brightness is BRIGHT_TYPICAL and clear the display*/ tm1636.init(); } void loop() { int8_t NumTab[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15};//index of 0~9,A,b,C,d,E,F int8_t table_length; table_length = sizeof(NumTab);//get the length of the number table: NumTab int8_t disp[4];//store the index of the 4 digit to display. unsigned char digit_index = 0; unsigned char starting_index = 0;//starting index of NumTab while(1) { digit_index = starting_index; starting_index ++; if(starting_index == table_length) { starting_index = 0;//start again } for(unsigned char BitSelect = 0;BitSelect < 4;BitSelect ++) { disp[BitSelect] = NumTab[digit_index]; digit_index ++; if(digit_index == table_length) digit_index = 0; } tm1636.display(disp);//display on the 4-digit display. delay(300);//display 4-digit number for 300ms and then it will change. } } /*The end of the file "CharacterFlow.ino"*/
This is a final demo that involves all hardware resources we mentioned above and performs all functions of a real life alarm clock, like time display, making a buzz to get you out of your bed and so on. What's more, because a light sensor and a temperature sensor are added, this Shield does more than a normal alarm clock. It can sense the ambient light and auto-adjust the brightness of 7-segment display. Also it can show you the current temperature at a given time interval.
The 7-segment Display will alternately display current time and temperature.
Arduino:
#include "Wire.h" #include <TimerOne.h> #include <MsTimer2.h> #include <EEPROM.h> #include "TM1636.h" #include "TickTockShield.h" #define ON 1 #define OFF 0 //definitions of global variables boolean flag_update;//1 = update the time on the 4-digit display unsigned char halfsecond;//each time the timer2 interrupts,halfsecond plus one. boolean flag_clockpoint = 1;//change between 0 and 1 every 500ms. If it is 1, //the clockpoint is on.Else the clockpoint is off. boolean flag_2s;//2 seconds flag.1 = to the end of 2 seconds so as to set //flag_display_time boolean flag_10s;//10 seconds flag.1 = to the end of 10 seconds so as to //display temperature boolean flag_display_time = 1;//1 = can display time that get from the RTC uint8_t counter_times = 20;//20*halfsecond = 10seconds. //If it is 20,to count for 10s,so display time for 10s. //If it is 4,to count for 2s,so display the temperture for 2s boolean flag_500ms_blink;//when adjusting the time or the alarm,the hour or minute //displayed on the 4-digit display will blink every 500ms. boolean flag_scan_again;//1 = can scan key again at the state of SYSTEM_NORAML //To avoid the mistake of entering the state of SYSTEM_ADJUSTING //again when pressing MENU for 3s to confirm the setting. uint8_t counter_500ms;//when counter_500 reach 6,flag_scan_again is set 1. /*status definitions for the tick shield control system*/ uint8_t system_states; #define SYSTEM_NORAML 0 //default status,and the system will turn to "normal" status #define SYSTEM_ADJUSTING 1 //triggered when key MENU is pressed at the "normal" status. #define SYSTEM_ALARMING 2 //--Declare a TickTockShield Class object--// TickTockShield ticktockshield; extern int8_t disp[4];//external global array defined in TickTockShield.cpp extern byte g_hand;//external global variable. //the clock hand, HOUR shows that it is adjusting the hour, //MINUTE shows that it is adjusting the minute. void setup() { #ifdef DEBUG Serial.begin(9600); #endif ticktockshield.init(); /*Run the 4 LEDs from left to right*/ ticktockshield.runLED(); if(isFirstLoad())//if it is the first time to load the firmware? { ticktockshield.setAlarm(12,0);//Yes,the alarm clock is initialized to 12:00 //and the data in the EEPROM. } else ticktockshield.getAlarm();//No,read the alarm clock stored in EEPROM /*When system starts, adjust the brightness of the digital tube according to the ambient light intensity.*/ uint8_t lightlevel; lightlevel = ticktockshield.getLightLevel(); ticktockshield.adjustBrightness(lightlevel); /*Read the ambient temperature and display on the digital tube.*/ ticktockshield.displayTemperature(ticktockshield.getTemperature()); delay(1000); MsTimer2::set(500, Timer2ISR);//Timer2 generates an interrupt every 500ms MsTimer2::start();//Timer2 starts counting } void loop() { clockStart(); } /****************************************************************/ /*Function:Implement the function of a clock with an alarm clock, and */ /* the buttons can adjust the clock.*/ void clockStart() { if(system_states == SYSTEM_NORAML)//if it is normal states? { /*Yes, the clock will update every 500ms,and check whether the Menu is pressed */ /*to enter SYSTEM_ADJUSTING state and check if it should be enter SYSTEM_ALARMING state.*/ if(flag_update)//if update flag is not zero? { flag_update = 0; if(flag_clockpoint) { tm1636.point(POINT_ON); } else tm1636.point(POINT_OFF); ticktockshield.getTime(); if(ticktockshield.isAlarmEnable()) { tm1636.point(POINT_ON); ticktockshield.displayTime(); system_states = SYSTEM_ALARMING; return; } if(flag_display_time)ticktockshield.displayTime(); if(flag_2s) { flag_2s = 0; flag_display_time = 1; counter_times = 20; halfsecond = 0; } if(flag_10s) { flag_10s = 0; flag_display_time = 0; tm1636.point(POINT_OFF); ticktockshield.displayTemperature(ticktockshield.getTemperature()); counter_times = 4; halfsecond = 0; } if((flag_scan_again)&&(KEY_MENU == ticktockshield.scanKey())) { ticktockshield.writeToAdjustArea(); ticktockshield.processKey(); system_states = SYSTEM_ADJUSTING; } } } else if(system_states == SYSTEM_ADJUSTING) { ticktockshield.scanKey(); ticktockshield.processKey(); ticktockshield.processSystemStatus(); if(ticktockshield.getQuitReq()) { system_states = SYSTEM_NORAML; counter_500ms = 0; flag_scan_again = 0; } else flag_scan_again = 1; } else if(system_states == SYSTEM_ALARMING) { /*It will sound alarm for a minute untill the "MENU" key is pressed*/ if(ticktockshield.isAlarmEnable()) { ticktockshield.alarming(); } else { ticktockshield.turnOffAlarm(); system_states = SYSTEM_NORAML; } if(KEY_MENU == ticktockshield.scanKey()) { ticktockshield.turnOffAlarm(); system_states = SYSTEM_NORAML; } } } //-------------------------------------- boolean isFirstLoad() { unsigned char mark[] = "ALARM"; unsigned char temp_data[5]; for(unsigned char i = 0;i < 5;i ++) { temp_data[i] = EEPROM.read(i); if(temp_data[i] != mark[i]) { EEPROM.write(0,mark[0]); EEPROM.write(1,mark[1]); EEPROM.write(2,mark[2]); EEPROM.write(3,mark[3]); EEPROM.write(4,mark[4]); return true; } } return false; } /*Function:It is timer 2 interrupt service routine.Timer2 generates an interrupt*/ /* every 500ms.And every time it interrupts,this function will be executed.*/ void Timer2ISR() { halfsecond ++; if(halfsecond == counter_times) { halfsecond = 0; if(counter_times == 4)flag_2s = 1; else if(counter_times == 20)flag_10s = 1; } flag_update = 1; flag_clockpoint = (~flag_clockpoint) & 0x01;//change between 0 and 1 every 500ms. flag_500ms_blink = ~flag_500ms_blink; if(ticktockshield.isAdjustingTime()) { if(g_hand == HOUR) { if(flag_500ms_blink) { disp[0] = INDEX_BLANK; disp[1] = INDEX_BLANK; } } else { if(flag_500ms_blink) { disp[2] = INDEX_BLANK; disp[3] = INDEX_BLANK; } } tm1636.display(disp); } counter_500ms ++; if(counter_500ms == 6) { counter_500ms = 0; flag_scan_again = 1; } }
Method to adjust the time and set the alarm clock:
Learning Shield include RTC, Buzzer, Light Sensor, Temperature Sensor, 3 Buttons, Display as well as 4 LEDs. Each of those has a class, whick make it very easy to use.
TTSTime time; // TTS: Tick Tock Shield time.setTime(int hour, int min, int sec); // set time time.getTime(int *hour, int *min, int *sec); time.getHour(); // return hour time.getMinute(); // return minutes time.getSecond(); // return seconds
TTSBuzzer buzzer; buzzer.on(); // on buzzer.off(); // off buzzer.state(); // return state of buzzer, HIGH:on, LOW:off
TTSLight light; light.get(); // return light sensor data, 0-1023
TTSTemperature temp; temp get(); // return temperature value, int
TTSButton button(Pin); // TTSK1, TTSK2, TTSK3 button.get(); // return button state, HIGH or LOW button.pressed(); // return HIGH when button is pressed button.released(); // return HIGH when button is released
TTSDisplay disp(); disp.display(int loca, int num); // control a nixie tube disp.num(int num); // display a number disp.time(int hour, int min); // display time disp.clear(); // clear display disp.pointOn(); // display : disp.pointOff(); // clear :
TTSLed led(Pin); // TTSLED1, TTSLED2, TTSLED3, TTSLED4 led.on(); // led on led.off(); // led off led.state(); // return led state
Class Functionoperate all components on the Tick Tock Shield.
This function is used to read data from a specified address of EEPROM.
Example:
temp_data[i] = EEPROM.read(i);
The function is used to write data to a specified address of EEPROM.
Example:
if(temp_data[i] != mark[i]) { EEPROM.write(0,mark[0]); EEPROM.write(1,mark[1]); EEPROM.write(2,mark[2]); EEPROM.write(3,mark[3]); EEPROM.write(4,mark[4]); return true; }
Class Function: this class contains all funtions to control four 7-segment displays.
The function is used to turn on or off the clock point (:). This function will come into effect every time the display content changes.
Example:
if(flag_clockpoint) { tm1636.point(POINT_ON); } else tm1636.point(POINT_OFF);
Create a character flow with the content of DispData[].
Example:
tm1636.display(disp);
Class Function: operate all components on the Tick Tock Shield.
The Initialization of the Shield.
This function sweep 4 LEDs in the direction you choose.
Example:
/*Run the 4 LEDs from left to right*/ ticktockshield.runLED(1,LEFT_TO_RIGHT);
Turn on all 4 LEDs.
Turn off all 4 LEDs.
The Function is used to turn on or off an individual LED.
Example:
void TickTockShield::turnOffLED() { setLed(LOW,LED_CLOCK_ADJUST); setLed(LOW,LED_ALARM_ADJUST); setLed(LOW,LED_BRIGHT_ADJUST); setLed(LOW,LED_ALARM_ENABLE); }
Let the buzzer buzz.
Example:
/*It will sound alarm for a minute untill the "MENU" key is pressed*/ if(ticktockshield.isAlarmEnable()) { ticktockshield.alarming(); }
Turn off the alarm when the buzzer is buzzing.
Set the alarm time.
Example:
ticktockshield.setAlarm(12,0);//Yes,the alarm clock is initialized to 12:00 and the data in the EEPROM.
Read the preset alarm value from EEPROM and store them into given variables, including the enable flag of the alarm.
Example:
if(isFirstLoad())//if it is the first time to load the firmware? { ticktockshield.setAlarm(12,0); } else ticktockshield.getAlarm();//No,read the alarm clock stored in EEPROM
Get the reading from temperature sensor.
Example:
/*Read the ambient temperature and display on the digital tube.*/ ticktockshield.displayTemperature(ticktockshield.getTemperature());
Display temperature value(negative value supported) on the 7 segment display. The character C represents celsius degrees.
Example:
ticktockshield.displayTemperature(ticktockshield.getTemperature());
Find out which key gets pressed. Return the pin number of the key pressed. And return "-1" if no keys is pressed.
if((flag_scan_again)&&(KEY_MENU == ticktockshield.scanKey())) { ticktockshield.writeToAdjustArea(); ticktockshield.processKey(); system_states = SYSTEM_ADJUSTING; }
Process the command you enter through keys. If it's a normal press. This function will make a buzz corresponding to the press. If you press the "menu" key longer than 3s, then this function will make Tick Tock Shield enter time setting mode. If no other key gets pressed after the "menu" key, then this function will make Tick Tock Shield quit the time setting mode.
Execute different tasks according to the system status when it's called. The system status can be "adjust clock time" ă "alarm time", "adjust 7 segment display brightness" and "enable alarm".
Deliver the latest time information from normal time display mode to time setting mode so that they can be used under time setting mode.
Deliver the time information set in time setting mode to normal time display mode.
Write time information into RTC chip.
Read the current time information from RTC.
Display time on 7 segment Display.
Example:
if(ticktockshield.isAlarmEnable()) { tm1636.point(POINT_ON); ticktockshield.displayTime(); system_states = SYSTEM_ALARMING; return; }
Display alpha-numeric information 7 segment Display.
If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.
Know more at:
Get the Starter Kits at: