This week's assignment was to design a circuit using arduino
I was inspired by a problem I face daily which is to keep checking my mobile phone. As I'm diagnosed with ADHD I find it hard to focus on tasks that I'm doing. And my mobile is really distracting me all time and reduces my attention span. I keep putting note everywhere to remember to focus and stop procrastinating but it's really overwhelming, So I decided to make a device to pot my phone on it and whenever I pick my phone up, it make this noise and shows messages to remind me of my work.
The software used for the assignment:
TinkerCad circuits building and simulation online tool
Arduino IDE
The Hardware:
Arduino uno
IR sensor
Jumpers wires
Buzzer (5V)
Breadboard
LCD screen
Lego for some enclosure
I dragged and dropped the components of the circuit in the design workspace in Tinker CAD
Then I connected the LCD screen to the Arduino and the breadboard:
Where GND connected to the negative part of the breadboard
VCC is connected to the positive part
SDA to A4 pin on the Arduino
SCL to A5 pin on the Arduino
The buzzer is connected to the Arduino and the breadboard where Anode is connected to pin 9 and the cathode is connected to the negative part of the breadboard
Simulation on TinkerCad
I started with getting the Arduino to recognize the type of the LCD I used.
I used some blocks to recognize the sensor's readings .
and according to these readings, if it was high (means that the IR sensor can sense the light) , the buzzer peeps. And the screen shows messages to tell the user to leave his phone.
and if it was low( it means that you put your phone down so the LCD light is off and the buzzer stops.
// C++ code
//
#include <LiquidCrystal_I2C.h>
int sensorState = 0;
LiquidCrystal_I2C lcd_1(39, 16, 2);
void setup()
{
lcd_1.init();
pinMode(2, INPUT);
pinMode(9, OUTPUT);
}
void loop()
{
sensorState = digitalRead(2);
if (sensorState == HIGH) {
tone(9, 523, 5000); // play tone 60 (C5 = 523 Hz)
lcd_1.clear();
lcd_1.backlight();
lcd_1.print("LEAVE YOUR PHONE");
delay(2000); // Wait for 2000 millisecond(s)
lcd_1.clear();
lcd_1.setCursor(0, 0);
lcd_1.print("FO2Y LIE NFSK");
lcd_1.setCursor(0, 1);
lcd_1.print("LEAVE IT NOW");
delay(2000); // Wait for 2000 millisecond(s)
} else {
noTone(9);
lcd_1.clear();
lcd_1.noBacklight();
delay(1000); // Wait for 1000 millisecond(s)
}
}
The whole circuit
Trying the circuit for the last time before putting it into the enclosure
Final product
I faced a lot of problems trying to make the LCD work.
First, on TinkerCad I didn't choose the right blocks but thanks to YARA, ESLAM and Abdelrahman I fixed this problem
then I didn't choose the right LCD which is supposed to be PCF8574-based
Then to know the serial number of your LCD you need to use some code and connect your LCD and Arduino to the laptop to know it and here's the code:
#include <Wire.h>
void setup() {
Serial.begin (9600);
// Leonardo: wait for serial port to connect
while (!Serial)
{
}
Serial.println ();
Serial.println ("I2C scanner. Scanning ...");
byte count = 0;
Wire.begin();
for (byte i = 8; i < 120; i++)
{
Wire.beginTransmission (i);
if (Wire.endTransmission () == 0)
{
Serial.print ("Found address: ");
Serial.print (i, DEC);
Serial.print (" (0x");
Serial.print (i, HEX);
Serial.println (")");
count++;
delay (1); // maybe unneeded?
} // end of good response
} // end of for loop
Serial.println ("Done.");
Serial.print ("Found ");
Serial.print (count, DEC);
Serial.println (" device(s).");
} // end of setup
void loop() {}
The next problem is that there's a library needs to be added to the arduio IDE for your code to work properly , just open your IDE and do the following in order:
Sketch>Include Library> Add.ZIP Library
I'll use an LCD in my final project, that's why I didn't give it despite all the problems I've faced and I guess I'll be able to use it later without any problems.
I learned how to make things get smarter with arduino, That's super cool actually.
I worked with my friend Mina this week to make a smart waving hand using an ultrasonic sensor and servo motor.