Write to a Micro SD card with an Arduino the Time & Date of an event from an IR sensor - Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
okay welcome again guys this is Ivan from bbs.com uh today I'm going to do a tutorial and we're going to use three modules today we're going to use one that we saw before the RTC uh the DS 1307 RTC clock the realtime clock that we use in a other tutorial and we're going to use today we're going to use this new one which is the IR avoidance sensor and basically all this does this guy sends out light and when something crosses it the light reflects and gets picked up by the receiver and then the pin it only uses one digital pin goes high or low depending on what's Happening uh these have a little potentium meter on board that you can adjust the sensitivity of it so we're going to take the I or low pin event of this sensor to actually get the time and date from the RTC and then put it on this module which is an SBI bus micro SD card module so here's the SD card we're going to use so when something breaks that beam or gets detected it's going to take the time and write it on the SD card you know this is kind of like a little Intruder uh log uh system you could put this next to your door and when somebody opens the door it will break that beam and then this event will be logged on the SD card but you could use it for multiple things a lot of people use these for like robot avoidance so when it gets near wall it turns and it goes ahead so we're connecting all these to our Uno so this is an i2c device so we're going to plug it into the i2c pins on the Uno which is A4 and A5 this guy is an SPI but the device so we're going to connect those to the SBI pins on the on the Uno which are 13 12 11 and 10 and the little sensor only has one pin so basically any digital will do we're connecting it to the pin two on our Uno so we're going to cut here we're going to take a look at the code first thing we need to make sure is that our RTC time and date are correct so we're going to use the library that we used before and it comes with a little sketch that's called I believe set time that will take the time from our computer and put it in there so we just got to make sure that this is correct and after that we'll look at the main code and how we're going to detect and write the information on the card so let's go take a look and we'll be right back to look at the results okay like we said we're going to use a couple libraries for this tutorial so let's take a look at them you can download these libraries on our website ber.com tututorial you'll find this tutorial with the link uh so basically there's two of them that are already included with the Arduino ID Library the SD one is for the uh micro SD card uh we have the wire which is also included and the one you'll need to download is time and the DS RTC for our clock module so just extract those to your already we know Library folder and restart your ID software and you're good to go so we need to make sure that the time is set on our RTC module so we're going to open this in the library we have the set time test I already did that so I'm going to go ahead we don't need to change anything just make sure that our Uno is connected we're going to upload that code and once it's done we're going to open the serial monitor right here and we're getting configured time from our computer so we're good to go here and if you want to double make sure you can always open the example dstc read test and this basically will get the time from the RTC so let's just do it really quick upload that code let's wait for it then open the serial Monitor and there you go it's getting the time so once this is done you know that the time is correct on your RTC we're going to go take a look at the main code to use our IR obstacle avoidance sensor and log the time and date to the micr SD so let's go take a look at that all right so here we are in the main code that we're going to use so we're going to start at the top we're including four libraries SD and wire are already included with the r we now install so you don't need to download these SD is for the SD card and the wire is for the i2c bus communication uh time is for time manipulation and ds1307 is for our little realtime clock you can find links on our website to download these both these libraries now we're going to define the r pin meaning the sensor is connected to pin 2 on our Uno then we're going to put the time and date into this buffer so we can format the date the the time and date string before we write it to the card then we're using the four digigit year like we did in the last video and here's our main setup main setup is using the serial monitor we're only using it for testing purposes so you guys can see what's happening and we set our pin mode IR pin to an input and we set the pin Moone 10 to an output for the SD card and we check if the card is present make sure the card is inserted inserted into the module now here's our main loop we're calling the time and we're checking if digital read IR pin goes to low basically something is in front of it IR detected we're going to read the time and date then we're going to format the year so year for digit equals T.E the TM .e will give us a result of 45 because it gives a it gives you the number of year elapsed since 1970 so to get the full year we're doing 45 plus 1970 will give us 2015 so and we're putting that in here then we're using the S print F again to format the information we're going to put into the time date buffer so we're writing all this string here and basically we're saying okay time and this part here says put aink leading zero in front of TM hour so this will be replaced with TM hour column TM minutes will be this guy here will be TM seconds and we do the same thing for date so this will be day month year and we're putting a little message so this string will be written on the MicroSD card now after we get we formatted this we're going to open the file which is called intruder text on our MicroSD we check if the file exists if the file exists we're printing putting on the card in the file the time and date buffer then we close the file and on our serial monitor we're just going to print it to make sure everything's okay else meaning the file is not there we have an error error opening Intruder do text and it gets out now here the while loop it's because if you put your hand in front of that sensor and you leave it there the pin will always be low if we didn't put this here it would just keep looping in there and writing to the card low low low so the while loop while digital real pin equals low waight so basically this will be stuck in here until this pin becomes high again so nothing's happening and when it gets out we put a delay of about 100 microc to give time for the IR to reset from low to high and then it goes back up and it does it again so there you go that's the way this works so we're going to upload that to our Uno and we're going to go back to our breadboard and look at the results so let's go take a look okay so we're back to our breadboard we uploaded the code that we just saw to the Uno I already plugged it in so everything is ready to go the SD card is installed into the micro SD card module so what I'm going to do I'm going to pass in front of our sensor and we should see something happening on the serial monitor there we go we logged that information going to go back loged another one what I'm going to do now I'm going to stop in front it logged it but nothing's happening cuz we're in the while loop now I'm going to take it off and it didn't log anything and back and forth there we go four 5 six so there you go that's an easy way to use one of these guys log the information there use the RTC clock to get the time and date you know uh these tutorials are basically done so you guys can get going going you know to connect them and after that you start experimenting with your own code making it more complicated uh you know that's that's uh the whole point that's why we do these uh tutorials so once again you can go to brb.com to find the schematics libraries that we used the code if you want to download it and also if you want to uh be informed when we post new videos you can always subscribe to our YouTube channel uh like I always say we try to do one or two a week so uh hope you guys enjoyed this one and I hope to catch you guys real soon take care
Info
Channel: Brainy-Bits
Views: 14,438
Rating: undefined out of 5
Keywords: Arduino (Brand), MicroSD, IR sensor, DS1307, Tutorial, RTC, UNO, micro sd
Id: 6JeOrZ7ckJ4
Channel Id: undefined
Length: 9min 49sec (589 seconds)
Published: Sun Feb 22 2015
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.