Arduino NANO Project

@LarryD

I completed task #49

I connect LCD as per your instruction, but that LCD having some problem. so i connect LCD outside.

  1. one was NAME display
  2. One was Counter
  3. Last one was timer.

NAME, counter and Timer LCD images.

Hi,
Double check your wiring to the LCD around pins 4, 5, and6.
Can you post a better picture of your LCD connections, that is from above.

Thanks Tom.. :slight_smile:

Hi,

I checked that LCD was ok but during un-soldering some track was open that why it was not display.

no problem i connect new LCD and it was working.

You are doing well!

  1. How would you change the sketch to display your name for only 2 seconds at power on?
  2. After your name disappears from the LCD screen, you see 'Counter = 0'
    When you press the Increment switch the Counter is increased by 1.
    When you press the Decrement switch the Counter is reduced by 1.
  3. Press the Increment/Decrement switches so you see 'Counter = 0'
    Next press the Decrement switch one more time.
    What do you see?
  4. Why do you see what you do in question 3?
  5. How would you change the sketch so negative numbers are displayed?
    example: Counter = -1
  6. What do you have to change in the sketch to make the Increment switch add 10 each time you
    push it?
  7. The second line of the LCD shows the time in milliseconds since the Nano was powered on.
  8. The three lower digits go by very fast and cannot be seen.
  9. LCD screens react slowly so there is no reason to update them faster than every 500ms.
  10. Look at this sketch, how often are we updating/printing 'Counter = 0' to the LCD screen?

Edit
11. Make a change to your sketch so the screen is updated only once every 3 seconds.
12. Do the Increment and Decrement switches work the same as before?
Why or why not?
13. What happens with the two LEDs when buttons are pushed?

(is there one 220 ohm resistor for each LED?)
.

Please read this web page.

Do not change the wiring on your breadboard until requested to do so.

When you are finished reading that page let us know.

  1. How would you change the sketch to display your name for only 2 seconds at power on?
  • Yes
  1. After your name disappears from the LCD screen, you see Counter = 0
    When you press the increment switch the Counter is increased by 1.
    When you press the Decrement switch the Counter is reduced by 1.
  • Yes
  1. Press the Increment/Decrement switches so you see Counter = 0
    Next press the Decrement switch one more time.
    What do you see?
  • If, i press Counter=0, press Decre. Shown 255,254,253....
    -If, i press counter=0, press Incre. Shown 1,2,3....
  1. Why do you see what you do in question 3?
  • Use code for 8 bits
  1. How would you change the sketch so negative numbers are displayed?
    example: Counter = -1
    -NO

  2. What do you have to change in the sketch to make the Increment switch add 10 each time you
    push it?

  • Yes
  1. The second line of the LCD shows the time in milliseconds since the Nano was powered on.
  • Yes
  1. The three lower digits go by very fast and cannot be seen.
  • Yes
  1. LCD screens react slowly so there is no reason to update them faster than every 500ms.
  • Yes
  1. Look at this sketch, often you are updating/printing Counter = 0 to the LCD screen.
  • Yes

*** Tutorial – Using DS1307 and DS3231 Real-time Clock Modules with Arduino ***

  • There are two types of RTC ICs.
  • DS3231 have a small EEPROM, an alarm function and The DS3231 is much more accurate.
  • SDA (or data) and SCL (or clock), use of this two pins we can read time from RTC.
  • Sketch required for read data from RTC.
  • Battery Backup required for both RTC otherwise, RTC will lost set time.
  • "I2C bus" i don't understand this function correctly.

@patelhiren

  1. How would you change the sketch to display your name for only 2 seconds at power on?
  • Yes
    What is the answer?
  1. How would you change the sketch so negative numbers are displayed?
    example: Counter = -1
    -NO
    Did you read this?
    Data Types in Arduino - SparkFun Learn

What has to be changed in the sketch?

  1. What do you have to change in the sketch to make the Increment switch add 10 each time you
    push it?
  • Yes
    I want to see 10,20,30 . . .
    What has to change in the sketch to get this to happen?
  1. Look at this sketch, how often are you updating/printing 'Counter = 0' to the LCD screen ?
  • Yes
    Please answer this?

===============

  1. Make a change to your sketch so the screen is updated only once every 3 seconds.

  2. Do the Increment and Decrement switches work the same as before?
    Why or why not?

  3. What happens with the two LEDs when buttons are pushed?

  4. Is there a 220 ohm resistor in series with each each of your LEDs?

======================

  • "I2C bus" i don't understand this function correctly.
    The I2C bus uses Arduino pins A4 and A5.
    You use these 2 pins to get and send data on your RTC.
    Soon, you will you these 2 pins to read the time of day from your RTC.
  1. How would you change the sketch to display your name for only 2 seconds at power on?
  • lcd.print("Hi patelhiren!!!"); //print message

delay(2000); //wait here for 2000 milli seconds, 2 seconds

  1. How would you change the sketch so negative numbers are displayed?
    example: Counter = -1
  • use "char" command
  1. What do you have to change in the sketch to make the Increment switch add 10 each time you
    push it?
    -Something change here "CounterValue++;" , but i don't know what change there.

I want to see 10,20,30 . . .
What has to change in the sketch to get this to happen?

  1. Look at this sketch, how often are you updating/printing 'Counter = 0' to the LCD screen ?
  • 0.1 Sec (delay(100); //wait here for 1/10 of a second)

===============

  1. Make a change to your sketch so the screen is updated only once every 3 seconds.
  • delay(3000); //wait here for 3 of a second
  1. Do the Increment and Decrement switches work the same as before?
    Why or why not?
  • No, Due to change of time delay
  1. What happens with the two LEDs when buttons are pushed?
  • When i press the buttons, LED was Low
  1. Is there a 220 ohm resistor in series with each each of your LEDs?
    -ok

Good!

  1. How would you change the sketch to display your name for only 2 seconds at power on?
  • lcd.print("Hi patelhiren!!!"); //print message

delay(2000); //wait here for 2000 milli seconds, 2 seconds
Yes

  1. How would you change the sketch so negative numbers are displayed?
    example: Counter = -1
  • use "char" command

Or use
int
or
long

  1. What do you have to change in the sketch to make the Increment switch add 10 each time you
    push it?
    -Something change here "CounterValue++;" , but i don't know what change there.

CounterValue = CounterValue + 10;

I want to see 10,20,30 . . .
What has to change in the sketch to get this to happen?

  1. Look at this sketch, how often are you updating/printing 'Counter = 0' to the LCD screen ?
  • 0.1 Sec (delay(100); //wait here for 1/10 of a second)

===============

  1. Make a change to your sketch so the screen is updated only once every 3 seconds.
  • delay(3000); //wait here for 3 of a second
    Yes
  1. Do the Increment and Decrement switches work the same as before?
    Why or why not?
  • No, Due to change of time delay

delay(3000) Freezes the Arduino for this delay period.
Therefore, the switches are not read and the program slows.
We will see a way to fix this later.

  1. What happens with the two LEDs when buttons are pushed?
  • When i press the buttons, LED was Low
  1. Is there a 220 ohm resistor in series with each each of your LEDs?
    -ok

Connect your components as in this schematic:

.

@patelhiren

  1. Download the required library from the attached ZIP file or get it from the link in the sketch.
  2. Install the library as in the image.
  3. Restart the IDE.
  4. Upload the sketch to the Nano after you connect it to your DS1307 RTC.
  5. The first time you run the sketch, uncomment this line:
    //RTC.adjust(DateTime(DATE, TIME));
  6. The next and subsequent times you download the sketch, make sure the line is commented again.

RTC.png

Use the new sketch in Post # 104

//Sketch_02
//Date and time functions using a DS1307 RTC connected via I2C (A4/A5) using Wire lib
//RTC used is the DS1307

//To make your sketch more readable, format your code every now and then. Press CTRL T 

//Get the RTClib library from here:
// https://github.com/adafruit/RTClib
//Install the library in C:\Users\YourName\Documents\Arduino\libraries\
//You should then have this entry: C:\Users\YourName\Documents\Arduino\libraries\RTClib
//You must restart all open IDEs after library installation

#include <Wire.h>          //This is needed to talk to the RTC
#include <LiquidCrystal.h> //include the LCD library in this Sketch
#include "RTClib.h"        //This helps you write/read data to/from the RTC

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

RTC_DS1307 RTC;

// Define variables
DateTime now;
const byte ONLED = 6; //the ON LED is connected to this pin

//**********************************************************************
void setup () 
{
  //baud rate for the serial port
  Serial.begin(9600);

  //number of columns and rows for this LCD
  //this is a 16 character by 2 row LCD
  lcd.begin(16, 2); 

  //start the RTC
  Wire.begin();
  RTC.begin();

  pinMode(ONLED, OUTPUT); //On LED connected here

  //clear the LCD screen, LCD cursor to location 0,0
  lcd.clear(); 
  //0,0 is the first character on the first line on the LCD
  //         0000000001111111  column position
  //         0123456789012345
  lcd.print("Hi patelhiren!!!"); 

  delay(3000);  

  //check to see if the RTC is working
  if (!RTC.isrunning()) 
  {
    lcd.print("RTC is not working");   
    //Serial.println("RTC is NOT running!");
  }

  //  Set the RTC time 
  //  Get the current time fron the PC, send the time to the RTC
  //  After setting the RTC time, comment the next line and upload this sketch to the Nano again
  //RTC.adjust(DateTime(__DATE__, __TIME__));  

} //  >>>>>>>>>>>>>> E N D  O F  s e t u p ( ) <<<<<<<<<<<<<<<<<

//**********************************************************************
void loop () 
{
  delay(500);

  //read the time from the RTC
  now = RTC.now();

  //Toggle the ON LED every second 
  //is the current second an even number?
  if(now.second()%2 == 0)
  {
    digitalWrite(ONLED, HIGH); //LED is ON for even seconds
  }
  else
  {
    digitalWrite(ONLED, LOW);  //LED is OFF for odd seconds
  }

  //update the date and time LCD display
  printLCDtime();

  //  If you want date and time send to the serial monitor, remove the // from the follow 12 lines
  //Serial.print(now.year(), DEC);
  //Serial.print('/');
  //Serial.print(now.month(), DEC);
  //Serial.print('/');
  //Serial.print(now.day(), DEC);
  //Serial.print(' ');
  //Serial.print(now.hour(), DEC);
  //Serial.print(':');
  //Serial.print(now.minute(), DEC);
  //Serial.print(':');
  //Serial.print(now.second(), DEC);
  //Serial.println();

} //  >>>>>>>>>>>>>> E N D  O F  l o o p ( ) <<<<<<<<<<<<<<<<<

//======================================================================
//                      F U N C T I O N S
//======================================================================

//**********************************************************************
//Function to send date and time to the LCD
void printLCDtime()
{
  //clear the LCD screen, LCD cursor to location 0,0
  lcd.clear();

  //         0000000001111111
  //         0123456789012345   
  //         YYYY/MM/DD
  lcd.print(now.year(), DEC);
  lcd.print("/");
  printDigits(now.month());
  lcd.print("/"); 
  printDigits(now.day());

  //move the LCD cursor to the first character on the second line 
  lcd.setCursor(0,1);  

  //         0000000001111111
  //         0123456789012345   
  //         HH:MM:SS
  printDigits(now.hour());   
  lcd.print(":");
  printDigits(now.minute());  
  lcd.print(":"); 
  printDigits(now.second());  

} // END of printLCDtime()

//**********************************************************************
//Function to print leading 0s
void printDigits(int digits)
{
  if(digits < 10)
  {
    //add a leading zero to numbers i.e. 0-9 = 00-09 
    lcd.print('0');                
  }

  lcd.print(digits);

} //END of printDigits()


//======================================================================
//                      E N D  O F  C O D E
//======================================================================

RTClibrary.zip (13.8 KB)

Were you able to get the RTC circuit and the sketch to work?

.

ok,

I will search in google

This one is ok?

Schematic-DS1307-RTC.png

"This one is ok?"
You told us you had this RTC, use it:

d82fd12c0beab5a60a3bb96d5c59e22b62bca146.jpg

.

Ya, i purchase online but, it will take time.

This is available with me.

i use this?

The RTC shown in post #96 should work.

The best RTC I have used this is the DS3231.
They are much superior, more accurate, than the DS1307.

The DS3231 is about $2.00 each.
example:

I do not believe the Dallas RTC will work in this application.

.