0% found this document useful (0 votes)
3 views

ArduinoSection4

The document provides examples of using Arduino to control an LED through a computer interface and a variable resistor. It includes code snippets for turning the LED on and off based on serial input and for controlling the LED's blinking delay using an analog sensor. The document is structured with sections for design and code for each example.

Uploaded by

kareem Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

ArduinoSection4

The document provides examples of using Arduino to control an LED through a computer interface and a variable resistor. It includes code snippets for turning the LED on and off based on serial input and for controlling the LED's blinking delay using an analog sensor. The document is structured with sections for design and code for each example.

Uploaded by

kareem Mohamed
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1

Arduino Section 4
Eng/ Dalia Tarek
2
Example 1

Using computer interface to control the led ( on and off )


3
Design
4

Code
While(Serial.available()==0){}
int ledPin=13; value = Serial.read();
int value; if (value == '1') {digitalWrite(ledPin,HIGH);}
void setup () else if (value == '0') {digitalWrite(ledPin,LOW);}
{
Serial.begin(9600);
pinMode(ledPin,OUTPUT);
}
void loop ()
{
5
Example 2

Variable resistor to control the delay of blinking led


6
Design
7

Code
sensorValue = analogRead(sensorPin);
const int sensorPin = A0; digitalWrite(ledPin, HIGH);
const int ledPin = 13; delay(sensorValue);
int sensorValue; digitalWrite(ledPin, LOW);
void setup( ) delay(sensorValue);
{ }
pinMode(ledPin, OUTPUT);
}
void loop ( )
{
8

Thank You

You might also like