Arduino Code:
#include <LiquidCrystal.h>
#define pot A0
#define LDR A1
#define input1 8
#define input2 9
#define pwm 10
float Pot_val = 0;
float LDR_val = 0;
// initialize the library with the numbers of the interface
pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(pot, INPUT);
pinMode(LDR, INPUT);
pinMode(input1, OUTPUT);
pinMode(input2, OUTPUT);
pinMode(pwm, OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.clear();
}
void loop()
{
Pot_val = analogRead(pot) / 1023 * 255;
analogWrite(pwm, Pot_val);
lcd.setCursor(0, 0);
lcd.print("speed:");
lcd.setCursor(7, 0);
lcd.print(Pot_val / 255 * speed_max);
LDR_val = analogRead(LDR) / 1023 * 10;
lcd.setCursor(11, 0);
lcd.print("Dir:");
if (LDR_val > 5)
{
digitalWrite(input1, 1);
digitalWrite(input2, 0);
lcd.setCursor(0, 1);
lcd.print("Clockwise");
}
else if (LDR_val < 5)
{
digitalWrite(input1, 0);
digitalWrite(input2, 1);
lcd.setCursor(0, 1);
lcd.print("Anti-Clockwise");
}
}
Embedded Systems Project Assignment 02 Connect a potentiometer and a LDR to your Arduino board. Using...