Automotic Wall Follower Robot


Today the autonomous robots by tracking some sort of guidance are very famous. One on this type is the line following robot, a similar is wall following robot where the robot follow some wall and move around the wall. Here in this section we will discuss all about the wall following robot and their simplest circuit.

Components required.

  • DC geared motor (2 sets)
  • wheels (2 sets)
  • caster wheel
  • IR LED (2 sets)
  • Phototransistor (2 sets)
  • Variable resistance, 100K-Ohm (2sets)
  • resistance, 330 Ohm (4 sets)
  • Power Transistor (4 sets)
  • PCB
  • Ribbon Wire
  • Robotic Base
  • Power source, 9V DC
  • Battery connector

Design and working:

As we have seen already in autonomous line follower robot that the transistor-transistor motor derive circuit have a central point across which the motor gets OFF and ON as per the logic we have incorporated therein. Here we will use the same circuit but the configuration is different from autonomous line follower. Here we use one circuit and tune up the variable resistance so that the motor turns ON when the light(IR) intensity increases on the face of Phototransistor. In other circuit we swap the configuration and alter the position of the phototransistor and the variable resistance in the voltage divider section so that the motor connected to this circuit tunes on when the light (IR) intensity increases above the certain level on the face of the phototransistor. As in shown in figure-1 the Motor-1 is turns ON when the IR light intensity increases on the phototransistor face and motor-2 turn ON when the IR light intensity decreased on the phototransistor face.



We use these two phenomenons to control our robot. But before this we have to transport the circuit parts as leveled in the figure-2 to form the wall sensing module.



Here the Sensor-Module (SM)-1 and SM2 are representing the sensor modules that will fixed up in the robot body parts as shown into the figure-3. When robot come closure to the wall the SM-2 senses the event and turns the motor-2 (which is away from the wall) OFF so that the robot goes away from the wall. when the robot goes far away from the wall then SM-1 comes into the picture and it senses the low IR light on the SM-1 which signifies the event of robot moves far away from the wall and in that condition the Moto-1 turned OFF by the intelligent circuit associated with this and then the Robot comes closure to the wall so by the both action the robot maintains a certain distance from the wall and these distance can be controlled by changing the variable resistance values. So that’s all about the wall follower, now it’s time to get up and build one for yourself :)



Autonomous Line Follower (Simplest IR Module Based)

graphics-click-here-688974Click here to get all components required to build this robot

Today world are very advance in the field of robotics. Still the term robotics it very advance but the hobbyist made it easy as to cope up with their lazy style of working. In this we talk the simplest circuit ever you encounter for the line follower robot.

Components Required:

  • DC geared motor (2 sets)
  • Wheels (2 sets)
  • caster wheel
  • PCB
  • Ribbon wire
  • IR LED (2 sets)
  • Phototransistor (2 sets)
  • 100K-Ohm Variable resistance (2 sets)
  • 330 ohm(3 sets)
  • Power transistor (4 sets)
  • Battery  9V DC
  • Battery connector
  • robotic base
  • Ribbon wire
    To get all the componentsgraphics-click-here-688974 Click here.

Design & Working:



for the design the first part is the sensor module and for that we use the  infrared module, first we take an IR LED and get it glow via a 330 Ohm resistance on the 9 Volt grid as shown in figure-1 (Always keep in mind that the Positive lead having longer terminal of IR LED), then comes our sensor part for that we’ll use a Phototransistor that is a very good sensor having immunity to the visible range light and hence very good for indoor robotic event as if will not malfunction due to the environmental lights which is present in the case of LDR based circuits. As far as the Phototransistor is concern always keep in mind that the longer terminal is emitter and shorter terminal is collector so when it connected to the circuit as per the  design is looks like you connected oppositely as we normally see in case of LED that we always connect the small terminal to the ground. but remember the Phototransistor is not the LED so instead it looks like we are connecting in opposite way as LED but the connection is correct. then we connect the variable resistance from the collector and the positive bus of 9 Volt grid (Use of variable resistance instead of fixed resistance has its own advantage as we can always has a facility to tune and adjust our sensor as per the requirement by just varying the variable resistance). there after we connect he middle point of PT(Phototransistor ) and variable resistance to the base of another NPN Power transistor which having a 330 Ohm resistance on its collector terminal having its other terminal to the positive but of the 9Volt grid. then the final connection is made via the collector terminal of 1st Power transistor is being connected to the base of second stage power transistor  which having a motor to its collector terminal. Yeah!!! it’s a quite good question why we are using two transistor, is it possible to use a single transistor instead? the answer is yeah, but in that case the tuning of the variable resistance should be precise and any deviation in the environmental IR light required another tuning, So to increase the circuit performance we like to employed 2 instead of one. Moreover it can work Black Line follower and White line follower both we have to just swap the position of PT and variable resistance or can put the sensor inside and outside the track.

Ohhhh….. The actual design has some more adventure then we see here in the circuit since we have to put the sensor module at the track level so make a sensor module by taking the circuit component out of main circuit as the shaded part shown in Figure-2 into the path sensor module and the terminal connected back to the circuit via a hard wire.

Now here are few tips over the mechanical arrangement of the setup. for the optimal dynamics control of the Robot always keep your sensor module in the direction of the motion at the half of the distance between wheels  in front of the wheels axis. So here is we are finally now take your Robot and do some artwork on it….. :) :):):)

Line Follower Robot Without Microcontroller

Line follower Robot is the  first Automatic Robot made by every engineer working on Robotics. as these days every robot functions with the help of Microcontroller and hence the circuit too complex to understand for start-up. due to this reason. i am presenting Line follower Robot with simple concept without Microcontroller. this robot is mobile automation robot which follow white/black line on black/white surface. using this concept you can make automatic loading goods system,

Here two sensor pairs LED-LDR are used. According to physics, if light falls on a white surface, it gets reflected but when it falls on black surface it will completely get absorbed by the surface. The LDR (Light Dependent Resistance) acts as a sensor which senses the reflected light i.e. “transmitted light by LED”.If the sensor is placed on a white surface, the D.C. motor is turned on and in black surface it will be turned off and robot
will move accordingly.

It is a simple circuit with a LM358 op-amp and is able to operate from 9v to 12V. The LM358 contains two op amps which are wired as comparators. Thus when the voltage at the non-inverting terminal (+) is higher than inverting terminal (-) its output will be high and when the voltage at the inverting terminal (-) is higher than non-inverting terminal (+) the output will be low. Outputs of the op-amp comparators are given to transistors which are wired as switch to drive the motors. Diodes D3 and D4 are provided to cancel the negative voltages produced due to the back emf of the motor.

The sensitivity of the LDR can be adjusted by using the 10K pot. For more accuracy, cover the sensor-LED pairs in a black wrapper through sides in such a way that only the reflected light falls on the LDR. The Line Follower can trace path drawn with black ink on a white chart and the width of the black track should be a litte less than the width between sensors.

Components Required

  •  LM358(2)
  •  D.C. MOTOR ( 2)
  • Variable 10K (2)
  •  Resistance 1K(4)
  • Wheel (4)
  •  Diode 4007
  •  LED ( 2)
  • LDR (2)
  • BC 547 ( 2)
  • Battery line-follower-robot-circuit-without-using-microcontroller-1005x1024


Can be Purchased from Here graphics-click-here-688974

Heart Rate Monitoring Sensor Circuit

Heart rate is a very vital health parameter that is directly related to the soundness of the human cardiovascular system. This project describes a technique of measuring the heart rate through a fingertip using a PIC microcontroller. While the heart is beating, it is actually pumping blood throughout the body, and that makes the blood volume inside the finger artery to change too. This fluctuation of blood can be detected through an optical sensing mechanism placed around the fingertip. The signal can be amplified further for the microcontroller to count the rate of fluctuation, which is actually the heart rate.

Reflective And Transmissive Pulse Oximetry

Pulse oximetry is a noninvasive photo-based technique that measures the light absorption and refection properties of deoxygenated and oxygenated hemoglobin. The amount of light absorbed in the hemoglobin is defined by the Lambert-Beer Law, which associates the degree of light absorption with the wavelength of the beam light, the path length, and the absorption coefficient of the blood constituents.



  • IC LM358
  • Potentiometer (2×100 K ohm).
  • Resistance (1×220 Ohm, 1×10 K,1×1 K, 1×47 K, 1×100 K.
  • Capacitor (1×100 nf , 1x 479 nf).
  • IR LED
  • IR Receiver.
  • Microcontroller board.
  • Display (LCD , LED Or Seven Segment).
  • Power Supply.

Sensor Assembly

The sensor unit consists of an infrared light-emitting-diode (IR LED) and a photo diode, placed side by side, and the fingertip is placed over the sensor assembly, as shown below. The IR LED transmits an infrared light into the fingertip, a part of which is reflected back from the blood inside the finger arteries. The photo diode senses the portion of the light that is reflected back. The intensity of reflected light depends upon the blood volume inside the fingertip. So, every time the heart beats the amount of reflected infrared light changes, which can be detected by the photo diode. With a high gain amplifier, this little alteration in the amplitude of the reflected light can be converted into a pulse.


About LCD and Its Interfacing

Electronic Display are important Devices used in the field of Robotics and Embedded System and its devices. the display Seven Segments, LCD (Liquid Crystal Display) can be used to display Data .  The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. They are of many types. The ones we commonly use for embedded systems, robotics, etc are of two types – character LCD and graphical LCD. lcd162b-yhy

A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix. This LCD has two registers.

  • Command/Instruction Register - stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing, clearing the screen, setting the cursor position, controlling display etc
  • Data Register - stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.


lcd cammand


Now the Pin Map



  •  Data pin8 (DB7) of the LCD is busy flag and is read when R/W = 1 & RS = 0. When busy flag=1, it means that LCD is not ready to accept data since it is busy with the internal operations. Therefore before passing any data to LCD, its command register should be read and busy flag should be checked.
  •  To send data on the LCD, data is first written to the data pins with R/W = 0 (to specify the write operation) and RS = 1 (to select the data register). A high to low pulse is given at EN pin when data is sent. Each write operation is performed on the positive edge of the Enable signal.
  •   To send a command on the LCD, a particular command is first specified to the data pins with R/W = 0 (to specify the write operation) and RS = 0 (to select the command register). A high to low pulse is given at EN pin when data is sent.


Arduino Liquid Crystal Library LCD Interface

Requirements :-

  • LCD 16×2
  • 1 Potentiometer
  • Jumperwire
  • Arduino Board
  • Bread board
  • Usb wire
  • Arduino IDE
  • Battery


All the product you can Buy From here

In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset, such as those available from Sparkfun.It currently implements 8-bit control and one line display of 5×7 characters. Functions are provided to initialize the screen, to print characters and strings, to clear the screen, and to send commands directly to the HD44780 chip. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions.

Install the Library
For a basic explanation of how libraries work in Arduino read the library page. Download the LiquidCrystal library here. Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under “Import Library”.

Connect Pin Out of arduino to LCD

The pinout is as follows:
Arduino                    LCD
2                             Enable
3                             Data Bit 0 (DB0)
4                             (DB1)
5                             (DB2)
6                             (DB3)
7                             (DB4)
8                             (DB5)
9                             (DB6)
10                           (DB7)
11                           Read/Write (RW)
12                           Register Select (RS)

Connect a potentiometer a a voltage divider between 5V, Ground, and the contrast adjustment pin on your LCD.





#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
void loop(void){
lcd.clear(); //clear the display
delay(1000); //delay 1000 ms to view change
lcd.print(‘a’); //send individual letters to the LCD
delay(1000);//delay 1000 ms to view change


This is all great fun, but who really wants to type out each letter of a message indivually? Enter the printIn() function. Simply initialize a string, pass it to printIn(), and now we have ourselves a proper hello world program.
#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
char string1[] = “Hello!”; //variable to store the string “Hello!”
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
void loop(void){
lcd.clear(); //clear the display
delay(1000); //delay 1000 ms to view change
lcd.printIn(string1); //send the string to the LCD
delay(1000); //delay 1000 ms to view change
} //repeat forever
Finally, you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function. For example, commandWrite(2) tells the board to move the cursor back to starting position. Here
is an example:
#include <LiquidCrystal.h> //include LiquidCrystal library
LiquidCrystal lcd = LiquidCrystal(); //create a LiquidCrystal object to control an LCD
char string1[] = “Hello!”; //variable to store the string “Hello!”
void setup(void){
lcd.init(); //initialize the LCD
digitalWrite(13,HIGH); //turn on an LED for debugging
void loop(void){
lcd.commandWrite(2); //bring the cursor to the starting position
delay(1000); //delay 1000 ms to view change
lcd.printIn(string1); //send the string to the LCD
delay(1000); //delay 1000 ms to view change
} //repeat forever


C Programming Based Database management project

Here we had given a small c programming  based Project that having following features.

  •  this project uses File handling and taking input and wring to files.
  • This program is password protected with password 12345.
  • This program uses good knowledge of structure.
  • this program calculates employee salay , age and sort them according to different way.
  • this  program uses some system command of c programming.
  • You can download project from  MiniProject

Using DC Gear Motor

Whenever a robotics we talk about making a robot, the first thing comes to our mind is how Robot will move (How its motion part work).  there are always three options in front of the us, one is to  use a DC Gear motor , second is to use a stepper motor and third one is to use servo motors. When we think about  speed, weight, size, cost… DC motors are always preffered over stepper motors and servo motors. There are many things which we can do with  DC motor when we interfacing it with a microcontroller.



  •  Control the speed of motor.
  •  Control the direction of rotation
  •  Using encoder, keeping track of how many turns are made by  motors.

Here we will work on interfacing a DC motor with a microcontroller. we will use H-bridge in interfacing a DC moto with microcontroller. Some Ic that are used to interface a DC motor with microcontroller are-

H-bridge can also be made with the help of trasistors and MOSFETs etc. rather of being cheap, they only increase the size of the design board, which is somtimes not required so using a small 16 pin IC is preffered for this purpose.

Why we are using Motor Driver for controlling motor. the perfect Ans of thing question is As microcontroller is running with small current and to run a motor need high current in compare to microcontroller  for that purpose we are using Motor Driver.

Most DC motors are normally very easy to reverse. By simply changing the polarity of the DC input, the direction of the drive shaft reverses. This property makes DC motors very popular among enthusiast people involved in robotics. In most cases, DC geared motors are used.

motor driver block


As in diagram shown we can run two motors with the help of 1 L293D Driver.

the following Features are available in a L293D

  •  two enable (EN) pins, pin 1 and pin 9. Pin 1 EN enables the motor Channel  M1 whereas pin 9 EN enables motor Channel M2.
  • Connect motor M1 across OUTPUT1 and OUTPUT2 i.e. across pins 3 and 6.
  • Connect motor M2 across OUTPUT3 and OUTPUT4 i.e. across pins 11 and 14.
  • The inputs for motor M1 is given across INPUT1 and INPUT2 i.e. across pins 2 and 7.
  • The inputs for motor M2 is given across INPUT3 and INPUT4 i.e. across pins 10 and 15.
  • Connect GROUND pins 4, 5, 12 and 13 to ground also work for heat sink.
  • Connect pin 16 to Vcc (=5V For Running Driver) and pin 8 to Vs (battery, 4.5V~36V)(Motor Operating voltage).


l293d pin diagram


  • If Input A1 = 0V and input A2 = 5V the motor1 will run Forward
  • If Input A1 = 5V and input A2 = 0V the motor1 will run Reverse
  • If Input A1 = 0V and input A2 = 0V Or  Input A1 = 5V and input A2 = 5V  the motor will Stop(0V) Or Breaking(5V).

motor clock

Same Situation will be occur for second channel

DC Gear Motor Using With Arduino

The Motor drive’s channel one is connected to pin 6 ,  9 to motor control and pin 8 for enable motor. and a potentiometer is connected to Analog 0 Pin for controlling the speed of


int motor1Pin = 6;    // H-bridge leg 1 (pin 6, 1A)
int motor2Pin = 9;    // H-bridge leg 2 (pin 9, 2A)
int enablePin = 8;    // H-bridge enable pin
int switchPin = A0;
int Motor_speed = 0;

 void setup()                                                                    {   // set the switch as an input:

    pinMode(switchPin, INPUT);
    // set all the other pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
void loop() {

    Motor_speed = analogRead(sensorPin);
       analogWrite(motor1Pin, Motor_speed );   // For motor run clockwise with speed //adjusted by potentiometer
     analogWrite(motor2Pin, Motor_speed );     // For motor run Anticlockwise with speed //adjusted by potentiometer
DC Gear Motor Using With AVR Microcontroller
Generating Signals for controlling the direction of motor using Port A
Motot is connected to Port A at Pin PA0, PA1, PA2 and PA3.
                               Port A Avr

#include <avr/io.h>
#include <util/delay.h>          // for _delay_ms()

int main(void)
DDRA = 0x0F; // initialize port A
// motors connected across PA0…PA3
// clockwise rotation
PORTA = 0b00000101; // PA0 = High = Vcc
// PA1 = Low = 0
// PA2 = High = Vcc
// PA3 = Low = 0

_delay_ms(500); // wait 0.5s

// counter-clockwise rotation
PORTA = 0b00001010; // PA0 = Low = 0
// PA1 = High = Vcc
// PA2 = Low = 0
// PA3 = High = Vcc

_delay_ms(500); // wait 0.5s

Here a Video of a Robot that is developed by using DC Gear Motor


Basic Before Embedded Programing

Bitwise or bitlevel operations form the basis of embedded programming. A knowledge of Hexadecimal and Binary Numbering system is required along with conversion from binary to hex and vice-verse. the link provides information regarding Hexadecimal Numbers.

Bit-wise Operators : Now getting armed with the knowledge of interconversion between Hexadecimal and Binary we can start with Bitwise(or bit level) operations in C. There are bascially 6 types of Bitwise operators. These are :

  • 1. Bitwise OR operator denoted by ‘|
  • 2. Bitwise AND operator denoted by ‘&
  • 3. Bitwise Complement or Negation Operator denoted by ‘~
  • 4. Bitwise Right Shift & Left Shift denoted by ‘>>‘ and ‘<<‘ respectively
  • 5. Bitwise XOR operator denoted by ‘^


Bitwise OR ( | ): This is same as OR Operator in digital logic. if we operate OR 0 with any No n then result will be the No ie. n. itself and if we operate OR 1 with any No n then result will be 1.

Ex. if the no is N then N | 1 = 1 and N | 0 = N

with value – 1 | 8 = 9 and 0 | 8 = 8

If you are using PORTA and want to Set pin 17 without changing rest of bits than by using OR Operator: PORTA |= (1<<17) you can change that bit.

Bitwise AND ( & ) : Bitwise AND operator in C is denoted by ‘&’. When 2 numbers are operated as AND then each pair of ‘corresponding’ bits in both numbers are operated as AND. Consider two 4-bit binary numbers ANDed : 1010 & 1101 , here nth bit of both numbers are operated as AND to get the result. if A and B are two no AND with each other than if any bit value of A or B is 0 than resultant bit value is zero.

Ex. 1 & 8 = 0 and 1 & 9 = 1

(0b10001000) & (0b01111000) = 0b00001000

If you are using PORTA and want to Clear pin 17 without changing rest of bits than by using AND Operator: PORTA &= ~ (1<<17) you can change that bit.

Bitwise Negation ( ~) :

If we need to convert all 1 in a bit to 0 and all 0 to 1 than that will be done by using operator ~ . if 1001 is operated with ~ than the result will be 0110.

in Hex No if ~(0x0F0F00) than result is 0xF0F0FF

If you are using PORTA and want to toggle all bits of a port than

PORTA = ~ PORTA will be use.

XOR Operator( ^ ): XOR is short for eXclusive-OR. By definition of XOR , the result will be a ’1′ if both the input bits are different and result will be ’0′ if both are same (as seen in the table few paragraphs above). XOR can be used to check the bit difference between 2 numbers. if XOR is operated between two no A and B and if bit value of A and B are same than result will be 0 and if they are different than result will be 1.

(0b01101001) ^ ( 0b00001111) = 0b10010110


Setting a bit
Use the bitwise OR operator (|) to set a bit.

number |= 1 << x;

That will set bit x.

Clearing a bit
Use the bitwise AND operator (&) to clear a bit.

number &= ~(1 << x);

That will clear bit x. You must invert the bit string with the bitwise NOT operator (~), then AND it.

Toggling a bit
The XOR operator (^) can be used to toggle a bit.

number ^= 1 << x;

That will toggle bit x.

Checking a bit
To check a bit, AND it with the bit you want to check:

bit = number & (1 << x);

Arduino Tutorial

Blink LED As Digital output: digitalWrite(PinNo, Pin Value);
In most programming languages, the first program you write prints “hello world” to the screen. Since an Arduino board doesn’t have a screen, we blink an LED instead. The boards are designed to make it easy to blink an LED using digital pin 13. Some (like the Diecimila and LilyPad) have the LED built-in to the board. On most others (like the Mini and BT), there is a 1 KB resistor on the pin, allowing you to connect an LED directly. (To connect an LED to another digital pin, you should use an external resistor.) .LEDs have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side. If the LED doesn’t light up, trying reversing the legs (you won’t hurt the LED if you plug it in backwards for a short period of
time) .



Program :

int ledPin = 13; // LED connected to digital pin 13
void setup()
pinMode(ledPin, OUTPUT); // sets the digital pin as output
void loop()
digitalWrite(ledPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second


Button For Digital Input : digitalRead(inPin);
The pushbutton is a component that connects two points in a circuit when you press it.The example turns on an LED when you press the button. We connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-up resistor (here 2.2 KOhms) to the 5 volt supply. The second goes from the corresponding leg of the pushbutton to ground. The third connects to a digital i/o pin (here pin 7) which reads the button’s state. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is “closer” to ground.) You can also wire this circuit the opposite way, with a pull-down resistor keeping the input LOW, and going HIGH when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button. If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is “floating” – that is, it will more-or-less randomly return either HIGH or LOW. That’s why you need a pull-up or pull-down resister in the





Program :

int ledPin = 13; // choose the pin for the LED
int inPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inPin, INPUT); // declare pushbutton as input
void loop(){
val = digitalRead(inPin); // read input value
if (val == HIGH) { // check if the input is HIGH (button released)
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON



Potentiometer Analog Input :analogRead(Analog pin no)
A potentiometer is a simple knob that provides a variable resistance, which we can read into the Arduino board as an analog value. In this example, that value controls the rate at which an LED blinks. We connect three wires to the Arduino board. The first goes to ground from one of the outer pins of the potentiometer. The second goes from 5 volts to the other outer pin of the potentiometer. The third goes from analog input 2 to the middle pin of the potentiometer. By turning the shaft of the potentiometer, we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. This changes the relative “closeness” of that pin to 5 volts and ground, giving us a different analog input. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and we read 0. When the shaft is turned all the way in the other direction, there are 5 volts going to the pin and we read 1023. In between, analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.



Program :

int potPin = 2; // select the input pin for the potentiometer
int ledPin = 13; // select the pin for the LED
int val = 0; // variable to store the value coming from the sensor
void setup() {
pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT
void loop() {
val = analogRead(potPin); // read the value from the sensor
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(val); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
delay(val); // stop the program for some time