DIY Desk Lamp

From Microduino Wiki
Jump to: navigation, search


Outline

Anywhere table-lamp.jpg

Make a small desk lamp, and learn to control the on and off of it with switch.

Suitable kits: mCookie102, mCookie202, mCookie302, IBC


Module Bill

Module

Module Number Function
mCookie-Core 1 Core board
mCookie-USBTTL 1 Program download
mCookie-Hub 1 Sensor adapter plate
Crash 1 Crash sensor
LED 1 Single-color LED

Other Equipment

  • USB cable*1
  • Sensor cable*1
  • Sensor shell*1
  • Lego or other fixation structure
Anywhere table-lamp-module.jpg


Module Setup

Anywhere table-lamp-module—step.jpg
  • Assemble the modules and sensors:
    • Stick the red core module, USB upload module and green extension module together;
    • Connect the red LED to pin 6/7 of Hub;
    • Connect the crash sensor to pin 4/5 of Hub;
    • Insert one end of USB cable into USB to upload the modules, and connect the other to computer;


Programming

Required Program Block

Programming Thought

Press the crash sensor, the LED lights on; press again, the LED goes off.

Mixly-ctrl-table-lamp.jpg

Programming

1. Press the crash sensor, the LED lights on.
Set the pin of "crash" program block to 4, and the state to press; set the pin of "digital write" program block to 6, and the state to high; that is controlling the LED to light up after pressing the crash sensor.

Mixly-ctrl-table-lamp-code1.jpg

2. Press again, the LED goes off
Set the pin of the "crash" program block to 4, and the state to press; set the pin of "digital write" to 6, and the state to low; that is controlling the LED to go off after the crash being pressed.

Mixly-ctrl-table-lamp-code2.jpg

3.Test the result:
Look at if it is as expected: press the switch, the light is on; press again, the light goes off. Repeat as this.

Q: Why is the switch flexible sometimes, and out of control now and then?
A: This is because the thinking speed of the core module is very fast, the moment you press the crash, the program judging switch stays down all the time, and the program has been executed millions of times. At this point, LED has been on and off for many times, which is invisible,that is why you think it is out of control.
Q: I get it. If I set the program to wait for the crash to be pressed, and then wait for it to be released, is this OK?
A: You can have a try!
Press the crash down, and then release, to turn the LED on. Repeat it to make turn the LED off. Modify the parameters of program block "crash" and "digital write".

Mixly-ctrl-table-lamp-code3.jpg



Q: The switch is still out of control?
A: Because the "crash" belongs to the mechanical keys, at the moment of being pressed or released, the internal metal chip will shake many times, the program will detect the crash has been pressed and released many times, and the program will be executed continuously. Actually, in this program, the LED has been turned om many times which can't be seen.
Q: How to make the switch stable?
A: In fact, only a "delay" can resolve this problem. At the time of pressing the switch, delay 100ms(make the program pause for 100ms), to wait for the internal shock of the crash subside, and eliminate the jitter of the crash.

Programming thought:
Every time the switch being pressed and released, add a delay program block to wait for the internal of the crash calm down, in order to make the switch able to control the LED.

Mixly-ctrl1-table-lamp.jpg

Programming
1. Every time the switch being pressed and released, add a delay, to wait for the internal shock of the crash to calm down. Press, release, then the LED lights up.

Mixly-ctrl4-table-lamp-code4.jpg

2. Every time the switch being pressed and released, add a delay, to wait for the internal shock of the crash to calm down. Press, release, then the LED goes off.

Mixly-ctrl4-table-lamp-code5.jpg

Test the result:
Press, release, then the LED lights up; press, release, then the LED goes off. Repeat that, turning it on and off continuously. So that we can use the crash to control the light stably.
Set up a desk lamp on your own, put the switch and LED at the right place, and see whose lamp is the most beautiful one.

Anywhere table-lamp.jpg

Technical Specification

  • The product number of crash sensor: MSDS11
  • Digital signal input sensor
  • For details, please refer to Sensor-Crash.

Related Cases

FAQ