Devices & Components
Arduino Uno Rev3
Rotary potentiometer (generic)
RGB LCD Shield Kit, 16x2 Character Display
Jumper wires (generic)
Breadboard (generic)
Project description
Code
Untitled file
c_cpp
1/* 2The program reads the analog values of A0. These values are in the range of 0-1023. 3*/ 4 5#include <LiquidCrystal_I2C.h> 6#include <LCD.h> 7 8#define analogInput A0 9#define R1 220 10#define vin 5 11#define BACKLIGHT_PIN 3 12#define En_pin 2 13#define Rw_pin 1 14#define Rs_pin 0 15#define D4_pin 4 16#define D5_pin 5 17#define D6_pin 6 18#define D7_pin 7 19 20LiquidCrystal_I2C lcd(0x27, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); 21 22void setup() { 23 24 Serial.begin(9600); 25 26} 27 28void loop() { 29 int sensorValue=analogRead(analogInput); 30 float voltage=sensorValue*(5.0/1023.0); 31 screen(String(resistance(voltage))); 32 delay(3000); 33} 34 35int resistance(float vout){ 36 return R1*(1/(vin/vout-1)); 37} 38 39void screen(String text){ 40 //Define the LCD as 16 column by 2 rows 41 lcd.begin (16,2); 42 43 //Switch on the backlight 44 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); 45 lcd.setBacklight(HIGH); 46 47 //goto first column (column 0) and first line (Line 0) 48 lcd.setCursor(0,0); 49 50 //Print at cursor Location 51 lcd.print("Resistor value is: "); 52 53 //goto second column and first line 54 lcd.setCursor(0,1); 55 lcd.print(text); 56 lcd.print(" ohm"); 57 58}
Untitled file
c_cpp
1/* 2The program reads the analog values of A0. These values are in the range of 0-1023. 3*/ 4 5#include <LiquidCrystal_I2C.h> 6#include <LCD.h> 7 8#define analogInput A0 9#define R1 220 10#define vin 5 11#define BACKLIGHT_PIN 3 12#define En_pin 2 13#define Rw_pin 1 14#define Rs_pin 0 15#define D4_pin 4 16#define D5_pin 5 17#define D6_pin 6 18#define D7_pin 7 19 20LiquidCrystal_I2C lcd(0x27, En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin); 21 22void setup() { 23 24 Serial.begin(9600); 25 26} 27 28void loop() { 29 int sensorValue=analogRead(analogInput); 30 float voltage=sensorValue*(5.0/1023.0); 31 screen(String(resistance(voltage))); 32 delay(3000); 33} 34 35int resistance(float vout){ 36 return R1*(1/(vin/vout-1)); 37} 38 39void screen(String text){ 40 //Define the LCD as 16 column by 2 rows 41 lcd.begin (16,2); 42 43 //Switch on the backlight 44 lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE); 45 lcd.setBacklight(HIGH); 46 47 //goto first column (column 0) and first line (Line 0) 48 lcd.setCursor(0,0); 49 50 //Print at cursor Location 51 lcd.print("Resistor value is: "); 52 53 //goto second column and first line 54 lcd.setCursor(0,1); 55 lcd.print(text); 56 lcd.print(" ohm"); 57 58}
Downloadable files
Complete circuit
Complete circuit
Comments
Only logged in users can leave comments