Monday, October 31, 2016

Connecting a 5V DC and a 12V DC motor to Arduino using L293D


Controlling a single 5V DC motor, and a 12V DC thru an Arduino.

Both are same connections -except that for a 5V, the Vss Motor Supply ( pin 8) will be fed 5V from the wall adapter
for a 12V, the Vss will be fed 12Vwall adapter, and the GND will be common across all.

Connect Pins 8 and 9 of the Arduino to Pins 3 and 7 of the L293D

Arduino   L293D
Pin 8      Pin 7
Pin 9      Pin 2

GND ->       GND // or else it wont work

        Pin 4 -> GND
             Pin 5 -> GND
        Pin 1 -> +5V
        Pin 16-> +5V ( or tie them up)

            Pin 3 -> Output to Motor
        Pin 6 -> Output to Motor
       
        Pin 2, and 7 ( as described above, goes to Arduino Pins 8 and 9)
             Pin 8 -> motor supply +5V ( Pin 1, 16 and Pin 8 - can all be tied to +5V)

For a 5V motor
  Pins 1..8 on left and Pin 16 are connected to connect a single DC motor in case of a 5V.)
   Pin 8 -> +5V ( all of them as 5V )

For a 12V motor
 Check 1 and 16 are internal - so 5V.
  Pins 8 is +12V




For a 5V DC motor.




For a 12V DC motor.




void setup()
{
    pinMode(8,OUTPUT) ;  //Logic pins are also set as output
    pinMode(9,OUTPUT) ;
    Serial.begin (9600);
}

void loop()
{
    forward_motor ();  
    delay(3000) ;    
    stop_motor ();
    delay(3000);
   
    backward_motor ();
    delay(3000);
    stop_motor ();
    delay(5000);
       
 }
 void forward_motor () {
 
    Serial.println ("forward");
    digitalWrite(8,HIGH) ;
    digitalWrite(9,LOW) ;

 }
 void stop_motor ()
 {
     // Stop
    Serial.println ("Stop " );
    digitalWrite(8,LOW) ;
    digitalWrite(9,LOW) ;
 }
 void backward_motor ()
 {
    Serial.println("backward");
    digitalWrite(8,LOW) ;
    digitalWrite(9,HIGH) ;
   }

Connecting a 5V DC motor to Arduino using L293D

Controlling a single 5V DC motor thru an Arduino.

Connect Pins 8 and 9 of the Arduino to Pins 3 and 7 of the L293D


Arduino   L293D
Pin 8      Pin 7
Pin 9      Pin 2

GND ->       GND // or else it wont work

        Pin 4 -> GND
             Pin 5 -> GND
        Pin 1 -> +5V
        Pin 16-> +5V ( or tie them up)

            Pin 3 -> Output to Motor
        Pin 6 -> Output to Motor
       
        Pin 2, and 7 ( as described above, goes to Arduino Pins 8 and 9)
             Pin 8 -> motor supply +5V ( Pin 1, 16 and Pin 8 - can all be tied to +5V)

 ( check that Pins 1..8 on left and Pin 16 are connected to connect a single DC motor )        






void setup()
{
    pinMode(8,OUTPUT) ;  //Logic pins are also set as output
    pinMode(9,OUTPUT) ;
    Serial.begin (9600);
}

void loop()
{
    forward_motor ();  
    delay(3000) ;    
    stop_motor ();
    delay(3000);
   
    backward_motor ();
    delay(3000);
    stop_motor ();
    delay(5000);
       
 }
 void forward_motor () {
 
    Serial.println ("forward");
    digitalWrite(8,HIGH) ;
    digitalWrite(9,LOW) ;

 }
 void stop_motor ()
 {
     // Stop
    Serial.println ("Stop " );
    digitalWrite(8,LOW) ;
    digitalWrite(9,LOW) ;
 }
 void backward_motor ()
 {
    Serial.println("backward");
    digitalWrite(8,LOW) ;
    digitalWrite(9,HIGH) ;
   }

Friday, October 14, 2016

End to End Publish/Subscribe from Laptop to Arduino over MQTT

A small demo of how I was able to communicate from my laptop using a python code sending commands to the Arduino Uno using a Cloud broker called cloudmqtt.com and turn on and off a LED.

https://github.com/kiranshashiny/python-cloudmqtt-example

This uses the Paho MQTT library on the laptop to publish commands like ON and OFF.

The code to run on the laptop as well as the Arduino sketch is in the repo.

Wednesday, October 12, 2016

5V Stepper Motor controls using Arduino Uno

This blog is about my Stepper motor that I used to control using an Arduino Uno.
A Stepper motor works in steps and there are times when you need to move the motor in steps -like in a wall clock. This is where the motor comes handy.

( the other types of motors are Servo, and DC motor - more of it in other blogs.)

Here I will control the Stepper motor and tell how to make it work with the Arduino Uno.

Cost :
Stepper Motor :125 rupees
ULN 2003    : 7 rupees.
Arduino Uno : 400 rupees.

Time to put it all together - one afternoon -including debugging and figuring out the wiring.
Skill level : Beginner to Medium.

Stepper Motor :

The stepper motor that I used is 28BYJ-48 and can be programmed to spin in steps to suit our industrial needs. It needs a 5V external power supply and I used a wall adapter. DO NOT use the 5V from Arduino !!!

The challenge was that after wiring the circuit and I executed the File -> Examples -> Stepper - > One Step Revolution, the motor would only move in 1 direction ( counter clockwise ) and would not do clockwise.

So, I had to change the wiring of Pin 9 to 10, and Pin 10 to 9 on the Arduino - to make it work.
Found the link here. https://forum.arduino.cc/index.php?topic=143276.0

In other words - don't pin 8,9,10 and 11 to Input 1,  2, 3 and 4, but instead pin to Input 1, 3 , 2 and 4 on the ULN 2003.
( the source in the File -> Examples had to be modified to make this work )

The next challenge is - this Motor driver ULN 2003 cannot move the motor direction on a DC motor. ( You cannot control a DC motor in reverse )
So this motor driver can only be used for a Stepper Motor and NOT a DC motor.

DO NOT CONNECT the Output pins of the Arduino to the Stepper Motor as you will fry your Arduino- Use the IC in between to make this work.

Have a 5V power supply ( wall adapter ) handy to work with the motor.


The circuit diagram of a ULN 2003 motor driver is as shown :

The inputs on the left are from the Arduino Pins and Outputs will go to the Stepper Motor. You are still left with 3 more Pins after all this.






The circuit is as shown: ( the only correction is Pin 9 and 10 has to be interchanged )













Tuesday, October 4, 2016

Parts for Microcontroller project

Hardware Required:
   - Micro controller ( Arduino Uno )
   - Arduino Ethernet shield
   - HC 05 Bluetooth adapter ( not required for beginners)
   - LEDs – Red, Green, Yellow  - 10 each ( or something on those lines )
   - ESP 8266 for wifi communication

    - 1 Breadboard a foot long.
    - Connector wires
                Male to Male  - 1 set,
                Female to Female connector wires - 1 set
      General purpose wire - about 5 meters ( for everyone )

Sensors:
    - Temperature and Humidity sensor DHT 11
    - PIR sensor for motion sensor. ( for detecting if someone came in etc )
    - Color Recognition Sensor       ( if we are getting into detection of colors, like tablets , or paper )
    - Soil Moisture sensor                        ( if we are into agriculture or conditions where we want to maintain humidity high / low )
    - Pressure sensor                          ( if we want to detect presence of someone on the door step )
    - Heart Rate sensor                         ( medical related stuff )
    - Rain Drop Sensor                        ( for Agriculture, labs, mechanical objects, if we want to Close doors On/Off  based on certain humid conditions)
    - Light detecting Resistors,  LDRs - 10 ( general purpose, if we want to do some solar stuff )
    - Ultrasonic Distance Measuring Sensor        
    - Water flow sensor                


Other things nice to have :
    - Piezo buzzer                            ( to make sound music )    
    - 1 Servo motor SG90 Tower Pro ( general purpose )
    - 12V DC motors - 100 RPM - geared
    - 5V DC motors 
    - LCD display
   
General purpose utilities :    
  - 1 Multimeter
  - 1 Piezo buzzer
  - L293D, 555 timers
  - Magnifying glass
  - Small screw driver set.
  - Wire stripper
  - Nose plier
  - Soldering wire, gun and other accessories.
  - 10k Potentiometer
  - a box of resistors ( usually costs 40 rupees for it - has 220, 270, 330 ohms and so on )

  - RGB LEDs - a few