Arduino Experiments Part1
Arduino Experiments Part1
Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 2.
The circuit:
- LED attached from pin 13 to ground through 220 ohm resistor
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
------------------------------------------------X ------------------------------------------------
/* Q2 Blink -builtinLED
Turns an LED on for one second, then off for one second, repeatedly.
On-board LED you can control . it is attached to digital pin 13,
Change Delay to 1) delay(2000) 2) delay(250)
3) unequal delay delay(1000) and delay(250) Compile, upload and observe
*/
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
------------------------------------------------X ------------------------------------------------
/* Q3 toggleSwitch-LED State Control Press-ON-Press-OFF
Turns on and off a light emitting diode(LED) connected to digital pin 13,
when pressing a pushbutton attached to pin 2.
The circuit:
- LED attached from pin 13 to ground through 220 ohm resistor
- pushbutton attached to pin 2 from +5V
- 10K resistor attached to pin 2 from ground
*/
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
------------------------------------------------X ------------------------------------------------
// Experiment-4 Q4 Led State contro by Serial Port and Display on Serial
const int ledPin = 13;
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Serial.println("enter '1' or '0' from Keyboard");
}
if(Serial.available()>0) {
char ch=Serial.read();
if(ch=='1') {
digitalWrite(ledPin, HIGH);
Serial.println(" LED ON");
}
else if(ch=='0') {
digitalWrite(ledPin, LOW);
Serial.println("LED OFF");
}
delay(1000); }
}
------------------------------------------------X ------------------------------------------------