bruno_opaiva
Published © GPL3+

LCD reactive bot

A simple project using I2C LCD display, that reacts to proximity, illumination and movement.

BeginnerFull instructions provided959
LCD reactive bot

Things used in this project

Hardware components

I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
I2C LCD display
×1
Arduino UNO
Arduino UNO
×1
High Brightness LED, White
High Brightness LED, White
High Brightness LED for illumination.
×2
Resistor 221 ohm
Resistor 221 ohm
Resistors for the LEDs.
×2
LDR, 5 Mohm
LDR, 5 Mohm
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
For detecting moviment
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
Resistor 10k ohm
Resistor 10k ohm
×1
Breadboard (generic)
Breadboard (generic)
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Schematic

Schematic made using Tinkercad. You can download it to a better view

Code

Project code

C/C++
Code made using Arduino IDE
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Ultrasonic.h>
LiquidCrystal_I2C lcd (0x27, 16, 2); //Creating lcd object
Ultrasonic ultrasonic1 (13, 12); //Creating ultrasonic1 object
Ultrasonic ultrasonic2 (11, 10); //Creating ultrasonic2 object
int val1; //variable to store the right Ultrasonic sensor reading values
int val2; //variable to store the left Ultrasonic sensor reading values
int sensor = 2; //PIR sensor attached to digital pin 2
int ldr = A0; //LDR attached to analog pin 0
int ldrvalue = 0; //variable to store the LDR reading values
int led = 3; //1º LED attached to digital pin 3
int led1 = 4; //2º LED attached to digital pin 4
void setup() {
  lcd.init(); //initialize the Display
  pinMode(sensor, INPUT); //sensor defined as input
  pinMode(led, OUTPUT); //1º LED defined as output
  pinMode(led1, OUTPUT); //2º LED defined as output
  pinMode(ldr, INPUT); //LDR defined as input
}

void loop() {
  val1 = ultrasonic1.Ranging(CM); //storing ultrasonic1 reading values in val1
  val2 = ultrasonic2.Ranging(CM); //storing ultrasonic2 reading values in val2
  ldrvalue = analogRead(ldr); //storing LDR reading values in ldrvalue
  if (digitalRead(sensor) == HIGH) { //if PIR sensor detects movement, turns on the Display backlight
    lcd.setBacklight(HIGH);
  }
  else { //if not, turns off the backlight 
    lcd.setBacklight(LOW);
  }
  if (ldrvalue < 300) { //if LDR don't detect luminosity, turn the LEDs on
    digitalWrite(led, HIGH);
    digitalWrite(led1, HIGH);
  }
  else { //if not, turn the LEDs off
    digitalWrite(led, LOW);
    digitalWrite(led1, LOW);
  } 
  if (val1 < 20) { //if the right ultrasonic sensor detects proximity, the face eyes go to right
    lcd.clear();
    lcd.print("O");
    lcd.setCursor(9, 0);
    lcd.print("O");
    lcd.setCursor(6, 1);
    lcd.print("____"); //the mouth
    delay(50);
  }
  else if (val2 < 20) { //if the left ultrasonic sensor detects proximity, the face eyes go to left
    lcd.clear();
    lcd.setCursor(6, 0);
    lcd.print("O");
    lcd.setCursor(15, 0);
    lcd.print("O");
    lcd.setCursor(6, 1);
    lcd.print("____");
    delay(50);
  }
  else { //else, the face don't move 
    lcd.clear();
    lcd.setCursor(3, 0);
    lcd.print("O");
    lcd.setCursor(12, 0);
    lcd.print("O");
    lcd.setCursor(6, 1);
    lcd.print("____");
    delay(50);
  }
}

Credits

bruno_opaiva
6 projects • 4 followers

Comments