
If (sensorValue Board -> Arduino/Genuino Uno. Serial.println(sensorValue) // send data to serial SensorValue = analogRead(sensorPin) // read pin A0 Void loop() // runs repeatedly after setup() finishes make the LED pin (pin 13) an output pin Void setup() // runs once when the sketch starts Int sensorValue // variable to stores data Int ledPin = 13 // The LED is connected on pin 13 Int sensorPin = A0 // The potentiometer on pin 0

reads a potentiometer and sends value over serial The read-send-compare process repeats in a loop. If sensorValue is greater than 500, the LED turn on. If sensorValue is less than 500, the LED stays off. Next, the Arduino sends the sensor value over the serial line (as a byte string). First, the Arduino reads the potentiometer sensor value and stores the sensor value in the variable sensorValue.

The Arduino sketch below (an Arduino program is called a sketch) accomplishes a couple things. The programming language used by Arduinos is a variant of the C programming language. Note that Arduinos don't use the Python programming language. Once the LED and potentiometer are hooked up the Arduino, upload the following code to the Arduino using the Arduino IDE. The hardware schematic describes how to the Arduino, LED, resistor, and potentiometer are connected with jumper wires and a breadboard.

The user knows when the sensor signal changes because the user manually turns the potentiometer dial. In the hardware schematic, the blue square with an arrow on it is a potentiometer. If the LED is wired backward, the LED will not turn on. Note the long lead of the LED is connected to PIN13 on the Arduino (yellow wire) and the short lead of the LED is connected through a resistor to ground (black wire). The middle pin of the potentiometer is connected to pin A0 on the Arduino (green wire). You will also need to download the Arduino IDE (the Arduino Integrated Development Environment) using the following link as shown in the previous section:Ĭonnect the potentiometer sensor to the Arduino using a resistor, wires and a breadboard. A USB cable to connect the Arduino to the computer.wires, a resistor, an LED, and a breadboard to connect the sensor to the Arduino.To accomplish this, the following hardware is required: In this section, you will learn how to read a sensor connected to an external piece of hardware (an Arduino) with Python. Reading a Sensor with Python Reading a Sensor with Python Problem Solving with Python Book Construction Use the Python REPL to read the potentiometer data

Connect the Arduino to the computer and Upload the Sketch
