cd

Nov 062011
 

Using a Potentiometer with Arduino: 5 LED chaser:

In this activity we connect a potentiometer with the Arduino, and use it to control the speed of 5 flashing LEDs.

arduino-5led-pot-fr

To build this activity you’ll need:

  • Potentiometer
  • 330 or 470 Ohm resistor
  • 5 LEDs
  • jumper wires
  • breadboard
  • Arduino

 

arduino-5-leds-potentiometer01

1) Connect 5 led’s to the breadboard so that the positive lead of each LED can be easily connected to pins 8,9,10,11 and 12 of the Arduino. The negative leads should be connected to a 330 Ohm (minimum) resistor which leads back to ground.

arduino-5-leds-potentiometer02

2) The potentiometer will have a positive, negative, and wiper connection. The wiper should go to pin 0 of the analog inputs while positive and negative go to +5 and Gnd repectively.

Arduino potentiometer & 5 LED chaser code:

 

int sensorValue = 0;    //make a variable where you can store incoming
                        //analog values

void setup(){
  pinMode(12, OUTPUT);  //tell arduino what you'll be using these pins
  pinMode(11, OUTPUT);  // for (output).
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);

  Serial.begin(9600);  //initialize serial
}

void loop(){      //we put the code we want executed in a loop 

Serial.print("sensor = " );  //sends what's in quotes via serial
Serial.println(sensorValue); //sends our variable (sensorValue)
                             //via serial   

  digitalWrite(12,HIGH);       // lights the led
  sensorValue = analogRead(0); // reads pin 0
  delay(sensorValue + 25);     // sensorValue used for delay
  digitalWrite(12,LOW);        //turns off the led
  delay(15);                   //delay before moving to next output pin
                               //the + 25 keeps delay from reaching zero
           //code below is for remaining 4 LEDs
  digitalWrite(11,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(11,LOW);
delay(15);

  digitalWrite(10,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(10,LOW);
delay(15);

  digitalWrite(9,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(9,LOW);
delay(15);

  digitalWrite(8, HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(8, LOW);
delay(15);

  digitalWrite(9,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(9,LOW);
delay(15);

  digitalWrite(10,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(10,LOW);
delay(15);

  digitalWrite(11,HIGH);
  sensorValue = analogRead(0);
  delay(sensorValue + 25);
  digitalWrite(11,LOW);
delay(15);

}

How it works:

As we turn the potentiometer knob we vary the voltage reaching analog pin 0. This voltage (0-5volts) is converted to a value between 0 and 1023. This numerical value is used to change the delay between blinks in the code above, controlling the speed at which the light “moves” from LED to LED. Since we wanted a minimum delay of 25 (any faster didn’t look right) we simply added 25 to the delay value in the code (sensorValue +25).

 

Nov 052011
 

How to Read Capacitor Value Codes:

  • Capacitance is the ability to store electrons and is measured in Farads.
  • One Farad is a very large value! So most capacitors are measured in MicroFarads (uF) or even Picofarads (pF).

capacitor values

What do the letters on a capacitor mean?

Letters that follow the number codes (ex: 103J or 252M) are the tolerance, or how much a capacitor may deviate from its official value. Common values are shown below:

E +/- 0.5% F +/- 1%
G +/- 2% H +/- 3%
J +/- 5% K +/- 10%
M +/- 20% N +/- 30%
P +100% ,-0% Z +80%, -20%

Different classes of capacitors have different meanings for their letter codes.  You can find a very good listing of all capacitor codes at TransTronics and more on ceramic codes at wikipedia.

 Posted by at 7:01 pm
Mar 022011
 

As an idea for a class project, I decided to try turning an inexpensive RC truck into a Robot.

phidget sbc robot truck

My criteria was that it must:

  • Have full movement and steering capability
  • Inlcude a camera
  • Be accessible over the internet (Wi-Fi)

Building the Phidget SBC Robot Truck

My prime candidate for a controller was the Phidget SBC (single board computer). It has wireless and ethernet capability, webcam capability, can control other phidgets (such as a motor controller) and has an integrated interface kit for sensing and control (8 digital out, 8 digital in, and 8 analog in).

For a platform I chose a 1:15 scale Dodge M80 RC truck, but any mid to large size RC vehicle should do. A larger truck would have made the build much easier and concealed more electronics, but the $19 price tag on this truck was too good to pass up. In hindsight it worked out for the best because concealing all the electronics would have greatly reduced the “wow” factor.  :)

Removing the original RC board:

The first step was to pop the truck open and see what kind of space I had to work worth. Four screws through the bottom of the chassis released the body. I also removed the “tinted” windows so I could see inside the truck when it was reassembled. Note the LED headlights! (which were not LEDs, more on that later).

testing steering voltage

Next I opened the chassis cover to identify where to tie in the Phidget SBC. I was a little disappointed that the steering motor was a regular DC motor (meaning there is no fine control of the steering). A servo would have been nice but would also require a third phidget board.  My plan is to hook the drive motor and steering motor both to the same phidget Motor Controller which I can access via the Phidget SBC.

I also tested the voltage that the RC board was sending to the steering motor since it looked a bit small. It turned out to be roughly 5 volts.

rc truck circuitry

Since I’m using my own single board computer and motor controller, all I really need are the drive and steering motors along with access to the battery pack. So I snipped the wires to the motors, headlights and battery pack and removed the antenna and frequency selector switch along with the main board.

remove the board

I’ll keep this RC board in case I want it for another project. A tri-frequency radio transmitter with a four-output receiver may come in handy some day!

Mounting the Phidget SBC and Motor Controller:

bigphoot009mcmount2

I mounted the Phidget motor controller to a thin piece of panel-board and screwed that to the chassis of the truck. Power wires from the battery pack and the SBC both connect to the Motor controller power port. This eliminated the need for a dedicated power distribution rail and kept the SBC and MC wired in parallel with the battery pack. The battery pack takes 5 AA batteries. Using 1.2 V rechargeable NiMH batteries will give me 6 volts, which is the minimum for the SBC, so I may have to switch to a larger external battery pack in the future.

Take note! You don’t want to connect external power (wall adapter) to the boards in this configuration since you’ll likely overcharge the batteries or cause fire or injury!! In the video I have the external power connected only when there are NO batteries in the truck.

mc mounted

phidget motor controller mounted

The drive motor wires were connected to the Motor(0) port and the steering motor wires were connected to the Motor(1) port. The wires did have to be extended. For the USB all I had was a large cable, so I connected it between the MC and the SBC then coiled the rest under the truck bed.

sbc mounted

phidget sbc mounted

The SBC was mounted to the rails of the truck bed. The usb devices (MC, WiFi dongle and webcam) were plugged into the back of the SBC. On closer inspection I realized that the WiFi dongle was putting a strain on everything due to it’s larger physical size. That was remedied by using the little extension USB cable that came with the SBC.

I plugged the headlights into Port 7 and GND on the output side of the SBC’s interface kit. Because the amperage is regulated, they didn’t light the mini-incandescent bulbs (which I had assumed to be LEDs). I removed the incandescents and replaced them with miniature green LEDs. They worked like a charm.

bigphoot lights

Controlling the Phidget SBC Robot Truck:

There are well over a dozen languages which can be used to program Phidgets. I used Visual Basic 6 since that is what we’ve been using in class. While it isn’t the newest language, it’s easy to pick up and there are some nifty active-X controls available for it. In the future I may re-do the controls in Java to allow use on both windows and linux.

bigphoot ui

The fwd, left right, etc are for testing, while the joystick is a more intuitive control. It’s a customizable Active-X from GlobalMajic.

Coding the Interface:

Here’s a copy and  explanation of the VB6 code in case you find it helpful! (and remember to load the Phidget’s reference under Project, References!)

 

Dim WithEvents remotekit As PhidgetInterfaceKit
Dim WithEvents remotemc As PhidgetMotorControl
'the dim line needs to reference both the phidgets we used
'I called one remotekit and the other remotemc

Private Sub Form_Load()
'set and call for both the Motor controller and
'the onboard 8/8/8. Note we must specify
'the wireless IP address, as well as the
'proper port and individual serial number of each phidget.
Set remotekit = New PhidgetInterfaceKit
Call remotekit.OpenRemoteIP("192.168.2.232", 5001, 45519)
Set remotemc = New PhidgetMotorControl
Call remotemc.OpenRemoteIP("192.168.2.232", 5001, 82588)
End Sub

Private Sub Command1_Click()
'geared motor at wheels seems to work ok with 
'pwm set to 30. Your's will differ.
remotemc.Velocity(0) = 30
End Sub

Private Sub Command2_Click()
'stop button should kill power to both motors
remotemc.Velocity(0) = 0
remotemc.Velocity(1) = 0
End Sub

Private Sub Command3_Click()
'geared motor at wheels seems to work ok with 
'pwm set to 30. Your's will differ.
remotemc.Velocity(0) = -30
End Sub

Private Sub Command4_Click()
'tiny motor for steering seems ok at 80.
'still makes noise though. Your's may differ.
remotemc.Velocity(1) = -80
End Sub

Private Sub Command5_Click()
'tiny motor for steering seems ok at 80.
'still makes noise though. Your's may differ.
remotemc.Velocity(1) = 80
End Sub

Private Sub lightson_Click()
'using the on board 8/8/8 to power the led headlights
remotekit.OutputState(7) = True
End Sub

Private Sub lightsoff_Click()
'using the on board 8/8/8 to turn off the led headlights
remotekit.OutputState(7) = False
End Sub

Private Sub joy1_JoyMove()
'Maps motor velocity to joystick x and Y
'values whenever the joystick moves.set your
'deadzone, max and mins in the properties window.
remotemc.Velocity(0) = joy1.YPos
remotemc.Velocity(1) = -(joy1.XPos)
End Sub

 

I ran the program alongside my web browser so that I could see what BigPhoot was seeing.

controlling BigPhoot with video!

Controlling BigPhoot with video!

The phidget SBC has a built-in webserver so that you can access the video feed. But in the picture above, I already had the phidget control page open so I just watched it though that.

Future Mods:

  1. A horn!
  2. More power!

Bigphoot came with a built in 5-cell battery bay (AA). It simply isn’t enough. I used five 1.2V NiMH cells each capable of  2200 mAh. They lasted for about 10 minutes of use. First of all, they barely supplied the 6V needed for the phidgets . My boards were probably drawing 500 mA and the motors more than that.

In fact, I had originally wanted to use a phidget Low Voltage (LV) motor controller. It was capable of handling 1500 mA. here’s what I saw when I fired up the program:

bigphoot012lverror

Danger Will Robinson!

This tells me that the truck motors use more power than I had allotted. The next modifications for Bigphoot will have to include a larger battery pack or a trailer for hauling a lead-acid battery :)

 

Feb 172011
 

Creating a LED chaser with arduino:

In this activity we’ll use an array of LEDs to do some neat stuff! This is a variation of the simple LED blink activity, except that it uses 5 LED’s and we’ll time them so that it looks look like a light is moving between them.

To build this activity you’ll need:

  • 330 or 470 Ohm resistor
  • 5 LEDs (all the same color looks nicer)
  • jumper wires
  • breadboard
  • Arduino

Connecting the Arduino and building the circuit:

0) Connect your Arduino to your computer using a USB cable. The power light should come on.

1) Place your 5 LEDs in the breadboard so that the cathode side of each LED can be connected to the ground rail with small jumper wires (shown below). A longer jumper wire should also be connected (through a resistor) to the ground rail.

2) Connect the other leg of each LED to pins 12,11,10,9, and 8 on the digital side of the Arduino. The long jumper wire that you connected to the ressitor also gets connected to the Gnd pin on the Arduino.

3) Open the Arduino IDE and type in the following code. This code is really just the same as the LED blink code except that extra output pins have been added to the setup section (one pin for each LED), and the loop section now contains instructions to turn each pin on and off after a certain delay.

void setup(){
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop(){
  digitalWrite(12,HIGH);
  delay(100);
  digitalWrite(12,LOW);
 delay(25);
  digitalWrite(11,HIGH);
  delay(100);
  digitalWrite(11,LOW);
 delay(25);
  digitalWrite(10,HIGH);
  delay(100);
  digitalWrite(10,LOW);
 delay(25);
  digitalWrite(9,HIGH);
  delay(100);
  digitalWrite(9,LOW);
 delay(25);
  digitalWrite(8, HIGH);
  delay(100);
  digitalWrite(8, LOW);
 delay(25);
}

4) Check the code by pressing the verify button and then upload to the Arduino using the upload button. It should run Automatically!

The code above will make the light “move” from the first LED to the last, but not back and forth. To do that we’ll need to add in a few more lines as shown below.

Arduino chaser variation -  “Knight Ride-uino”

These lines turn the middle LEDs on in a reverse order, making it look like the Light is moving back to its starting position. Putting a longer delay on the first and last LED seems to improve the “look” of the chaser.

void setup(){
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
}

void loop(){
//big pause on pin 12
  digitalWrite(12,HIGH);
  delay(200);
  digitalWrite(12,LOW);
  delay(25);
  digitalWrite(11,HIGH);
  delay(100);
  digitalWrite(11,LOW);
 delay(25);
  digitalWrite(10,HIGH);
  delay(100);
  digitalWrite(10,LOW);
 delay(25);
  digitalWrite(9,HIGH);
  delay(100);
  digitalWrite(9,LOW);
 delay(25);
// big pause on pin 8
  digitalWrite(8, HIGH);
  delay(200);
  digitalWrite(8, LOW);
 delay(25);
//new lines to make the light move
//in the opposite direction
  digitalWrite(9,HIGH);
  delay(100);
  digitalWrite(9,LOW);
 delay(25);
  digitalWrite(10,HIGH);
  delay(100);
  digitalWrite(10,LOW);
 delay(25);
  digitalWrite(11,HIGH);
  delay(100);
  digitalWrite(11,LOW);
 delay(25);

}

Challenge:

Try varying the delay times to get the rhythm you want and adding extra LEDs!

 Posted by at 1:16 am