Skills Dev II: Working with Inputs and Sensors-Hongyu Mao

For this exercise, I learned how to use some basic sensors and resistors as inputs to control the output. And I use potentiometers and force sensors to control the lightness of an LED light.

Created: December 15th, 2021

0

Outcome

• For this exercise, I learned how to use some basic sensors and resistors as inputs to control the output. And I use potentiometers and force sensors to control the lightness of an LED light.
0

Exercise 1:For this exercise, I try to use potentiometers as an input to vary the brightness of a LED light.

0
// Define a pin that we'll place the pot on
int potPin = A2;

// Create a variable to hold the pot reading

// Define a pin we'll place an LED on
int ledPin = D6;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

//
void setup(){

// Set up the LED for output
pinMode(ledPin, OUTPUT);

// Create a cloud variable of type integer
// called 'light' mapped to photoCellReading
}

void loop() {

// This gives us a value from 0 to 4095

// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(potReading, 0, 4095, 0, 255);

// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);

// wait 1/10th of a second and then loop
delay(100);
}
Click to Expand
0
skill dev2.2
Hongyu Mao
0

Exercise 2:

For the second exercise, I use both a force sensor and a potentiometers to vary the LED light.

0
// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int fsrPin = A2;

// Create a variable to hold the light reading

// Define a pin we'll place an LED on
int ledPin = D6;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

int potentiometerPin = A4;

void setup()
{
// Set up the LED for output
pinMode(ledPin, OUTPUT);

}

void loop()
{
// This gives us a value from 0 to 4095

analogWrite(ledPin,LOW);
}else{
// Map this value into the PWM range (0-255)
// and store as the led brightness
ledBrightness = map(fsrReading, 0, 4095, 0, 255);

// fade the LED to the desired brightness
analogWrite(ledPin, ledBrightness);

// wait 1/10th of a second and then loop
delay(100);

delay(100);
}
}
Click to Expand
0
Skill dev 2
Hongyu Mao