Search the Arduino Website
Learning Examples ([Link] | Foundations ([Link] | Hacking ([Link] | Links ([Link] Examples > EEPROM Library
EEPROM Write
The microcontroller on the Arduino board has 512 bytes of EEPROM: ([Link] memory whose values are kept when the board is turned off (like a tiny hard drive). This example illustrates how to store values read from analog input 0 into the EEPROM using [Link]() ([Link] function. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch.
Hardware Required
- Arduino Board
Circuit
There is no circuit for this example.
([Link]
image developed using Fritzing ([Link] For more circuit examples, see the Fritzing project page ([Link]
Code
/ * *E E P R O MW r i t e * *S t o r e sv a l u e sr e a df r o ma n a l o gi n p u t0i n t ot h eE E P R O M . *T h e s ev a l u e sw i l ls t a yi nt h eE E P R O Mw h e nt h eb o a r di s *t u r n e do f fa n dm a yb er e t r i e v e dl a t e rb ya n o t h e rs k e t c h . * / # i n c l u d e< E E P R O M . h > / /t h ec u r r e n ta d d r e s si nt h eE E P R O M( i . e .w h i c hb y t e / /w e ' r eg o i n gt ow r i t et on e x t ) i n ta d d r=0 ; v o i ds e t u p ( ) { } v o i dl o o p ( ) { / /n e e dt od i v i d eb y4b e c a u s ea n a l o gi n p u t sr a n g ef r o m / /0t o1 0 2 3a n de a c hb y t eo ft h eE E P R O Mc a no n l yh o l da / /v a l u ef r o m0t o2 5 5 . i n tv a l=a n a l o g R e a d ( 0 )/4 ; / /w r i t et h ev a l u et ot h ea p p r o p r i a t eb y t eo ft h eE E P R O M . / /t h e s ev a l u e sw i l lr e m a i nt h e r ew h e nt h eb o a r di s / /t u r n e do f f . E E P R O M . w r i t e ( a d d r ,v a l ) ; / /a d v a n c et ot h en e x ta d d r e s s . t h e r ea r e5 1 2b y t e si n / /t h eE E P R O M ,s og ob a c kt o0w h e nw eh i t5 1 2 . a d d r=a d d r+1 ; i f( a d d r= =5 1 2 ) a d d r=0 ; } d e l a y ( 1 0 0 ) ;
[Get Code] ([Link]
See also
E E P R O M . w r i t e ( )([Link] a n a l o g R e a d ( )([Link] i f ( )([Link]
- EEPROM Clear example ([Link] - EEPROM Read example ([Link] - EEPROM library reference ([Link]
Share
NEWSLETTER
SUBSCRIBE Enter your email to sign up 2014 Arduino Copyright Notice ([Link]
Contact us ([Link]
([Link] ([Link] ([Link]
([Link] ([Link]