In: Computer Science
Modify experiment 2 (below) such that the sensor value and data conversion to be shown on both LCD display and Serial Monitor
Here is modification of above program that fade LED light based upon sensed voltage level. Connect LED on pin 9 with current limiting resistor in series. Execute modified version of following program.
const int led = 9; void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); int dataConv = sensorValue*(256.0/1024); //write analog equvivalant data on led pin analogWrite(led, dataConv); // print out the value you read: Serial.println(sensorValue); Serial.println(dataConv); delay(1000); // delay in between reads for stability } |
Thanks for your help!
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface
pins
LiquidCrystal lcd(6,7,8,10,11,12);//lcd is connected to pin
6,7,8,10,11,12
const int led = 9;//led pin 9
int A0;//input pin
void setup()
{
pinMode(A0,INPUT);
pinMode(led,OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
void loop()
{
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
int dataConv = sensorValue*(256.0/1024);
//write analog equvivalant data on led pin
analogWrite(led, dataConv);
// print out the value you read in Serial monitor:
Serial.println(sensorValue);
Serial.println(dataConv);
lcd.setCursor(0,0); // Sets the cursor to col 0 and row 0
lcd.print("SensorValue: "); // Prints SensorValue: to LCD
lcd.print((sensorValue)); // Prints value on sensorValue to
LCD
lcd.setCursor(0,1); // Sets the cursor to col 1 and row 0
lcd.print("dataConv: "); // Prints dataConv: to LCD
lcd.print(dataConv); // Prints value on dataConv to LCD
delay(1000); // delay in between reads for stability
}
output compiled: