Analog Signal Output
int sensorPin = A0; // select the input pin for the potentiometer int ledPin = 13; // select the pin for the LED int sensorValue = 0; // variable to store the value coming from the sensor void setup() { pinMode(ledPin,OUTPUT); Serial.begin(9600); } void loop(){ sensorValue = analogRead(sensorPin); digitalWrite(ledPin, HIGH); delay(sensorValue); digitalWrite(ledPin, LOW); delay(sensorValue); Serial.println(sensorValue, DEC); }
Digital Signal Output
int Led=13;//define LED port int buttonpin=3; //define switch port ;int val;//define digital variable val void setup() { pinMode(Led,OUTPUT);//define LED as a output port pinMode(buttonpin,INPUT);//define switch as a output port } void loop() { val=digitalRead(buttonpin);//read the value of the digital interface 3 assigned to val if(val==HIGH)//when the switch sensor have signal, LED blink { digitalWrite(Led,HIGH); } else { digitalWrite(Led,LOW); } }