Using all of Arduino’s Inputs and Outputs

Arduino inputs and outputs:

analog in – Arduino receives a signal from a sensor

analog out – Arduino sends voltage to a sensor

digital in – Arduino receives voltage from a sensor

digital out – Arduino sens voltage to a sensor

serial in – The Arduino receives an input from the serial monitor

serial out – The Arduino sends data to the serial monitor

 

Screen Shot 2015-02-09 at 3.35.41 PM Screen Shot 2015-02-10 at 12.22.39 AM

 

//led that i will trigger
int led = 8;
//led that i will fade
int pwm = 3;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(led,OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 1 from the photoresistor:
int sensorValue = analogRead(A1);
//map the sensor values to a new range
sensorValue = map(sensorValue,0,1024,0,500);
// print out the value you read:
Serial.print(“photosensor value: “);
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
//trigger the led to turn on and off depending on different lighting conditions
if (sensorValue < 34) {
digitalWrite(led,HIGH);
} else {
digitalWrite(led,LOW);
}
int flexValue = analogRead(A5);
// Convert the analog reading (which goes from 0 – 1023) to a voltage (0 – 5V):
float voltage = flexValue * (5.0 / 1023.0);
Serial.print(“flex value: “);
Serial.println(voltage);
delay(100);
for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) {
// sets the value (range from 0 to 255):
analogWrite(pwm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
// fade out from max to min in increments of 5 points:
for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
// sets the value (range from 0 to 255):
analogWrite(pwm, fadeValue);
// wait for 30 milliseconds to see the dimming effect
delay(30);
}
}

Leave a Reply