Friday, 29 January 2016

Controlling the LED brightness Using Potentiometer

Controlling the LED brightness using Potentiometer and Servo Library

Code
#include<Servo.h>
Servo myservo;
void setup(){
 myservo.attach(9);
  pinMode(A0,INPUT);
}

void loop(){
int potVal = analogRead(A0);
  int val = map(potVal,0,1023,0,180);
  myservo.write(val);
}

Output :

Wednesday, 6 January 2016

Interfacing Photo Resistor With Arduino

Demonstrating Analog Input and Digital Output Using a photo Resistor and LED

Circuit:
Analog Input From Photo Resistor is Connected to A0 pin
LED is Connected to digitalPin 7


Sketch :

void setup(){
pinMode(A0,INPUT);
pinMode(7,OUTPUT);
}

void loop(){
if(analogRead(A0) < 100)
{
digitalWrite(7,HIGH);
}
digitalWrite(7,LOW);
}


Output :

Sunday, 3 January 2016

Arduino Push Buttons

Connecting Two Push Buttons To Arduino.. Taking the Input From Them Using DigitalRead() via Arduino Digital Pins and Switching On the Led If The Both the Push Buttons are Pressed.

Circuit :
The Values of LED resistor : 220 ohms
 PushButton resistors : 1 Mohm Each

Code : 

void setup() {
  // put your setup code here, to run once:
pinMode(3,OUTPUT);
pinMode(7,INPUT);
pinMode(11,INPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(11) && digitalRead(7))
digitalWrite(3,HIGH);

digitalWrite(3,LOW);

}


change the && into || and See the Ouput

Output: