Skip to main content

Posts

Showing posts from July, 2016

Arduino Blinking LEDs

Arduino boards have I/Os (Input/Output) that can either receive or transmit signals. One of its basic functions is digital input/output. It can be programmed to output digital signals that can be used drive devices, such as an LED . To drive an LED, you will have to add a resistor to regulate the current to the LED. The digital output is about 3V (5V or a little less for 5V board), and for an LED the forward voltage is about 2V. What is left (1V) divided by the resistor sets the current. Current is typically 10 to 20mA. Driving an LED Below is an example code for alternating LEDs on Arduino Pro Micro Board. It uses pins 2, 3, 4, and 5 as digital outputs. My 11 year old son helped out in the programming. :) void setup() {   // initialize digital pins 2, 3, 4, and 5 as outputs.   pinMode(2, OUTPUT);   pinMode(3, OUTPUT);   pinMode(4, OUTPUT);   pinMode(5, OUTPUT); } // the loop function runs over and over again forever void loop() {   digitalWrite(2, LOW);   // turn

Arduino Transistor DC Motor Control

Arduino boards have PWM (Pulse Width Modulation) outputs that can be used to control like the speed of a DC motor. On a Pro Micro, those outputs are encircled white on the board. You can program it such that it outputs on a scale of 1-255, 1 being the slowest and 255 being the fastest. PWM gives out pulses whose width is varied (modulated) while the period is constant. The longer it is high, the higher power it delivers to the circuit. PWM can be used to drive a transistor (switch) which in turn drives the motor ON and OFF. The longer the switch is ON, the higher the power delivered to the motor, and thus faster. The circuit consists of a transistor Q1 (TIP31) NPN transistor, driven by the PWM from Arduino. The resistor is to limit the current to the base, but enough to operate the transistor in saturation when the input is high. The diode is to protect the motor from any back emf that might come from the motor when the current is cut off. The circuit is supplied by a 9V battery.