part 1

int sensorPin = A0;      // variable for analog pin (specified as A0-A5)
int ledPin = 13;         // change LED blink rate based on sensor input!
int sensorValue = 0;     // variable to read sensor value

void setup() {
pinMode(ledPin, OUTPUT);

}

void loop() {

// read the sensor’s value (0-1023**)

// set the LED’s brightness to the sensor value
for (int brightness = sensorValue; brightness <= 200; brightness+=5) {             // for loop for adjusting brightness
analogWrite(ledPin, brightness);                                                                         // value of brightness is analog write to pin 12

}

}

Part 2

I only had two of the three sensors

A giant pot and photo resistor. Again the usual initiating variables and setup commands.

Here’s the code

/* POT to LED
*/

int potPin = 0;    // Analog input pin that the potentiometer is attached to
int potValue = 0;  // value read from the pot
int led = 9;      // PWM pin that the LED is on.  n.b. PWM 0 is on digital pin 9
int sensorPin = A1; // select the input pin for the potentiometer
int ledPin = 6; // select the pin for the LED
int sensorValue = 0; // variable to store the value coming from the sensor
int minThresh = 0;// replace this number with a lowest number from the serial monitor
int maxThresh = 1000;// replace this number with a highest number from the serial monitor

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(led, OUTPUT);
}

void loop() {
analogWrite(led, potValue/5);  // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println(“hello”);      // print the pot value back to the debugger pane
delay(10);                     // wait 10 milliseconds before the next loop
Serial.println(sensorValue);
analogWrite(ledPin, map(sensorValue, minThresh, maxThresh, 0, 255));
}

Part 3

Essentially just added the Pin Value (0-255) = 255 * (AnalogVolts / 5);

Here’s the code:

int pwmPin = 9; // output pin supporting PWM
int inPin = A0; // voltage connected to analog pin 3, e.g. a potentiometer
int val = 0; // variable to store the read value
float volt = 0; // variable to hold the voltage read
void setup()
{
pinMode(pwmPin, OUTPUT); // sets the pin as output
}
void loop()
{
volt =(5.0 * val) / 1023;
val = 255 * (volt / 5);
analogWrite(pwmPin, val);
}

This also works for outputting a analog value (PWM) of 0-255 to control the brightness of a LED.

int ledPin = 9;      // PWM pin to LED
int sensorValue = 0;  // variable to store pot value

void setup() {}

void loop() {
// read the value from the sensor:
{"ft_lang_label":"__label__en","ft_lang_prob":0.60419387,"math_prob":0.9836034,"size":2877,"snap":"2019-51-2020-05","text_gpt3_token_len":812,"char_repetition_ratio":0.16115558,"word_repetition_ratio":0.06336634,"special_character_ratio":0.3072645,"punctuation_ratio":0.13483146,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.990111,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-01-21T01:09:29Z\",\"WARC-Record-ID\":\"<urn:uuid:c31a9ff0-fc2b-4067-957a-4bfe55024d77>\",\"Content-Length\":\"63509\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ee3062c4-0a87-438f-bdd8-0114ee357c14>\",\"WARC-Concurrent-To\":\"<urn:uuid:5b44637c-64a4-45ce-8986-268a37cf6894>\",\"WARC-IP-Address\":\"192.0.78.25\",\"WARC-Target-URI\":\"https://jeffreyyip.xyz/2014/02/26/analog-inputoutput/\",\"WARC-Payload-Digest\":\"sha1:FV4I7NRF6EKEWNVGKVALOQY6BRHOHR3T\",\"WARC-Block-Digest\":\"sha1:3ANFJJILH5XQHNZBSWMKCULA2A2EIA7B\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-05/CC-MAIN-2020-05_segments_1579250601040.47_warc_CC-MAIN-20200120224950-20200121013950-00100.warc.gz\"}"}