Saturday, March 10, 2012

Circuit Lab - Sketch, simulate, and share schematics

For Students & Educators

Draw and print beautiful schematics for lab reports. In-browser simulations make it easy to quickly learn electronics concepts via just-for-fun playing and guided exploration. Our tools complement undergraduate and graduate electrical engineering classes, as well as high school and college physics curriculum.

For Hobbyists & Tinkerers

CircuitLab lets you rapidly test circuit ideas before breadboarding. And when we host your circuit, we provide you with a convenient image and link that you can use to share your circuit on online forums or your own website, so you can contribute to or get help from the hobbyist community.

For Practicing Engineers

Our user-friendly schematic capture tool lets you explore the design space in a fraction of the time of traditional tools. SPICE-like models with a mixed-mode simulation engine help you apply one tool to a wide range of design tasks, from digital to analog, DC to VHF and beyond.

Sunday, March 4, 2012

Fun with Servos

Hacktronics recently sent me two HXT900 servos to play with. I used the sample servo code included in the Arduino IDE, that allows me to control the servo position with a potentiometer.

The pot is connected to the arduino, with the center wiper connected to Analog 0, and the outside connections to +5 and Gnd., respectively.

The servo initially gave us trouble, till Wild Bill on the Arduino.cc forum pointed out the servo needs it's own power supply. The Arduino can't provide enough power to operate it reliably, and could possibly damage the Arduino (thankfully it didn't).

So, we connected the orange wire on the servo to Arduino pin 9, the servo red wire to the + of two AA batteries in series, and the servo brown wire, plus the AA battery pack negative, to Arduino ground. We then loaded the following sketch, and had instant success!

// Controlling a servo position using a potentiometer (variable resistor)
// by Michal Rinott

#include "servo.h"

Servo myservo;  // create servo object to control a servo

int potpin = 0;  // analog pin used to connect the potentiometer
int val;    // variable to read the value from the analog pin

void setup()
{
  Serial.begin(9600);          //  setup serial
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop()
{
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
//  Serial.println(val);
  val = map(val, 0, 1023, 0, 179);     // scale it to use it with the servo (value between 0 and 180)
  myservo.write(val);    // sets the servo position according to the scaled value
//  Serial.println(val);
  delay(15);                           // waits for the servo to get there
}  




Light Sensing with a Cds (LDR)

A Cadmium Sulfide (CdS) sensor is a Light Dependent Resistor (LDR). It is a resistor that reduces resistance when hit with light. The more light, the lower the resistance. The Arduino is ideal for monitoring one of these sensors, and can be the heart of a streetlight or burglar alarm system, turning devices on or off in the presence of light. It could also be used in photography or solar applications, detecting the amount or direction of light.

See the following sketch for ideas. The parts are available at Hacktronics.


/*
Cds Connections:
CdS Pin 1 to +5v
CdS Pin 2 to Analog Pin 3
10k ohm resistor pin 1 to Analog Pin 3
10k ohm resistor pin 2 to Gnd
*/

int analogPin = 3;   // CdS (ldr) connected to analog pin 3
int val = 0;         // variable to store the read value



void setup() {
 Serial.begin(9600);
}



void loop() {
  val = analogRead(analogPin);   // read the input pin
  Serial.println(val);
  delay(100);
   }





Arduino 1.0 upgrades

We have been going through our old sketches, making sure they are Arduino 1.0 friendly. Most of the sketches are, and we have been upgrading any libraries that were not. Please check frequently as we post new upgrades. This weekend has seen a flurry of Arduino activity and we are posting as fast as possible.

To learn more about the changes seen in Arduino 1.0 coding, please see the 2nd Edition (Dec. 2011) of the Arduino Cookbook, by Michael Margolis.


Dallas DS18B20 Temperature Chip

We previously addressed this great temperature sensor (http://arduinotronics.blogspot.com/2010/11/ds18b20-digital-thermometer.html), and have built many projects around it including thermostats and process controls. Unfortunately, the new Arduino 1.0 software upgrade did not work with the older One Wire and Dallas Temperature Libraries. Never fear, the folks at Hacktronics dug up the upgraded libraries, and we just finished testing them with the old sketches. Everything once again is wonderful!
Libraries:

Dallas Temp
One Wire

Both at http://groups.yahoo.com/group/arduinohome/files/temperature%20controlled%20solder%20/ 

Get the DS18B20 at http://www.hacktronics.com/Sensors/Digital-Temperature-Sensor-DS18B20/flypage.tpl.html