Difference between revisions of "Smart Piggy Bank"

From Microduino Wiki
Jump to: navigation, search
(Start to Program)
 
Line 6: Line 6:
 
[[File:anywhere_piggy bank.jpg|600px|center]]
 
[[File:anywhere_piggy bank.jpg|600px|center]]
  
Make a smart piggy bank, which can record the coin number and display it on OLED, and emit “ding” sound every time throw a coin into it.  
+
Make a smart piggy bank, which can record the coin number and display it on OLED, and emit "ding" sound every time throw a coin into it.  
 
<br>
 
<br>
 
Suitable kit: mCookie302
 
Suitable kit: mCookie302
Line 48: Line 48:
 
==Program==
 
==Program==
 
===Required Program Blocks===
 
===Required Program Blocks===
*[[“OLED display-print” program block]]
+
*[["OLED display-print" program block]]
*[[“If-do”program block]]
+
*[["If-do" program block]]
*[[“Declare as”, “variable assignment” program block]]
+
*[["Declare as", "variable assignment" program block]]
*[[“Repeat doing” program block]]
+
*[["Repeat doing" program block]]
*[[“Println” program block]]
+
*[["Println" program block]]
*[[“Calculate” program block]]
+
*[["Calculate" program block]]
*[[“Text” program block]]
+
*[["Text" program block]]
  
  
Line 68: Line 68:
 
'''The buzzer rings, the number counts, and it is displayed on the screen.'''
 
'''The buzzer rings, the number counts, and it is displayed on the screen.'''
 
<br>
 
<br>
The buzzer produce a “ding” sound, variable coin adds 1. Pay attention to adjusting the direction of the screen according to the installation direction. Display the value of coin on the OLED. Wait for the distance value of the line finder to be larger than 220 (the coin fell into the bank.).  
+
The buzzer produce a "ding" sound, variable coin adds 1. Pay attention to adjusting the direction of the screen according to the installation direction. Display the value of coin on the OLED. Wait for the distance value of the line finder to be larger than 220 (the coin fell into the bank.).  
 
[[File:mixly-ctrl-piggy bank-code.jpg|600px|center]]
 
[[File:mixly-ctrl-piggy bank-code.jpg|600px|center]]
 
<br>
 
<br>
Line 74: Line 74:
 
'''Test the result'''
 
'''Test the result'''
 
<br>
 
<br>
After upload, approach the line finder with a coin, and you can hear a “ding” sound produced by the buzzer, and the number on OLED counts once to the current coin number.  
+
After upload, approach the line finder with a coin, and you can hear a "ding" sound produced by the buzzer, and the number on OLED counts once to the current coin number.  
 
<br>
 
<br>
 
[[File:anywhere_piggy bank.jpg|600px|center]]
 
[[File:anywhere_piggy bank.jpg|600px|center]]
Line 81: Line 81:
 
'''Q: If I take all coins in the bank away, how to reset the record? '''
 
'''Q: If I take all coins in the bank away, how to reset the record? '''
 
<br>
 
<br>
'''A: Add a touch button. Judge whether the touch button has been pressed with “if-do” program block. If it has, reset the variable coin. '''
+
'''A: Add a touch button. Judge whether the touch button has been pressed with "if-do" program block. If it has, reset the variable coin. '''
 
<br>
 
<br>
 
<br>
 
<br>
If the “reset” button was pressed, the reset program will be executed. The buzzer will produce “ding” sound, and the value of variable coin will change into 0. Display the coin number again.  
+
If the "reset" button was pressed, the reset program will be executed. The buzzer will produce "ding" sound, and the value of variable coin will change into 0. Display the coin number again.  
 
[[File:mixly-ctrl-piggy bank-code2.jpg|600px|center]]
 
[[File:mixly-ctrl-piggy bank-code2.jpg|600px|center]]
  

Latest revision as of 06:54, 4 November 2016

Overview

Anywhere piggy bank.jpg

Make a smart piggy bank, which can record the coin number and display it on OLED, and emit "ding" sound every time throw a coin into it.
Suitable kit: mCookie302


Module Bill

Module

Module Number Function
mCookie-Core 1 Core board
Battery base 1 Program download and power supply
mCookie-Hub 1 Sensor adapter plate
mCookie-OLED 1 Display
Buzzer 1 Produce sound
Line Finder 1 Detect objects

Other Equipment

  • USB cable*1
  • Sensor cable*2
  • Sensor shell
  • Lego or other fixation structure
Anywhere piggy bank-module.jpg

Module Setup

Setup

Anywhere piggy bank-step.jpg
  • Assemble modules and sensors:
    • Stick the red core module, battery base, OLED and green extension module together;
    • Connect the line finder to pin A0/A1 of Hub;
    • Connect the buzzer to pin 6/7 of Hub;
    • Insert one end of USB cable into the battery base, and connect the other to computer;

Program

Required Program Blocks


Programming Thought

Judge whether the distance value of the line finder is less than 180. If it is, there was coins thrown in (according to the material of the coins, the judgement value can be adjusted appropriately), the buzzer will produce a ding sound, the coin number will increase 1, and it will be displayed on the screen.Finally wait for the distance of the line finder to be larger than 220.

Mixly-ctrl-piggy bank.jpg

Start to Program

Judge if a coin has passed
Declare a variable coin to record the coin number. If the distance value detected by the line finder is less than 180, there are coins in front of the sensor.
The buzzer rings, the number counts, and it is displayed on the screen.
The buzzer produce a "ding" sound, variable coin adds 1. Pay attention to adjusting the direction of the screen according to the installation direction. Display the value of coin on the OLED. Wait for the distance value of the line finder to be larger than 220 (the coin fell into the bank.).

Mixly-ctrl-piggy bank-code.jpg



Test the result
After upload, approach the line finder with a coin, and you can hear a "ding" sound produced by the buzzer, and the number on OLED counts once to the current coin number.

Anywhere piggy bank.jpg



Q: If I take all coins in the bank away, how to reset the record?
A: Add a touch button. Judge whether the touch button has been pressed with "if-do" program block. If it has, reset the variable coin.

If the "reset" button was pressed, the reset program will be executed. The buzzer will produce "ding" sound, and the value of variable coin will change into 0. Display the coin number again.

Mixly-ctrl-piggy bank-code2.jpg

Technical Specification


Related Cases


FAQ