≡ Menu

simple motor control diagram* This is a multi-part post. Here are links to all parts:

Part 1: Overview and bill of materials
Part 2: Assembly
Part 3: DC motor control, this post
Part 4: RGB LED control

Most motor control applications can be accomplished with a simple single-transistor circuit. This type of circuit controls the basic operation of turning the motor on and off, and allows very fast switching of the motor, which makes it possible to control the speed of the motor using pulse width modulation (PWM).

The basic problem with this circuit is that the direction of the motor cannot be reversed. For our simple application in this RGB LED night light, spinning the motor in one direction is enough. In the future we will use motors in applications which require us to reverse the direction as well, and for that we will be using the type of motor control circuit called H-bridge circuit.
[continue reading…]

{ 2 comments }

* This is a multi-part post. Here are links to all parts:

Part 1: Overview and bill of materials
Part 2: Assembly, this post
Part 3: DC motor control
Part 4: RGB LED control

Here are the steps:

  1. Solder wires to motor terminals and cover with heat-shrink tubing
  2. Using a knife, sharp scissors or an awl, puncture a small hole (to fit the motor shaft snugly) on the center of the jar lid
  3. Solder motor shaft to jar lid (if necessary use hot glue or super glue, as some surfaces won’t “catch” the solder easily)
  4. Solder the RGB LED leads to long wires and cover the connections with heat-shrink tubing
  5. Build the circuit on the mini breadboard using the schematic as your guide
  6. Prepare the paper diffuser (use a hole puncher and punch a few holes to allow some light to shine through) and tape it around the jar lid using mounting tape
  7. Mount the motor to the side of the breadboard using mounting tape
  8. Tie the LED wires together and secure the wire bundle using a stick as prop (I used a lollipop stick in one of the holes on the breadboard); split the stick tip shaping it as a “Y” to help secure the LED wires in place(show finished picture)

Check the previous post if you need to see the parts list and sketch for the Arduino RGB LED night light again.

{ 0 comments }
Arduino RGB LED Night Light

* This is a multi-part post. Here are links to all parts:

Part 1: Overview and bill of materials, this post
Part 2: Assembly
Part 3: DC motor control
Part 4: RGB LED control

This month’s project uses the Arduino to control a motor and an RGB LED to create an aquarium style spinning night light.

The initial idea was to recycle empty toilet paper tubes to serve as the lampshade, but it turns out the project looks much more attractive and colorful using white paper. (I haven’t given up on the idea of finding a use for the empty tubes, though. Suggestions are welcome.)

A simple DC motor is used to spin the lamp structure, and a jar lid serves as the base. There is (a lot of) room for improvement in the design of the lamp, but I’m a computer scientist and wanna-be crafter at best.
[continue reading…]

{ 4 comments }

* This is a multi-part post. Here are links to all parts:

Part 1: Intro, bill of materials and simple sketch
Part 2: The circuit for the 2-digit 7-segment counter
Part 3: Sketch broken down in sections, explained
Part 4: Added two buttons, and modified sketch
Part 5: Code for buttons, explained; this post

As you could see from last week’s full Arduino sketch listing, the source code for the 2-digit 7-segment display project using buttons is strikingly similar to the one without the buttons; praise for ‘copy and paste‘! (It is worth noting, though, that ‘copy and paste‘ can be responsible for a higher percentage of bugs than I’d care to admit).

There are just a couple of snippets that I would like to comment on:

2 Digit 7 Segment Display Sketch

The first part of the loop() function checks whether either button has been pressed and increments the value of each digit.

  // check button1
  int val1 = digitalRead(BTN1);
  if (val1 == HIGH) {
    digit1++;
    digit1 %= 10;
    delay(10);
  }

  // check button2
  int val2 = digitalRead(BTN2);
  if (val2 == HIGH) {
    digit2++;
    digit2 %= 10;
    delay(10);
  }

The line

digit1 %= 10;

which is shorthand for

digit1 = digit1 % 10;

accomplishes the same as the line

if (count == 10) count = 0;

that was used on the sketch for the single-digit 7-segment project a couple of months ago. It updates digit1 with the remainder of the division of itself by 10, which will be zero when digit1 is 10. The latter code looks a bit more obvious for beginner programmers.

The last part of the loop() function refreshes the display, and is very similar to the sketch for the 2-digit 7-segment display counter.

  // display number
  unsigned long startTime = millis();
  for (unsigned long elapsed=0; elapsed < 600; elapsed = millis() - startTime) {
    lightDigit1(numbers[digit1]);
    delay(5);
    lightDigit2(numbers[digit2]);
    delay(5);
  }
{ 7 comments }

* This is a multi-part post. Here are links to all parts:

Part 1: Intro, bill of materials and simple sketch
Part 2: The circuit for the 2-digit 7-segment counter
Part 3: Sketch broken down in sections, explained
Part 4: Added two buttons, and modified sketch; this post
Part 5: Code for buttons, explained

This week we modify the original circuit and sketch to include two buttons, one to control each digit of the display.

Here’s what the setup of our 2 digit 7 segment display with buttons looks like:

2 Digit 7 Segment Display with Buttons

And here’s the complete sketch:
[continue reading…]

{ 65 comments }

* This is a multi-part post. Here are links to all parts:

Part 1: Intro, bill of materials and simple sketch
Part 2: The circuit for the 2-digit 7-segment counter
Part 3: Sketch broken down in sections, explained; this post
Part 4: Added two buttons, and modified sketch
Part 5: Code for buttons, explained

So now on the the meatier sections of the sketch for this project:

Common anode displays are not immediately obvious as a segment is lit when the corresponding pin is made LOW. You might be surprised, though, that common anode displays are most often used because they can be used with 74xx series logic data-selector chips and general purpose general purpose PNP transistors.
[continue reading…]

{ 8 comments }