![Projet arduino photoresistance et led en Projet arduino photoresistance et led en](/uploads/1/2/4/2/124213004/241921314.jpg)
01.Basics AnalogReadSerialAnalog Read SerialThis example shows you how to read analog input from the physical world using a potentiometer. A potentiometer is a simple mechanical device that provides a varying amount of resistance when its shaft is turned. By passing voltage through a potentiometer and into an analog input on your board, it is possible to measure the amount of resistance produced by a potentiometer (or pot for short) as an analog value. In this example you will monitor the state of your potentiometer after establishing serial communication between your Arduino or Genuino and your computer running the Arduino Software (IDE). Image developed using. For more circuit examples, see theBy turning the shaft of the potentiometer, you change the amount of resistance on either side of the wiper, which is connected to the center pin of the potentiometer. This changes the voltage at the center pin.
How to Use a Photoresistor (or Photocell) - Arduino Tutorial: A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor decreases with increasing incident light intensity. A photoresistor can be applied in light-sensitive detector circuits, and light- and dark-ac.
When the resistance between the center and the side connected to 5 volts is close to zero (and the resistance on the other side is close to 10k ohm), the voltage at the center pin nears 5 volts. When the resistances are reversed, the voltage at the center pin nears 0 volts, or ground. This voltage is the analog voltage that you're reading as an input.The Arduino and Genuino boards have a circuit inside called an analog-to-digital converter or ADC that reads this changing voltage and converts it to a number between 0 and 1023. When the shaft is turned all the way in one direction, there are 0 volts going to the pin, and the input value is 0.
When the shaft is turned all the way in the opposite direction, there are 5 volts going to the pin and the input value is 1023. In betweenreturns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin.Schematic. CodeIn the sketch below, the only thing that you do in the setup function is to begin serial communications, at 9600 bits of data per second, between your board and your computer with the command:Serial.begin(9600);Next, in the main loop of your code, you need to establish a variable to store the resistance value (which will be between 0 and 1023, perfect for an ) coming in from your potentiometer:int sensorValue = analogRead(A0);Finally, you need to print this information to your serial monitor window. You can do this with the command in your last line of code:Serial.println(sensorValue)Now, when you open your Serial Monitor in the Arduino Software (IDE) (by clicking the icon that looks like a lens, on the right, in the green top bar or using the keyboard shortcut Ctrl+Shift+M), you should see a steady stream of numbers ranging from 0-1023, correlating to the position of the pot. As you turn your potentiometer, these numbers will respond almost instantly.
![Photoresistance Photoresistance](/uploads/1/2/4/2/124213004/283775161.jpg)
Here's the 'led & photoresistor' code, embedded using codebender!How it works:. Read analog value from photoresistor/photocell - value=analogRead(pResistor). Check if value is bigger than e.g. 25. Send command to turn on/off the ledTry downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board!You can keep playing with that by clicking the 'Edit' button and start making your own modifications to the code.For example, try to change '25' value and see how it changes the program.