Arduino – LCD Pin Description A register select (RS) pin that controls where in the LCD's memory you're writing data to. You can select either the data register, which holds what goes on the screen, or an instruction register, which is where the LCD's controller looks for instructions on what to do next. A Read/Write (R/W) pin that selects reading mode or writing mode An Enable (E) pin that enables writing to the registers 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing to a register when you write, or the values you're reading when you read. There's also a display constrast pin (Vo), power supply pins (+5V and Gnd) and LED Backlight (Bklt+ and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off the LED backlight, respectively.
Arduino – LCD connection
Arduino – LCD connection
Arduino – LCD connection TASK • Display Character second LINE • Display Character “PTSB” at the center of LCD first LINE
Arduino – LCD LiquidCrystal Library •scrollDisplayLeft() •scrollDisplayRight() •autoscroll() •noAutoscroll() •leftToRight() •rightToLeft() •createChar() Function •LiquidCrystal() •begin() •clear() •home() •setCursor() •write() •print() •cursor() •noCursor() •blink() •noBlink() •display() •noDisplay()
TEMPERATURE SENSOR LM 35
Arduino – LM 35 sensor overview LM35 Linear Temperature Sensor can be used to detect ambient air temperature. The output voltage is proportional to the temperature. Specification • Based on the semiconductor LM35 temperature sensor • Can be used to detect ambient air temperature • Sensitivity: 10mV per degree Celsius • Functional range: 0 degree Celsius to 100 degree Celsius
Arduino – LM 35 sensor connection temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;--- Vref = 5V & Temp = 10mV for each 1oC
Arduino – LM 35 sensor connection temp = (1.1V * analogRead(tempPin) * 100.0) / 1024;--- Vref = 5V & Temp = 10mV for each 1oC The LM35 is only guaranteed to be within 0.5 degrees of the actual temperature The LM35 only produces voltages from 0 to +1V. The ADC uses 5V as the highest possible value. This is wasting 80% of the possible range. If you change aRef to 1.1V, you will get almost the highest resolution possible. To change aRef to 1.1V, you use the command analogReference(INTERNAL)
Arduino – LM 35 sensor connection temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;--- Vref = 5V & Temp = 10mV for each 1oC TASK • Write a code to alert by ON LED at Pin 13 when the temperature increase to more than 35oC
ARDUINO LDR Seeing the LIGHT
Arduino – LDR connection Overview Photoresistors, also known as light dependent resistors (LDRs) or photocells, are low-cost variable resistors where the resistance changes depending on the amount of light hitting its surface. In dark environments the resistance is high; in light environments the resistance is lower. https://blog.udemy.com/arduino-ldr/
Arduino – LDR connection
Arduino – LDR connection TASK • Determine the value of sensor on following condition • Normal Room Light • Finger on top of sensor • Torch shone onto sensor ( use your mobile phone torch) • Create Condition to display light condition to your monitor (use if… else based on the condition value, allow some range)
ULTRASONIC
Arduino – ULTRASONIC connection TASK • Display Character second LINE • Display Character “PTSB” at the center of LCD first LINE Connecting the SR04 Ultrasonic Sensor to the Arduino Arduino uno R3, or any Arduino for that matter 1 SR04 Ultrasonic Sensor 1 breadboard 4 Jumper Wires
Arduino – ULTRASONIC connection TASK Write a code to display a short distance detect and long distance sense
Analog to Digital Conversion The Analog World • Microcontrollers are capable of detecting binary signals: is the button pressed or not? These are digital signals. When a microcontroller is powered from five volts, it understands zero volts (0V) as a binary 0 and a five volts (5V) as a binary 1. • The world however is not so simple and likes to use shades of gray. What if the signal is 2.72V? Is that a zero or a one? • We often need to measure signals that vary; these are called analog signals. A 5V analogue sensor may output 0.01V or 4.99V or anything in between. • Nearly all microcontrollers have a device built into them that allows us to convert these voltages into values that we can use in a program to make a decision.
Analog to Digital Conversion What is the ADC? • An Analog to Digital Converter (ADC) is a very useful feature that converts an analog voltage on a pin to a digital number. By converting from the analog world to the digital world, we can begin to use electronics to interface to the analog world around us.
Analog to Digital Conversion Relating ADC Value to Voltage • The ADC reports a ratio metric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023. • Analog to digital conversions are dependant on the system voltage. Because we predominantly use the 10-bit ADC of the Arduino on a 5V system, we can simplify this equation slightly:
Analog to Digital Conversion Resolution 10 Bits, Reference (system voltage) = 5V, If the analog voltage is 2.12V what will the ADC report as a value? The ADC should output 434.
Analog to Digital Conversion Relating ADC Value to Voltage • The ADC reports a ratiometric value. This means that the ADC assumes 5V is 1023 and anything less than 5V will be a ratio between 5V and 1023. • Analog to digital conversions are dependant on the system voltage. Because we predominantly use the 10-bit ADC of the Arduino on a 5V system, we can simplify this equation slightly:
Analog to Digital Conversion Resolution and Quality Analog-to-digital converter precision is determined by the number of bits the device possesses. The number of bits, n, is directly related to the number of sampling gradations, N, so that N = 2n . (Gradations can be thought of as the scale of measured intervals with which to express values contained in the analog signal.) For example, a 12-bit converter is capable of 4096 gradations. If the analog signal is within the range of 0-5 V (a typical control signal), this range would be broken up into 4096 intervals in order to express analog values, with 0 V being 0 and 5 V being 4095. If the analog signal measures 2.4414 V at a given sample time, the digital equivalent would be 2000. The entire analog signal can be mapped proportionally using these gradations. Device precision can be defined as 1/N, with smaller values indicating greater precision. For example, a 4-bit converter has a precision 1/16 that of the analog signal, while a 10-bit one is 1/1024 as precise.
Analog to Digital Conversion Resolution and Quality
Referenced from the perspective of the microcontroller (electrical board). Inputsis a signal / information going into the board. Examples: Buttons Switches, Light Sensors, Flex Sensors, Humidity Sensors, Temperature Sensors… Output is any signal exiting the board. Examples: LEDs, DC motor, servo motor, a piezo buzzer, relay, an RGB LED CONCEPST - INPUT & OUTPUT
digitalWrite() analogWrite() digitalRead() if() statements / Boolean analogRead() Serial communication # Activity 1: LED – The Circuit