Servo Motor Control using Arduino

Following post will explain Servo motor control using Arduino UNO 3.

Servo motors have three wires: power, ground, and signal. The power wire is typically red, and should be connected to the 5V pin on the Arduino board. The ground wire is typically black or brown and should be connected to a ground pin on the board. The signal pin is typically yellow or orange and should be connected to pin 9 on the board.

The potentiometer should be wired so that its two outer pins are connected to power (+5V) and ground, and its middle pin is connected to analog input 0 on the board.

Figure 1 – Schematic Diagram

servomotor-arduino_bb

Figure 2- Circuit Diagram

servomotor-arduino_schem

 

 

Complie and upload the following code.

#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() {
  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)
 val = map(val, 0, 1023, 0, 180); 
 // 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
 delay(15);   
// waits for the servo to get there
}

Next we will see how to measure temperature using DS18B20.

 

How to test Arduino UNO

C:\Users\Pintu\OneDrive\Blogs\Electronics\Adrino_UNO_image.png

You have received your Arduino UNO and want to quickly verify and test arduino uno that it is in good condition or you want to write your first Arduino UNO program. To do so you need to follow the following steps:

  • Launch the Arduino IDE. If you have not installed, you can download from following site and install it.

https://www.arduino.cc/en/Main/Software

  • Connect the Arduino to USB port.
  • Write the following code to blink the on board LEDtest arduino uno 1
  • Compile and upload the code.
  • The on board LED should start blinking every second.

 

Adjustable Buck regulator with Low Ripple voltage

The LM2576-Adjustable Buck regulator using LM2576- Adj series are monolithic IC that provides all active functions for a step-down(buck) switching regulator. The output voltage is adjustable from 1.23 v to 37 v and are capable of driving 3 am. Load with excellent line and load regulation

It requires minimum number of external components.

Below are 2 version of it.

Fig 1 – LM2576-Adjustable Buck regulator output of 5V

LM2576-Adjustable Buck regulator 1

Fig 2 – LM2576-Adjustable Buck regulator output of 1.2v to 35 v

LM2576-Adjustable Buck regulator 2

If you want to voltage regulator circuit using LM78XX IC click here.

Lighting LED Using Raspberry Pi and Python

Lighting LED using Raspberry Pi

To lighting LED using Raspberry Pi we first need Python GPIO. In my previous post on Raspberry pi we have installed raspbian. Next thing is to start experimenting on it. In this post we will see how you can setup your pi to run Python and create your first Project.

As a first step we need to make sure that we have Python GPIO library installed and working. To do so follow the following steps.

Installing The Python GPIO Library

Python should already be installed in your Raspberry Pi. Next step would be to install GPIO library.

Installation

If you have the latest version of Raspbian then most likely Rpi.GPIO is pre-installed. You just need to update your library using the following commands.

sudo python
import RPi.GPIO as GPIO
GPIO.VERSION

To update the library use following commands.

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install rpi.gpio

Alternate way to install Python GPIO Library:

 

Important: You must be a superuser to run scripts that control the GPIO pins on your RPi. If you are using the IDLE IDE to write your Python scripts, be sure to launch it as a superuser.

Your first Project – lighting up a LED

Parts Required:

  1. Raspberry Pi 2 ( you can use Pi 3)
  2. A small LED( any colour, I have used RED)
  3. 1 100 ohm resistance
  4. Some wires/connectors
  5. Breadboard

At first we will start with lighting the LED with 3.3v pin of Raspberry Pi. For this use the following Schematic:

pi_schematics_1

  • Pin 1 (+3.3 volts) should go to the longer leg of your led. This pin provides a steady supply of 3.3v. Unlike the GPIO pins on your Pi, this pin is not programmable, and cannot be controlled by software.
  • Attach the shorter leg of the led to the resistor. Finally, attach the other end of the resistor to Pin 6 (- GND) on your Pi

If everything goes well, LED should light up when turning on the Raspberry Pi.

Next, we will make this LED to blink by using the GPIO pin 4( or board Pin 7). For this we will write small piece of code in Python.

Launch idle IDE as superuser(root).

sudo idle

type following into the code window and save the file as python1.py

import RPi.GPIO as GPIO 
import time
GPIO.setwarnings(True)
GPIO.setmode(GPIO.BCM) ## Use BCM pin numbering
GPIO.setup(4, GPIO.OUT) ## Setup GPIO Pin 7 to OUT
while True :
    GPIO.output(4,True)
    time.sleep(5)
    GPIO.output(4,False)
    time.sleep(5)

Make connections as shown below:

lighting LED using Raspberry Pi

To run the code press ctrl+f5. You show now see LED blinking with a delay of 5 sec. That’s it for now. We will see some complex code in next post.

Multi browser testing using Visual Studio

Multi browser testing using Visual Studio can be achieved by using Selenium and NUnit plugins. Below are step by step details of how it can be achieved.

Step 1

In order to achieve multi browser testing using Visual Studio, we need to install few extensions and plugins. First is NUnit adapter ( used in test execution and NUnit Test framework) and Selenium Web Drivers.

Install Nunit adapter for Visual Studio from Tools-> Extensions and updates..

Step1 extensions and updatesStep1 extensions and updates 2

Similarly install NUnit framework extension.

Step 2

Create an empty Test project in Visual Studio as shown below.

Step2 create project

Select the newly created project and click on “NuGet package manager” and search for Selenium. It will list selenium WebDriver for different browsers. Select them and install. In my example I have selected for browser Edge, Chrome, and Firefox.

Step2 select package managerStep2 select selenium webdrivers 2Step2_installedAfter Installation of Web drivers, they will be automatically added to project references.

Alternative way to add references is by manually downloading the respective Web Drivers and adding references in the project.

Step 3

Now we will start on writing code for launching the browsers. Add a new item of type class file and add following code.

using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Edge;

namespace Sample1
{
    class Sample1_Edge
    {
        private IWebDriver driver;
        [SetUp]
        public void Setup()
        {
            driver = new EdgeDriver();
        }

        [Test]
        public void SampeBrowserLaunch1()
        {
            driver.Navigate().GoToUrl("http://digitalab.org");
        }
        [TearDown]
        public void TearDown()
        {
            driver.Quit();
            driver.Dispose();
        }
    }
}

Note the 3 important sections. Setup, Test and TearDown. Test will repeat for multiple tests.

For other browsers, you need to change the following code.

driver = new EdgeDriver();

to

driver = new FirefoxDriver();
driver = new ChromeDriver();

Step4

Build the code and run the test using Test Explorer.

Step4 Test execution

 

In the next post we will structure this and use xml file to control multiple browser settings.

In this example of Multi browser testing using Visual Studio, we have used VS 2015. But this will also work with version 2013. It should also work with VS 2012 but I have not tested it.

Raspberry Pi 2 Pinouts

In my earlier blogs I have shown you how to install the OS and use it. Now we are ready to start building the projects. To do so we first need to understand what each pin does. The diagram below shows raspberry pi 2 pinouts and what each pins can do.

rapberry pi 2 pinout 1

Raspberry Pi 2 pinout figure 1

In order to understand pin number, make sure to have your pi oriented as shown in the figure. Now look at the centre two columns on the chart. These shows the Physical Pin number. The outer two columns of the chart show you the bcm numbering. The numbering system that you use depends on how you configure things in the software. There are 2 numbering sachems. One is BCM(Broadcom)

which is more common and will be using for most of the projects and the other is  WiringPi. The picture below shows WiringPi numbering.

raspberry pi2 pinout 2

Also you can notice that some of the pins are multi-purpose. For example pin3 and 5 can be GPIO pins, or they can be configured for I2C. Similarly, 8 and 10 can be General purpose or can be Tx and Rx. Also note that the GPIO pins are analogous to your digital input/output pins on Arduino.

 

 

Raspberry Pi 2 pinout figure 2