map it to the range of the analog out:
#Arduino read input serial
initialize serial communications at 9600 bps: Int outputValue = 0 // value output to the PWM (analog out) Int sensorValue = 0 // value read from the pot They're used to give namesĬonst int analogInPin = A0 // Analog input pin that the potentiometer is attached toĬonst int analogOutPin = 9 // Analog output pin that the LED is attached to This example code is in the public domain. * LED connected from digital pin 9 to ground Side pins of the potentiometer go to +5V and ground * potentiometer connected to analog pin 0.Ĭenter pin of the potentiometer goes to the analog pin. Reads an analog input pin, maps the result to a range from 0 to 255Īnd uses the result to set the pulsewidth modulation (PWM) of an output pin.Īlso prints the results to the serial monitor. As you adjust the knob of the potentiometer the brightness of the LED should vary.Īnalog input, analog output, serial output.Open the serial monitor window – sensor input and output data should be streaming along.It will turn orange and then back to blue once it has finished. Click the Upload button (next to the Verify button).Click the Verify button on the top left side of the screen.Connect the long leg of the LED to the other end of the resistor with the alligator clip.Place the short leg of the LED into the ground pin next to pin 13. Place one end of the 220-ohm resistor into pin 9.Run the final jumper wire from pin A0 on the Arduino to the middle pin of the potentiometer.Run another jumper wire from one of the ground pins on the Arduino (labeled GND) to the other outside pin of the potentiometer.Run a jumper wire from the 5-volt pin of the Arduino to either one of the outside pins of the potentiometer.Place the potentiometer into the breadboard pictured in the circuit diagram.If you like this tutorial, click here to check out FREE Video Arduino course – thousands of people have really enjoyed it.
#Arduino read input how to
This lesson explores how to use analog input to adjust the intensity of an LED. Controlling a digital pin with an analog input can be extremely helpful because many sensors report analog data. Now this lesson doesn’t use mind control, but it does use Arduino analog input to control the output of a digital pin. My personal bet is on the monster – but I would be concerned with Dracula doing some funky vampire mind control trick. I often wonder who would win if Frankenstein’s Monster and Dracula got into a fight. Arduino Course for Absolute Beginners Arduino Analog Input / Output